Search in sources :

Example 6 with UPlainAttr

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

the class PlainAttrTest method read.

@Test
public void read() {
    UPlainAttr attribute = plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class);
    assertNotNull(attribute);
    assertTrue(attribute.getValues().isEmpty());
    assertNotNull(attribute.getUniqueValue());
}
Also used : 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 7 with UPlainAttr

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

the class PlainAttrTest method save.

@Test
public void save() throws ClassNotFoundException {
    User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
    PlainSchema emailSchema = plainSchemaDAO.find("email");
    assertNotNull(emailSchema);
    UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
    attr.setOwner(user);
    attr.setSchema(emailSchema);
    Exception thrown = null;
    try {
        attr.add("john.doe@gmail.com", anyUtilsFactory.getInstance(AnyTypeKind.USER));
        attr.add("mario.rossi@gmail.com", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    } catch (ValidationException e) {
        thrown = e;
    }
    assertNull(thrown);
    try {
        attr.add("http://www.apache.org", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    } catch (ValidationException e) {
        thrown = e;
    }
    assertNotNull(thrown);
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) ValidationException(javax.validation.ValidationException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) ValidationException(javax.validation.ValidationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 8 with UPlainAttr

use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr 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 9 with UPlainAttr

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

the class PlainAttrTest method deleteAttributeValue.

@Test
public void deleteAttributeValue() {
    UPlainAttrValue value = plainAttrValueDAO.find("7034de3b-3687-4db5-8454-363468f1a9de", UPlainAttrValue.class);
    int attributeValueNumber = value.getAttr().getValues().size();
    plainAttrValueDAO.delete(value.getKey(), UPlainAttrValue.class);
    plainAttrValueDAO.flush();
    assertNull(plainAttrValueDAO.find(value.getKey(), UPlainAttrValue.class));
    UPlainAttr attribute = plainAttrDAO.find("9d0d9e40-1b18-488e-9482-37dab82163c9", UPlainAttr.class);
    assertEquals(attribute.getValues().size(), attributeValueNumber - 1);
}
Also used : UPlainAttrValue(org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue) 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 10 with UPlainAttr

use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr 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)

Aggregations

UPlainAttr (org.apache.syncope.core.persistence.api.entity.user.UPlainAttr)18 User (org.apache.syncope.core.persistence.api.entity.user.User)13 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)13 Test (org.junit.jupiter.api.Test)13 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)10 Transactional (org.springframework.transaction.annotation.Transactional)5 InvalidEntityException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException)4 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)4 Group (org.apache.syncope.core.persistence.api.entity.group.Group)4 Date (java.util.Date)3 List (java.util.List)3 UMembership (org.apache.syncope.core.persistence.api.entity.user.UMembership)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Optional (java.util.Optional)2 ValidationException (javax.validation.ValidationException)2 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)2 InvalidPlainAttrValueException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException)2 UPlainAttrValue (org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue)2 URelationship (org.apache.syncope.core.persistence.api.entity.user.URelationship)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2