Search in sources :

Example 11 with UPlainAttr

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

the class UserTest method issueSYNCOPE1016.

@Test
public void issueSYNCOPE1016() {
    User user = userDAO.findByUsername("rossini");
    Date initial = user.getLastChangeDate();
    assertNotNull(initial);
    UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
    attr.setOwner(user);
    attr.setSchema(plainSchemaDAO.find("obscure"));
    attr.add("testvalue", anyUtilsFactory.getInstance(AnyTypeKind.USER));
    user.add(attr);
    userDAO.save(user);
    userDAO.flush();
    user = userDAO.findByUsername("rossini");
    Date afterwards = user.getLastChangeDate();
    assertNotNull(afterwards);
    assertTrue(afterwards.after(initial));
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) Date(java.util.Date) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 12 with UPlainAttr

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

the class NotificationManagerImpl method getRecipientEmail.

private String getRecipientEmail(final String recipientAttrName, final User user) {
    String email = null;
    IntAttrName intAttrName;
    try {
        intAttrName = intAttrNameParser.parse(recipientAttrName, AnyTypeKind.USER);
    } catch (ParseException e) {
        LOG.error("Invalid intAttrName '{}' specified as recipient, ignoring", recipientAttrName, e);
        return email;
    }
    if ("username".equals(intAttrName.getField())) {
        email = user.getUsername();
    } else if (intAttrName.getSchemaType() != null) {
        UMembership membership = null;
        if (intAttrName.getMembershipOfGroup() != null) {
            Group group = groupDAO.findByName(intAttrName.getMembershipOfGroup());
            if (group != null) {
                membership = user.getMembership(group.getKey()).orElse(null);
            }
        }
        switch(intAttrName.getSchemaType()) {
            case PLAIN:
                Optional<? extends UPlainAttr> attr = membership == null ? user.getPlainAttr(recipientAttrName) : user.getPlainAttr(recipientAttrName, membership);
                if (attr.isPresent()) {
                    email = attr.get().getValuesAsStrings().isEmpty() ? null : attr.get().getValuesAsStrings().get(0);
                }
                break;
            case DERIVED:
                DerSchema schema = derSchemaDAO.find(recipientAttrName);
                if (schema == null) {
                    LOG.warn("Ignoring non existing {} {}", DerSchema.class.getSimpleName(), recipientAttrName);
                } else {
                    email = membership == null ? derAttrHander.getValue(user, schema) : derAttrHander.getValue(user, membership, schema);
                }
                break;
            case VIRTUAL:
                VirSchema virSchema = virSchemaDAO.find(recipientAttrName);
                if (virSchema == null) {
                    LOG.warn("Ignoring non existing {} {}", VirSchema.class.getSimpleName(), recipientAttrName);
                } else {
                    List<String> virAttrValues = membership == null ? virAttrHander.getValues(user, virSchema) : virAttrHander.getValues(user, membership, virSchema);
                    email = virAttrValues.isEmpty() ? null : virAttrValues.get(0);
                }
                break;
            default:
        }
    }
    return email;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) Optional(java.util.Optional) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName)

Example 13 with UPlainAttr

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

the class GoogleAppsPropagationActions method after.

@Transactional
@Override
public void after(final PropagationTask task, final TaskExec execution, final ConnectorObject afterObj) {
    if (task.getOperation() == ResourceOperation.DELETE || task.getOperation() == ResourceOperation.NONE) {
        return;
    }
    if (AnyTypeKind.USER != task.getAnyTypeKind()) {
        return;
    }
    User user = userDAO.find(task.getEntityKey());
    if (user == null) {
        LOG.error("Could not find user {}, skipping", task.getEntityKey());
    } else {
        boolean modified = false;
        AnyUtils anyUtils = anyUtilsFactory.getInstance(user);
        PlainSchema googleAppsId = plainSchemaDAO.find(getGoogleAppsIdSchema());
        if (googleAppsId == null) {
            LOG.error("Could not find schema {}, skipping", getGoogleAppsIdSchema());
        } else {
            // set back the __UID__ received by Google
            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(afterObj.getUid().getUidValue(), anyUtils);
                    modified = true;
                } catch (InvalidPlainAttrValueException e) {
                    LOG.error("Invalid value for attribute {}: {}", googleAppsId.getKey(), afterObj.getUid().getUidValue(), e);
                }
            } else {
                LOG.debug("User {} has already {} assigned: {}", user, googleAppsId.getKey(), attr.getValuesAsStrings());
            }
        }
        if (modified) {
            userDAO.save(user);
        }
    }
}
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 14 with UPlainAttr

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

the class PlainAttrTest method findByKey.

@Test
public void findByKey() {
    UPlainAttr attribute = plainAttrDAO.find("01f22fbd-b672-40af-b528-686d9b27ebc4", UPlainAttr.class);
    assertNotNull(attribute);
    attribute = plainAttrDAO.find("9d0d9e40-1b18-488e-9482-37dab82163c9", UPlainAttr.class);
    assertNotNull(attribute);
}
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 15 with UPlainAttr

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

the class PlainAttrTest method validateAndSave.

@Test
public void validateAndSave() {
    User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
    PlainSchema emailSchema = plainSchemaDAO.find("email");
    assertNotNull(emailSchema);
    PlainSchema fullnameSchema = plainSchemaDAO.find("fullname");
    assertNotNull(fullnameSchema);
    UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
    attr.setOwner(user);
    attr.setSchema(emailSchema);
    UPlainAttrUniqueValue uauv = entityFactory.newEntity(UPlainAttrUniqueValue.class);
    uauv.setAttr(attr);
    uauv.setSchema(fullnameSchema);
    uauv.setStringValue("a value");
    attr.setUniqueValue(uauv);
    user.add(attr);
    InvalidEntityException iee = null;
    try {
        userDAO.save(user);
        fail("This should not happen");
    } catch (InvalidEntityException e) {
        iee = e;
    }
    assertNotNull(iee);
    // for attribute
    assertTrue(iee.hasViolation(EntityViolationType.InvalidValueList));
    // for uauv
    assertTrue(iee.hasViolation(EntityViolationType.InvalidPlainAttr));
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) UPlainAttrUniqueValue(org.apache.syncope.core.persistence.api.entity.user.UPlainAttrUniqueValue) 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) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

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