Search in sources :

Example 6 with Attribute

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

the class PropagationManagerImpl method createTasks.

/**
 * Create propagation tasks.
 *
 * @param any to be provisioned
 * @param password clear text password to be provisioned
 * @param changePwd whether password should be included for propagation attributes or not
 * @param enable whether user must be enabled or not
 * @param deleteOnResource whether any must be deleted anyway from external resource or not
 * @param propByRes operation to be performed per resource
 * @param vAttrs virtual attributes to be set
 * @return list of propagation tasks created
 */
protected List<PropagationTaskTO> createTasks(final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final boolean deleteOnResource, final PropagationByResource propByRes, final Collection<AttrTO> vAttrs) {
    LOG.debug("Provisioning {}:\n{}", any, propByRes);
    // Avoid duplicates - see javadoc
    propByRes.purge();
    LOG.debug("After purge {}:\n{}", any, propByRes);
    // Virtual attributes
    Set<String> virtualResources = new HashSet<>();
    virtualResources.addAll(propByRes.get(ResourceOperation.CREATE));
    virtualResources.addAll(propByRes.get(ResourceOperation.UPDATE));
    virtualResources.addAll(dao(any.getType().getKind()).findAllResourceKeys(any.getKey()));
    Map<String, Set<Attribute>> vAttrMap = new HashMap<>();
    if (vAttrs != null) {
        vAttrs.forEach(vAttr -> {
            VirSchema schema = virSchemaDAO.find(vAttr.getSchema());
            if (schema == null) {
                LOG.warn("Ignoring invalid {} {}", VirSchema.class.getSimpleName(), vAttr.getSchema());
            } else if (schema.isReadonly()) {
                LOG.warn("Ignoring read-only {} {}", VirSchema.class.getSimpleName(), vAttr.getSchema());
            } else if (anyUtilsFactory.getInstance(any).getAllowedSchemas(any, VirSchema.class).contains(schema) && virtualResources.contains(schema.getProvision().getResource().getKey())) {
                Set<Attribute> values = vAttrMap.get(schema.getProvision().getResource().getKey());
                if (values == null) {
                    values = new HashSet<>();
                    vAttrMap.put(schema.getProvision().getResource().getKey(), values);
                }
                values.add(AttributeBuilder.build(schema.getExtAttrName(), vAttr.getValues()));
                propByRes.add(ResourceOperation.UPDATE, schema.getProvision().getResource().getKey());
            } else {
                LOG.warn("{} not owned by or {} not allowed for {}", schema.getProvision().getResource(), schema, any);
            }
        });
    }
    LOG.debug("With virtual attributes {}:\n{}\n{}", any, propByRes, vAttrMap);
    List<PropagationTaskTO> tasks = new ArrayList<>();
    propByRes.asMap().forEach((resourceKey, operation) -> {
        ExternalResource resource = resourceDAO.find(resourceKey);
        Provision provision = resource == null ? null : resource.getProvision(any.getType()).orElse(null);
        List<? extends Item> mappingItems = provision == null ? Collections.<Item>emptyList() : MappingUtils.getPropagationItems(provision.getMapping().getItems());
        if (resource == null) {
            LOG.error("Invalid resource name specified: {}, ignoring...", resourceKey);
        } else if (provision == null) {
            LOG.error("No provision specified on resource {} for type {}, ignoring...", resource, any.getType());
        } else if (mappingItems.isEmpty()) {
            LOG.warn("Requesting propagation for {} but no propagation mapping provided for {}", any.getType(), resource);
        } else {
            PropagationTaskTO task = new PropagationTaskTO();
            task.setResource(resource.getKey());
            task.setObjectClassName(provision.getObjectClass().getObjectClassValue());
            task.setAnyTypeKind(any.getType().getKind());
            task.setAnyType(any.getType().getKey());
            if (!deleteOnResource) {
                task.setEntityKey(any.getKey());
            }
            task.setOperation(operation);
            task.setOldConnObjectKey(propByRes.getOldConnObjectKey(resource.getKey()));
            Pair<String, Set<Attribute>> preparedAttrs = mappingManager.prepareAttrs(any, password, changePwd, enable, provision);
            task.setConnObjectKey(preparedAttrs.getKey());
            // Check if any of mandatory attributes (in the mapping) is missing or not received any value:
            // if so, add special attributes that will be evaluated by PropagationTaskExecutor
            List<String> mandatoryMissing = new ArrayList<>();
            List<String> mandatoryNullOrEmpty = new ArrayList<>();
            mappingItems.stream().filter(item -> (!item.isConnObjectKey() && JexlUtils.evaluateMandatoryCondition(item.getMandatoryCondition(), any))).forEachOrdered(item -> {
                Attribute attr = AttributeUtil.find(item.getExtAttrName(), preparedAttrs.getValue());
                if (attr == null) {
                    mandatoryMissing.add(item.getExtAttrName());
                } else if (attr.getValue() == null || attr.getValue().isEmpty()) {
                    mandatoryNullOrEmpty.add(item.getExtAttrName());
                }
            });
            if (!mandatoryMissing.isEmpty()) {
                preparedAttrs.getValue().add(AttributeBuilder.build(PropagationTaskExecutor.MANDATORY_MISSING_ATTR_NAME, mandatoryMissing));
            }
            if (!mandatoryNullOrEmpty.isEmpty()) {
                preparedAttrs.getValue().add(AttributeBuilder.build(PropagationTaskExecutor.MANDATORY_NULL_OR_EMPTY_ATTR_NAME, mandatoryNullOrEmpty));
            }
            if (vAttrMap.containsKey(resource.getKey())) {
                preparedAttrs.getValue().addAll(vAttrMap.get(resource.getKey()));
            }
            task.setAttributes(POJOHelper.serialize(preparedAttrs.getValue()));
            tasks.add(task);
            LOG.debug("PropagationTask created: {}", task);
        }
    });
    return tasks;
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) PropagationManager(org.apache.syncope.core.provisioning.api.propagation.PropagationManager) POJOHelper(org.apache.syncope.core.provisioning.api.serialization.POJOHelper) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyUtilsFactory(org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory) Realm(org.apache.syncope.core.persistence.api.entity.Realm) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) Attribute(org.identityconnectors.framework.common.objects.Attribute) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) ConnObjectUtils(org.apache.syncope.core.provisioning.java.utils.ConnObjectUtils) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) Map(java.util.Map) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Item(org.apache.syncope.core.persistence.api.entity.resource.Item) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) Logger(org.slf4j.Logger) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttributeUtil(org.identityconnectors.framework.common.objects.AttributeUtil) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder) AnyDAO(org.apache.syncope.core.persistence.api.dao.AnyDAO) PropagationTaskExecutor(org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) Collections(java.util.Collections) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) HashSet(java.util.HashSet) Set(java.util.Set) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) HashMap(java.util.HashMap) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) Attribute(org.identityconnectors.framework.common.objects.Attribute) ArrayList(java.util.ArrayList) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) HashSet(java.util.HashSet)

Example 7 with Attribute

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

the class PullUtils method match.

/**
 * Finds internal realms based on external attributes and mapping.
 *
 * @param connObj external attributes
 * @param orgUnit mapping
 * @return list of matching realms' keys.
 */
public List<String> match(final ConnectorObject connObj, final OrgUnit orgUnit) {
    String connObjectKey = null;
    Optional<? extends OrgUnitItem> connObjectKeyItem = orgUnit.getConnObjectKeyItem();
    if (connObjectKeyItem != null) {
        Attribute connObjectKeyAttr = connObj.getAttributeByName(connObjectKeyItem.get().getExtAttrName());
        if (connObjectKeyAttr != null) {
            connObjectKey = AttributeUtil.getStringValue(connObjectKeyAttr);
        }
    }
    if (connObjectKey == null) {
        return Collections.emptyList();
    }
    for (ItemTransformer transformer : MappingUtils.getItemTransformers(connObjectKeyItem.get())) {
        List<Object> output = transformer.beforePull(connObjectKeyItem.get(), null, Collections.<Object>singletonList(connObjectKey));
        if (output != null && !output.isEmpty()) {
            connObjectKey = output.get(0).toString();
        }
    }
    List<String> result = new ArrayList<>();
    Realm realm;
    switch(connObjectKeyItem.get().getIntAttrName()) {
        case "key":
            realm = realmDAO.find(connObjectKey);
            if (realm != null) {
                result.add(realm.getKey());
            }
            break;
        case "name":
            result.addAll(realmDAO.findByName(connObjectKey).stream().map(Entity::getKey).collect(Collectors.toList()));
            break;
        case "fullpath":
            realm = realmDAO.findByFullPath(connObjectKey);
            if (realm != null) {
                result.add(realm.getKey());
            }
            break;
        default:
    }
    return result;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) Attribute(org.identityconnectors.framework.common.objects.Attribute) ItemTransformer(org.apache.syncope.core.provisioning.api.data.ItemTransformer) ArrayList(java.util.ArrayList) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 8 with Attribute

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

the class PullUtils method findByConnObjectKey.

private List<String> findByConnObjectKey(final ConnectorObject connObj, final Provision provision, final AnyUtils anyUtils) {
    String connObjectKey = null;
    Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
    if (connObjectKeyItem.isPresent()) {
        Attribute connObjectKeyAttr = connObj.getAttributeByName(connObjectKeyItem.get().getExtAttrName());
        if (connObjectKeyAttr != null) {
            connObjectKey = AttributeUtil.getStringValue(connObjectKeyAttr);
        }
    }
    if (connObjectKey == null) {
        return Collections.emptyList();
    }
    for (ItemTransformer transformer : MappingUtils.getItemTransformers(connObjectKeyItem.get())) {
        List<Object> output = transformer.beforePull(connObjectKeyItem.get(), null, Collections.<Object>singletonList(connObjectKey));
        if (output != null && !output.isEmpty()) {
            connObjectKey = output.get(0).toString();
        }
    }
    List<String> result = new ArrayList<>();
    IntAttrName intAttrName;
    try {
        intAttrName = intAttrNameParser.parse(connObjectKeyItem.get().getIntAttrName(), provision.getAnyType().getKind());
    } catch (ParseException e) {
        LOG.error("Invalid intAttrName '{}' specified, ignoring", connObjectKeyItem.get().getIntAttrName(), e);
        return result;
    }
    if (intAttrName.getField() != null) {
        switch(intAttrName.getField()) {
            case "key":
                Any<?> any = getAnyDAO(provision.getAnyType().getKind()).find(connObjectKey);
                if (any != null) {
                    result.add(any.getKey());
                }
                break;
            case "username":
                User user = userDAO.findByUsername(connObjectKey);
                if (user != null) {
                    result.add(user.getKey());
                }
                break;
            case "name":
                Group group = groupDAO.findByName(connObjectKey);
                if (group != null) {
                    result.add(group.getKey());
                }
                AnyObject anyObject = anyObjectDAO.findByName(connObjectKey);
                if (anyObject != null) {
                    result.add(anyObject.getKey());
                }
                break;
            default:
        }
    } else if (intAttrName.getSchemaType() != null) {
        switch(intAttrName.getSchemaType()) {
            case PLAIN:
                PlainAttrValue value = anyUtils.newPlainAttrValue();
                PlainSchema schema = plainSchemaDAO.find(intAttrName.getSchemaName());
                if (schema == null) {
                    value.setStringValue(connObjectKey);
                } else {
                    try {
                        value.parseValue(schema, connObjectKey);
                    } catch (ParsingValidationException e) {
                        LOG.error("While parsing provided __UID__ {}", value, e);
                        value.setStringValue(connObjectKey);
                    }
                }
                result.addAll(getAnyDAO(provision.getAnyType().getKind()).findByPlainAttrValue(intAttrName.getSchemaName(), value).stream().map(Entity::getKey).collect(Collectors.toList()));
                break;
            case DERIVED:
                result.addAll(getAnyDAO(provision.getAnyType().getKind()).findByDerAttrValue(intAttrName.getSchemaName(), connObjectKey).stream().map(Entity::getKey).collect(Collectors.toList()));
                break;
            default:
        }
    }
    return result;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) User(org.apache.syncope.core.persistence.api.entity.user.User) Attribute(org.identityconnectors.framework.common.objects.Attribute) ItemTransformer(org.apache.syncope.core.provisioning.api.data.ItemTransformer) ArrayList(java.util.ArrayList) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) ParseException(java.text.ParseException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema)

Example 9 with Attribute

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

the class ReconciliationReportlet method doExtract.

private void doExtract(final ContentHandler handler, final List<? extends Any<?>> anys) throws SAXException, ReportException {
    final Set<Missing> missing = new HashSet<>();
    final Set<Misaligned> misaligned = new HashSet<>();
    for (Any<?> any : anys) {
        missing.clear();
        misaligned.clear();
        AnyUtils anyUtils = anyUtilsFactory.getInstance(any);
        anyUtils.getAllResources(any).forEach(resource -> {
            Provision provision = resource.getProvision(any.getType()).orElse(null);
            Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
            final String connObjectKeyValue = connObjectKeyItem.isPresent() ? mappingManager.getConnObjectKeyValue(any, provision).get() : StringUtils.EMPTY;
            if (provision != null && connObjectKeyItem.isPresent() && StringUtils.isNotBlank(connObjectKeyValue)) {
                // 1. read from the underlying connector
                Connector connector = connFactory.getConnector(resource);
                ConnectorObject connectorObject = connector.getObject(provision.getObjectClass(), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue), MappingUtils.buildOperationOptions(provision.getMapping().getItems().iterator()));
                if (connectorObject == null) {
                    // 2. not found on resource?
                    LOG.error("Object {} with class {} not found on resource {}", connObjectKeyValue, provision.getObjectClass(), resource);
                    missing.add(new Missing(resource.getKey(), connObjectKeyValue));
                } else {
                    // 3. found but misaligned?
                    Pair<String, Set<Attribute>> preparedAttrs = mappingManager.prepareAttrs(any, null, false, null, provision);
                    preparedAttrs.getRight().add(AttributeBuilder.build(Uid.NAME, preparedAttrs.getLeft()));
                    preparedAttrs.getRight().add(AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), preparedAttrs.getLeft()));
                    final Map<String, Set<Object>> syncopeAttrs = new HashMap<>();
                    preparedAttrs.getRight().forEach(attr -> {
                        syncopeAttrs.put(attr.getName(), getValues(attr));
                    });
                    final Map<String, Set<Object>> resourceAttrs = new HashMap<>();
                    connectorObject.getAttributes().stream().filter(attr -> (!OperationalAttributes.PASSWORD_NAME.equals(attr.getName()) && !OperationalAttributes.ENABLE_NAME.equals(attr.getName()))).forEachOrdered(attr -> {
                        resourceAttrs.put(attr.getName(), getValues(attr));
                    });
                    syncopeAttrs.keySet().stream().filter(syncopeAttr -> !resourceAttrs.containsKey(syncopeAttr)).forEach(name -> {
                        misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, name, syncopeAttrs.get(name), Collections.emptySet()));
                    });
                    resourceAttrs.forEach((key, values) -> {
                        if (syncopeAttrs.containsKey(key)) {
                            if (!Objects.equals(syncopeAttrs.get(key), values)) {
                                misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, key, syncopeAttrs.get(key), values));
                            }
                        } else {
                            misaligned.add(new Misaligned(resource.getKey(), connObjectKeyValue, key, Collections.emptySet(), values));
                        }
                    });
                }
            }
        });
        if (!missing.isEmpty() || !misaligned.isEmpty()) {
            doExtract(handler, any, missing, misaligned);
        }
    }
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) Feature(org.apache.syncope.common.lib.report.ReconciliationReportletConf.Feature) FormatUtils(org.apache.syncope.core.provisioning.api.utils.FormatUtils) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Attribute(org.identityconnectors.framework.common.objects.Attribute) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) OperationalAttributes(org.identityconnectors.framework.common.objects.OperationalAttributes) AttributesImpl(org.xml.sax.helpers.AttributesImpl) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Set(java.util.Set) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Objects(java.util.Objects) Connector(org.apache.syncope.core.provisioning.api.Connector) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) Base64(java.util.Base64) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder) ReconciliationReportletConf(org.apache.syncope.common.lib.report.ReconciliationReportletConf) ConnectorFactory(org.apache.syncope.core.provisioning.api.ConnectorFactory) SAXException(org.xml.sax.SAXException) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) ReportletConfClass(org.apache.syncope.core.persistence.api.dao.ReportletConfClass) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) AnyUtilsFactory(org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) ReportletConf(org.apache.syncope.common.lib.report.ReportletConf) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) SearchCondConverter(org.apache.syncope.core.persistence.api.search.SearchCondConverter) ContentHandler(org.xml.sax.ContentHandler) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Uid(org.identityconnectors.framework.common.objects.Uid) User(org.apache.syncope.core.persistence.api.entity.user.User) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) AnyDAO(org.apache.syncope.core.persistence.api.dao.AnyDAO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) Connector(org.apache.syncope.core.provisioning.api.Connector) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) HashSet(java.util.HashSet)

Example 10 with Attribute

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

the class MappingManagerImpl method prepareAttrs.

@Override
public Pair<String, Set<Attribute>> prepareAttrs(final Realm realm, final OrgUnit orgUnit) {
    LOG.debug("Preparing resource attributes for {} with orgUnit {}", realm, orgUnit);
    Set<Attribute> attributes = new HashSet<>();
    String connObjectKey = null;
    for (Item orgUnitItem : MappingUtils.getPropagationItems(orgUnit.getItems())) {
        LOG.debug("Processing expression '{}'", orgUnitItem.getIntAttrName());
        String value = getIntValue(realm, orgUnitItem);
        if (orgUnitItem.isConnObjectKey()) {
            connObjectKey = value;
        }
        Attribute alreadyAdded = AttributeUtil.find(orgUnitItem.getExtAttrName(), attributes);
        if (alreadyAdded == null) {
            if (value == null) {
                attributes.add(AttributeBuilder.build(orgUnitItem.getExtAttrName()));
            } else {
                attributes.add(AttributeBuilder.build(orgUnitItem.getExtAttrName(), value));
            }
        } else if (value != null) {
            attributes.remove(alreadyAdded);
            Set<Object> values = new HashSet<>();
            if (alreadyAdded.getValue() != null && !alreadyAdded.getValue().isEmpty()) {
                values.addAll(alreadyAdded.getValue());
            }
            values.add(value);
            attributes.add(AttributeBuilder.build(orgUnitItem.getExtAttrName(), values));
        }
    }
    Optional<? extends OrgUnitItem> connObjectKeyItem = orgUnit.getConnObjectKeyItem();
    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));
        }
        attributes.add(MappingUtils.evaluateNAME(realm, orgUnit, connObjectKey));
    }
    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) Set(java.util.Set) HashSet(java.util.HashSet) Attribute(org.identityconnectors.framework.common.objects.Attribute) HashSet(java.util.HashSet)

Aggregations

Attribute (org.identityconnectors.framework.common.objects.Attribute)35 HashSet (java.util.HashSet)19 ArrayList (java.util.ArrayList)14 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)12 Transactional (org.springframework.transaction.annotation.Transactional)12 User (org.apache.syncope.core.persistence.api.entity.user.User)11 List (java.util.List)10 Set (java.util.Set)10 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)10 Uid (org.identityconnectors.framework.common.objects.Uid)10 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)9 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)8 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)8 Name (org.identityconnectors.framework.common.objects.Name)8 AttributeBuilder (org.identityconnectors.framework.common.objects.AttributeBuilder)7 Map (java.util.Map)6 StringUtils (org.apache.commons.lang3.StringUtils)6 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)6 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)6 OrgUnitItem (org.apache.syncope.core.persistence.api.entity.resource.OrgUnitItem)6