Search in sources :

Example 11 with Connector

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

the class LDAPMembershipPullActions method populateMemberships.

/**
 * Pull Syncope memberships with the situation read on the external resource's group.
 *
 * @param profile pull profile
 * @param delta representing the pullong group
 * @param groupTO group after modification performed by the handler
 * @throws JobExecutionException if anything goes wrong
 */
protected void populateMemberships(final ProvisioningProfile<?, ?> profile, final SyncDelta delta, final GroupTO groupTO) throws JobExecutionException {
    Connector connector = profile.getConnector();
    getMembAttrValues(delta, connector).stream().map(membValue -> {
        Set<String> memb = memberships.get(membValue.toString());
        if (memb == null) {
            memb = new HashSet<>();
            memberships.put(membValue.toString(), memb);
        }
        return memb;
    }).forEachOrdered(memb -> {
        memb.add(groupTO.getKey());
    });
}
Also used : ProvisioningProfile(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ConnConfProperty(org.apache.syncope.common.lib.types.ConnConfProperty) Attribute(org.identityconnectors.framework.common.objects.Attribute) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) EntityTO(org.apache.syncope.common.lib.to.EntityTO) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) Map(java.util.Map) SetUMembershipsJob(org.apache.syncope.core.provisioning.java.job.SetUMembershipsJob) SyncDelta(org.identityconnectors.framework.common.objects.SyncDelta) Logger(org.slf4j.Logger) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Set(java.util.Set) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) JobExecutionException(org.quartz.JobExecutionException) Connector(org.apache.syncope.core.provisioning.api.Connector) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) List(java.util.List) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) Optional(java.util.Optional) Collections(java.util.Collections) Connector(org.apache.syncope.core.provisioning.api.Connector) HashSet(java.util.HashSet) Set(java.util.Set) HashSet(java.util.HashSet)

Example 12 with Connector

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

the class VirAttrHandlerImpl method getValues.

private Map<VirSchema, List<String>> getValues(final Any<?> any, final Set<VirSchema> schemas) {
    Set<ExternalResource> ownedResources = anyUtilsFactory.getInstance(any).getAllResources(any);
    Map<VirSchema, List<String>> result = new HashMap<>();
    Map<Provision, Set<VirSchema>> toRead = new HashMap<>();
    for (VirSchema schema : schemas) {
        if (ownedResources.contains(schema.getProvision().getResource())) {
            VirAttrCacheValue virAttrCacheValue = virAttrCache.get(any.getType().getKey(), any.getKey(), schema.getKey());
            if (virAttrCache.isValidEntry(virAttrCacheValue)) {
                LOG.debug("Values for {} found in cache: {}", schema, virAttrCacheValue);
                result.put(schema, virAttrCacheValue.getValues());
            } else {
                Set<VirSchema> schemasToRead = toRead.get(schema.getProvision());
                if (schemasToRead == null) {
                    schemasToRead = new HashSet<>();
                    toRead.put(schema.getProvision(), schemasToRead);
                }
                schemasToRead.add(schema);
            }
        } else {
            LOG.debug("Not considering {} since {} is not assigned to {}", schema, any, schema.getProvision().getResource());
        }
    }
    for (Map.Entry<Provision, Set<VirSchema>> entry : toRead.entrySet()) {
        LOG.debug("About to read from {}: {}", entry.getKey(), entry.getValue());
        Optional<MappingItem> connObjectKeyItem = MappingUtils.getConnObjectKeyItem(entry.getKey());
        String connObjectKeyValue = connObjectKeyItem.isPresent() ? mappingManager.getConnObjectKeyValue(any, entry.getKey()).orElse(null) : null;
        if (!connObjectKeyItem.isPresent() || connObjectKeyValue == null) {
            LOG.error("No ConnObjectKey or value found for {}, ignoring...", entry.getKey());
        } else {
            Set<MappingItem> linkingMappingItems = new HashSet<>();
            linkingMappingItems.add(connObjectKeyItem.get());
            linkingMappingItems.addAll(entry.getValue().stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet()));
            Connector connector = connFactory.getConnector(entry.getKey().getResource());
            try {
                ConnectorObject connectorObject = connector.getObject(entry.getKey().getObjectClass(), AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue), MappingUtils.buildOperationOptions(linkingMappingItems.iterator()));
                if (connectorObject == null) {
                    LOG.debug("No read from {} with filter '{} == {}'", entry.getKey(), connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue);
                } else {
                    entry.getValue().forEach(schema -> {
                        Attribute attr = connectorObject.getAttributeByName(schema.getExtAttrName());
                        if (attr != null) {
                            VirAttrCacheValue virAttrCacheValue = new VirAttrCacheValue();
                            virAttrCacheValue.setValues(attr.getValue());
                            virAttrCache.put(any.getType().getKey(), any.getKey(), schema.getKey(), virAttrCacheValue);
                            LOG.debug("Values for {} set in cache: {}", schema, virAttrCacheValue);
                            result.put(schema, virAttrCacheValue.getValues());
                        }
                    });
                }
            } catch (Exception e) {
                LOG.error("Error reading from {}", entry.getKey(), e);
            }
        }
    }
    return result;
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) Connector(org.apache.syncope.core.provisioning.api.Connector) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) HashSet(java.util.HashSet) Set(java.util.Set) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) HashMap(java.util.HashMap) Attribute(org.identityconnectors.framework.common.objects.Attribute) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) VirAttrCacheValue(org.apache.syncope.core.provisioning.api.cache.VirAttrCacheValue) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

Connector (org.apache.syncope.core.provisioning.api.Connector)12 List (java.util.List)8 Set (java.util.Set)8 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)8 Map (java.util.Map)7 Optional (java.util.Optional)7 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)7 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)7 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)7 Attribute (org.identityconnectors.framework.common.objects.Attribute)7 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 HashSet (java.util.HashSet)6 StringUtils (org.apache.commons.lang3.StringUtils)6 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)6 ObjectClass (org.identityconnectors.framework.common.objects.ObjectClass)6 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 Collectors (java.util.stream.Collectors)5 IteratorChain (org.apache.syncope.common.lib.collections.IteratorChain)5