Search in sources :

Example 11 with IntAttrName

use of org.apache.syncope.core.provisioning.api.IntAttrName 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 12 with IntAttrName

use of org.apache.syncope.core.provisioning.api.IntAttrName in project syncope by apache.

the class IntAttrNameParser method parse.

@Transactional(readOnly = true)
public IntAttrName parse(final String intAttrName, final AnyTypeKind provisionAnyTypeKind) throws ParseException {
    IntAttrName result = new IntAttrName();
    Matcher matcher;
    if (intAttrName.indexOf('.') == -1) {
        matcher = PRIVILEGE_PATTERN.matcher(intAttrName);
        if (matcher.matches()) {
            result.setAnyTypeKind(AnyTypeKind.USER);
            result.setPrivilegesOfApplication(matcher.group(1));
        } else {
            result.setAnyTypeKind(provisionAnyTypeKind);
            setFieldOrSchemaName(intAttrName, result.getAnyTypeKind(), result);
        }
    } else {
        matcher = ENCLOSING_GROUP_PATTERN.matcher(intAttrName);
        if (matcher.matches()) {
            result.setAnyTypeKind(AnyTypeKind.GROUP);
            result.setEnclosingGroup(matcher.group(1));
            setFieldOrSchemaName(matcher.group(2), result.getAnyTypeKind(), result);
        } else {
            matcher = RELATED_ANY_OBJECT_PATTERN.matcher(intAttrName);
            if (matcher.matches()) {
                result.setAnyTypeKind(AnyTypeKind.ANY_OBJECT);
                result.setRelatedAnyObject(matcher.group(1));
                setFieldOrSchemaName(matcher.group(2), result.getAnyTypeKind(), result);
            } else {
                matcher = MEMBERSHIP_PATTERN.matcher(intAttrName);
                if (matcher.matches()) {
                    result.setAnyTypeKind(AnyTypeKind.USER);
                    result.setMembershipOfGroup(matcher.group(1));
                    setFieldOrSchemaName(matcher.group(2), result.getAnyTypeKind(), result);
                } else {
                    throw new ParseException("Unparsable expression: " + intAttrName, 0);
                }
            }
        }
    }
    return result;
}
Also used : Matcher(java.util.regex.Matcher) ParseException(java.text.ParseException) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with IntAttrName

use of org.apache.syncope.core.provisioning.api.IntAttrName in project syncope by apache.

the class AbstractAnyDataBinder method evaluateMandatoryCondition.

private List<String> evaluateMandatoryCondition(final Provision provision, final Any<?> any) {
    List<String> missingAttrNames = new ArrayList<>();
    MappingUtils.getPropagationItems(provision.getMapping().getItems()).forEach(mapItem -> {
        IntAttrName intAttrName = null;
        try {
            intAttrName = intAttrNameParser.parse(mapItem.getIntAttrName(), provision.getAnyType().getKind());
        } catch (ParseException e) {
            LOG.error("Invalid intAttrName '{}', ignoring", mapItem.getIntAttrName(), e);
        }
        if (intAttrName != null && intAttrName.getSchemaType() != null) {
            List<PlainAttrValue> values = mappingManager.getIntValues(provision, mapItem, intAttrName, any);
            if (values.isEmpty() && JexlUtils.evaluateMandatoryCondition(mapItem.getMandatoryCondition(), any)) {
                missingAttrNames.add(mapItem.getIntAttrName());
            }
        }
    });
    return missingAttrNames;
}
Also used : ArrayList(java.util.ArrayList) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) ParseException(java.text.ParseException) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName)

Example 14 with IntAttrName

use of org.apache.syncope.core.provisioning.api.IntAttrName in project syncope by apache.

the class SAML2IdPDataBinderImpl method populateItems.

private void populateItems(final SAML2IdPTO idpTO, final SAML2IdP idp, final AnyTypeClassTO allowedSchemas) {
    SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
    SyncopeClientException invalidMapping = SyncopeClientException.build(ClientExceptionType.InvalidMapping);
    SyncopeClientException requiredValuesMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
    for (ItemTO itemTO : idpTO.getItems()) {
        if (itemTO == null) {
            LOG.error("Null {}", ItemTO.class.getSimpleName());
            invalidMapping.getElements().add("Null " + ItemTO.class.getSimpleName());
        } else if (itemTO.getIntAttrName() == null) {
            requiredValuesMissing.getElements().add("intAttrName");
            scce.addException(requiredValuesMissing);
        } else {
            IntAttrName intAttrName = null;
            try {
                intAttrName = intAttrNameParser.parse(itemTO.getIntAttrName(), AnyTypeKind.USER);
            } catch (ParseException e) {
                LOG.error("Invalid intAttrName '{}' specified, ignoring", itemTO.getIntAttrName(), e);
            }
            if (intAttrName == null || intAttrName.getSchemaType() == null && intAttrName.getField() == null) {
                LOG.error("'{}' not existing", itemTO.getIntAttrName());
                invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not existing");
            } else {
                boolean allowed = true;
                if (intAttrName.getSchemaType() != null && intAttrName.getEnclosingGroup() == null && intAttrName.getRelatedAnyObject() == null) {
                    switch(intAttrName.getSchemaType()) {
                        case PLAIN:
                            allowed = allowedSchemas.getPlainSchemas().contains(intAttrName.getSchemaName());
                            break;
                        case DERIVED:
                            allowed = allowedSchemas.getDerSchemas().contains(intAttrName.getSchemaName());
                            break;
                        case VIRTUAL:
                            allowed = allowedSchemas.getVirSchemas().contains(intAttrName.getSchemaName());
                            break;
                        default:
                    }
                }
                if (allowed) {
                    // no mandatory condition implies mandatory condition false
                    if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() == null ? "false" : itemTO.getMandatoryCondition())) {
                        SyncopeClientException invalidMandatoryCondition = SyncopeClientException.build(ClientExceptionType.InvalidValues);
                        invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
                        scce.addException(invalidMandatoryCondition);
                    }
                    SAML2IdPItem item = entityFactory.newEntity(SAML2IdPItem.class);
                    BeanUtils.copyProperties(itemTO, item, ITEM_IGNORE_PROPERTIES);
                    item.setIdP(idp);
                    item.setPurpose(MappingPurpose.NONE);
                    if (item.isConnObjectKey()) {
                        if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
                            invalidMapping.getElements().add("Virtual attributes cannot be set as ConnObjectKey");
                        }
                        if ("password".equals(intAttrName.getField())) {
                            invalidMapping.getElements().add("Password attributes cannot be set as ConnObjectKey");
                        }
                        idp.setConnObjectKeyItem(item);
                    } else {
                        idp.add(item);
                    }
                } else {
                    LOG.error("'{}' not allowed", itemTO.getIntAttrName());
                    invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not allowed");
                }
            }
        }
    }
    if (!invalidMapping.getElements().isEmpty()) {
        scce.addException(invalidMapping);
    }
    if (scce.hasExceptions()) {
        throw scce;
    }
}
Also used : SAML2IdPItem(org.apache.syncope.core.persistence.api.entity.SAML2IdPItem) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ParseException(java.text.ParseException) ItemTO(org.apache.syncope.common.lib.to.ItemTO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName)

Example 15 with IntAttrName

use of org.apache.syncope.core.provisioning.api.IntAttrName in project syncope by apache.

the class IntAttrNameParserTest method privileges.

@Test
public void privileges() throws ParseException {
    IntAttrName intAttrName = intAttrNameParser.parse("privileges[mightyApp]", AnyTypeKind.USER);
    assertNotNull(intAttrName);
    assertEquals(AnyTypeKind.USER, intAttrName.getAnyTypeKind());
    assertNull(intAttrName.getField());
    assertNull(intAttrName.getSchemaName());
    assertNull(intAttrName.getSchemaType());
    assertNull(intAttrName.getEnclosingGroup());
    assertNull(intAttrName.getRelatedAnyObject());
    assertEquals("mightyApp", intAttrName.getPrivilegesOfApplication());
}
Also used : IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) Test(org.junit.jupiter.api.Test)

Aggregations

IntAttrName (org.apache.syncope.core.provisioning.api.IntAttrName)17 ParseException (java.text.ParseException)11 ArrayList (java.util.ArrayList)8 PlainAttrValue (org.apache.syncope.core.persistence.api.entity.PlainAttrValue)6 Test (org.junit.jupiter.api.Test)6 List (java.util.List)5 Optional (java.util.Optional)5 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)5 ItemTransformer (org.apache.syncope.core.provisioning.api.data.ItemTransformer)5 Collections (java.util.Collections)4 AttrTO (org.apache.syncope.common.lib.to.AttrTO)4 ParsingValidationException (org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException)4 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)4 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)4 User (org.apache.syncope.core.persistence.api.entity.user.User)4 Attribute (org.identityconnectors.framework.common.objects.Attribute)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Pair (org.apache.commons.lang3.tuple.Pair)3 AttrSchemaType (org.apache.syncope.common.lib.types.AttrSchemaType)3