Search in sources :

Example 31 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class PlainAttrTest method saveWithEncrypted.

@Test
public void saveWithEncrypted() throws Exception {
    User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
    PlainSchema obscureSchema = plainSchemaDAO.find("obscure");
    assertNotNull(obscureSchema);
    assertNotNull(obscureSchema.getSecretKey());
    assertNotNull(obscureSchema.getCipherAlgorithm());
    UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
    attr.setOwner(user);
    attr.setSchema(obscureSchema);
    attr.add("testvalue", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    user.add(attr);
    userDAO.save(user);
    UPlainAttr obscure = user.getPlainAttr("obscure").get();
    assertNotNull(obscure);
    assertEquals(1, obscure.getValues().size());
    assertEquals(Encryptor.getInstance(obscureSchema.getSecretKey()).encode("testvalue", obscureSchema.getCipherAlgorithm()), obscure.getValues().get(0).getStringValue());
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 32 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class GoogleAppsPullActions method afterAll.

@Transactional
@Override
public void afterAll(final ProvisioningProfile<?, ?> profile) throws JobExecutionException {
    googleAppsIds.forEach((key, value) -> {
        User user = userDAO.find(key);
        if (user == null) {
            LOG.error("Could not find user {}, skipping", key);
        } else {
            AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
            // 1. stores the __UID__ received by Google
            PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
            if (googleAppsId == null) {
                LOG.error("Could not find schema googleAppsId, skipping");
            } else {
                UPlainAttr attr = user.getPlainAttr(getGoogleAppsIdSchema()).orElse(null);
                if (attr == null) {
                    attr = entityFactory.newEntity(UPlainAttr.class);
                    attr.setSchema(googleAppsId);
                    attr.setOwner(user);
                    user.add(attr);
                    try {
                        attr.add(value, anyUtils);
                        userDAO.save(user);
                    } catch (InvalidPlainAttrValueException e) {
                        LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), value, e);
                    }
                } else {
                    LOG.debug("User {} has already a googleAppsId assigned: {}", user, attr.getValuesAsStrings());
                }
            }
        }
    });
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class AnyTypeClassTest method create.

@Test
public void create() {
    PlainSchema newSchema = entityFactory.newEntity(PlainSchema.class);
    newSchema.setKey("new_plain_schema");
    newSchema.setType(AttrSchemaType.String);
    plainSchemaDAO.save(newSchema);
    plainSchemaDAO.flush();
    newSchema = plainSchemaDAO.find(newSchema.getKey());
    assertNotNull(newSchema);
    AnyTypeClass newClass = entityFactory.newEntity(AnyTypeClass.class);
    newClass.setKey("new class");
    newClass.add(newSchema);
    anyTypeClassDAO.save(newClass);
    anyTypeClassDAO.flush();
    newClass = anyTypeClassDAO.find(newClass.getKey());
    assertNotNull(newClass);
    assertEquals(1, newClass.getPlainSchemas().size());
    assertEquals(newSchema, newClass.getPlainSchemas().get(0));
    assertEquals(newClass, newClass.getPlainSchemas().get(0).getAnyTypeClass());
    newSchema = plainSchemaDAO.find(newSchema.getKey());
    assertNotNull(newSchema.getAnyTypeClass());
}
Also used : PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 34 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class PlainSchemaTest method deleteSurname.

@Test
public void deleteSurname() {
    // search for user schema fullname
    PlainSchema schema = plainSchemaDAO.find("surname");
    assertNotNull(schema);
    // check for associated mappings
    Set<MappingItem> mappings = new HashSet<>();
    for (ExternalResource resource : resourceDAO.findAll()) {
        if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (schema.getKey().equals(mapItem.getIntAttrName())) {
                    mappings.add(mapItem);
                }
            }
        }
    }
    assertFalse(mappings.isEmpty());
    // delete user schema fullname
    plainSchemaDAO.delete("surname");
    plainSchemaDAO.flush();
    // check for schema deletion
    schema = plainSchemaDAO.find("surname");
    assertNull(schema);
}
Also used : MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 35 with PlainSchema

use of org.apache.syncope.core.persistence.api.entity.PlainSchema in project syncope by apache.

the class PlainSchemaTest method deleteFullname.

@Test
public void deleteFullname() {
    // fullname is mapped as ConnObjectKey for ws-target-resource-2, need to swap it otherwise validation errors
    // will be raised
    resourceDAO.find("ws-target-resource-2").getProvision(anyTypeDAO.findUser()).get().getMapping().getItems().forEach(item -> {
        if ("fullname".equals(item.getIntAttrName())) {
            item.setConnObjectKey(false);
        } else if ("surname".equals(item.getIntAttrName())) {
            item.setConnObjectKey(true);
        }
    });
    // search for user schema fullname
    PlainSchema schema = plainSchemaDAO.find("fullname");
    assertNotNull(schema);
    // check for associated mappings
    Set<MappingItem> mapItems = new HashSet<>();
    for (ExternalResource resource : resourceDAO.findAll()) {
        if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if (schema.getKey().equals(mapItem.getIntAttrName())) {
                    mapItems.add(mapItem);
                }
            }
        }
    }
    assertFalse(mapItems.isEmpty());
    // delete user schema fullname
    plainSchemaDAO.delete("fullname");
    plainSchemaDAO.flush();
    // check for schema deletion
    schema = plainSchemaDAO.find("fullname");
    assertNull(schema);
    plainSchemaDAO.clear();
    // check for mappings deletion
    mapItems = new HashSet<>();
    for (ExternalResource resource : resourceDAO.findAll()) {
        if (resource.getProvision(anyTypeDAO.findUser()).isPresent() && resource.getProvision(anyTypeDAO.findUser()).get().getMapping() != null) {
            for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).get().getMapping().getItems()) {
                if ("fullname".equals(mapItem.getIntAttrName())) {
                    mapItems.add(mapItem);
                }
            }
        }
    }
    assertTrue(mapItems.isEmpty());
    assertNull(plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class));
    assertNull(plainAttrDAO.find(UUID.randomUUID().toString(), UPlainAttr.class));
    assertFalse(userDAO.findByUsername("rossini").getPlainAttr("fullname").isPresent());
    assertFalse(userDAO.findByUsername("vivaldi").getPlainAttr("fullname").isPresent());
}
Also used : MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)55 Test (org.junit.jupiter.api.Test)22 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)21 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)15 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)14 User (org.apache.syncope.core.persistence.api.entity.user.User)13 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)12 UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)11 ArrayList (java.util.ArrayList)10 PlainAttrValue (org.apache.syncope.core.persistence.api.entity.PlainAttrValue)10 Transactional (org.springframework.transaction.annotation.Transactional)10 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)9 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)9 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 List (java.util.List)8 Optional (java.util.Optional)8 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)8 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)8