Search in sources :

Example 11 with Name

use of org.identityconnectors.framework.common.objects.Name in project syncope by apache.

the class MappingManagerImpl method prepareAttrs.

@Transactional(readOnly = true)
@Override
public Pair<String, Set<Attribute>> prepareAttrs(final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final Provision provision) {
    LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}", any, provision, any.getPlainAttrs());
    Set<Attribute> attributes = new HashSet<>();
    String connObjectKey = null;
    for (Item mapItem : MappingUtils.getPropagationItems(provision.getMapping().getItems())) {
        LOG.debug("Processing expression '{}'", mapItem.getIntAttrName());
        try {
            Pair<String, Attribute> preparedAttr = prepareAttr(provision, mapItem, any, password);
            if (preparedAttr != null) {
                if (preparedAttr.getLeft() != null) {
                    connObjectKey = preparedAttr.getLeft();
                }
                if (preparedAttr.getRight() != null) {
                    Attribute alreadyAdded = AttributeUtil.find(preparedAttr.getRight().getName(), attributes);
                    if (alreadyAdded == null) {
                        attributes.add(preparedAttr.getRight());
                    } else {
                        attributes.remove(alreadyAdded);
                        Set<Object> values = new HashSet<>();
                        if (alreadyAdded.getValue() != null && !alreadyAdded.getValue().isEmpty()) {
                            values.addAll(alreadyAdded.getValue());
                        }
                        if (preparedAttr.getRight().getValue() != null) {
                            values.addAll(preparedAttr.getRight().getValue());
                        }
                        attributes.add(AttributeBuilder.build(preparedAttr.getRight().getName(), values));
                    }
                }
            }
        } catch (Exception e) {
            LOG.error("Expression '{}' processing failed", mapItem.getIntAttrName(), e);
        }
    }
    Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
    if (connObjectKeyItem.isPresent()) {
        Attribute connObjectKeyExtAttr = AttributeUtil.find(connObjectKeyItem.get().getExtAttrName(), attributes);
        if (connObjectKeyExtAttr != null) {
            attributes.remove(connObjectKeyExtAttr);
            attributes.add(AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey));
        }
        Name name = MappingUtils.evaluateNAME(any, provision, connObjectKey);
        attributes.add(name);
        if (connObjectKey != null && !connObjectKey.equals(name.getNameValue()) && connObjectKeyExtAttr == null) {
            attributes.add(AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKey));
        }
    }
    if (enable != null) {
        attributes.add(AttributeBuilder.buildEnabled(enable));
    }
    if (!changePwd) {
        Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes);
        if (pwdAttr != null) {
            attributes.remove(pwdAttr);
        }
    }
    return Pair.of(connObjectKey, attributes);
}
Also used : OrgUnitItem(org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Item(org.apache.syncope.core.persistence.api.entity.resource.Item) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Attribute(org.identityconnectors.framework.common.objects.Attribute) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) ParseException(java.text.ParseException) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) HashSet(java.util.HashSet) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) Name(org.identityconnectors.framework.common.objects.Name) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with Name

use of org.identityconnectors.framework.common.objects.Name in project syncope by apache.

the class MappingTest method anyConnObjectLink.

@Test
public void anyConnObjectLink() {
    ExternalResource ldap = resourceDAO.find("resource-ldap");
    assertNotNull(ldap);
    Provision provision = ldap.getProvision(anyTypeDAO.findUser()).get();
    assertNotNull(provision);
    assertNotNull(provision.getMapping());
    assertNotNull(provision.getMapping().getConnObjectLink());
    User user = userDAO.findByUsername("rossini");
    assertNotNull(user);
    Name name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
    assertEquals("uid=rossini,ou=people,o=isp", name.getNameValue());
    provision.getMapping().setConnObjectLink("'uid=' + username + realm.replaceAll('/', ',o=') + ',ou=people,o=isp'");
    name = MappingUtils.evaluateNAME(user, provision, user.getUsername());
    assertEquals("uid=rossini,o=even,ou=people,o=isp", name.getNameValue());
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) User(org.apache.syncope.core.persistence.api.entity.user.User) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) Name(org.identityconnectors.framework.common.objects.Name) Test(org.junit.jupiter.api.Test)

Aggregations

Name (org.identityconnectors.framework.common.objects.Name)12 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Attribute (org.identityconnectors.framework.common.objects.Attribute)6 Transactional (org.springframework.transaction.annotation.Transactional)6 List (java.util.List)4 Set (java.util.Set)4 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)4 OrgUnitItem (org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem)4 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)4 Uid (org.identityconnectors.framework.common.objects.Uid)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Collections (java.util.Collections)3 Date (java.util.Date)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3 AnyObjectDAO (org.apache.syncope.core.persistence.api.dao.AnyObjectDAO)3