Search in sources :

Example 1 with Connector

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

the class AbstractProvisioningJobDelegate method doExecute.

@Override
protected String doExecute(final boolean dryRun) throws JobExecutionException {
    try {
        Class<T> clazz = getTaskClassReference();
        if (!clazz.isAssignableFrom(task.getClass())) {
            throw new JobExecutionException("Task " + task.getKey() + " isn't a ProvisioningTask");
        }
        T provisioningTask = clazz.cast(task);
        Connector connector;
        try {
            connector = connFactory.getConnector(provisioningTask.getResource());
        } catch (Exception e) {
            String msg = String.format("Connector instance bean for resource %s and connInstance %s not found", provisioningTask.getResource(), provisioningTask.getResource().getConnector());
            throw new JobExecutionException(msg, e);
        }
        boolean noMapping = true;
        for (Provision provision : provisioningTask.getResource().getProvisions()) {
            Mapping mapping = provision.getMapping();
            if (mapping != null) {
                noMapping = false;
                if (mapping.getConnObjectKeyItem() == null) {
                    throw new JobExecutionException("Invalid ConnObjectKey mapping for provision " + provision);
                }
            }
        }
        if (noMapping) {
            noMapping = provisioningTask.getResource().getOrgUnit() == null;
        }
        if (noMapping) {
            return "No provisions nor orgUnit available: aborting...";
        }
        return doExecuteProvisioning(provisioningTask, connector, dryRun);
    } catch (Throwable t) {
        LOG.error("While executing provisioning job {}", getClass().getName(), t);
        throw t;
    }
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) Connector(org.apache.syncope.core.provisioning.api.Connector) JobExecutionException(org.quartz.JobExecutionException) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) JobExecutionException(org.quartz.JobExecutionException)

Example 2 with Connector

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

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

the class PullJobDelegate method doExecuteProvisioning.

@Override
protected String doExecuteProvisioning(final PullTask pullTask, final Connector connector, final boolean dryRun) throws JobExecutionException {
    LOG.debug("Executing pull on {}", pullTask.getResource());
    List<PullActions> actions = new ArrayList<>();
    pullTask.getActions().forEach(impl -> {
        try {
            actions.add(ImplementationManager.build(impl));
        } catch (Exception e) {
            LOG.warn("While building {}", impl, e);
        }
    });
    profile = new ProvisioningProfile<>(connector, pullTask);
    profile.getActions().addAll(actions);
    profile.setDryRun(dryRun);
    profile.setResAct(pullTask.getResource().getPullPolicy() == null ? ConflictResolutionAction.IGNORE : pullTask.getResource().getPullPolicy().getConflictResolutionAction());
    latestSyncTokens.clear();
    if (!profile.isDryRun()) {
        for (PullActions action : actions) {
            action.beforeAll(profile);
        }
    }
    status.set("Initialization completed");
    // First realms...
    if (pullTask.getResource().getOrgUnit() != null) {
        status.set("Pulling " + pullTask.getResource().getOrgUnit().getObjectClass().getObjectClassValue());
        OrgUnit orgUnit = pullTask.getResource().getOrgUnit();
        OperationOptions options = MappingUtils.buildOperationOptions(MappingUtils.getPullItems(orgUnit.getItems()).iterator());
        rhandler = buildRealmHandler();
        try {
            switch(pullTask.getPullMode()) {
                case INCREMENTAL:
                    if (!dryRun) {
                        latestSyncTokens.put(orgUnit.getObjectClass(), orgUnit.getSyncToken());
                    }
                    connector.sync(orgUnit.getObjectClass(), orgUnit.getSyncToken(), rhandler, options);
                    if (!dryRun) {
                        orgUnit.setSyncToken(latestSyncTokens.get(orgUnit.getObjectClass()));
                        resourceDAO.save(orgUnit.getResource());
                    }
                    break;
                case FILTERED_RECONCILIATION:
                    ReconFilterBuilder filterBuilder = ImplementationManager.build(pullTask.getReconFilterBuilder());
                    connector.filteredReconciliation(orgUnit.getObjectClass(), filterBuilder, rhandler, options);
                    break;
                case FULL_RECONCILIATION:
                default:
                    connector.fullReconciliation(orgUnit.getObjectClass(), rhandler, options);
                    break;
            }
        } catch (Throwable t) {
            throw new JobExecutionException("While pulling from connector", t);
        }
    }
    // ...then provisions for any types
    ahandler = buildAnyObjectHandler();
    uhandler = buildUserHandler();
    ghandler = buildGroupHandler();
    for (Provision provision : pullTask.getResource().getProvisions()) {
        if (provision.getMapping() != null) {
            status.set("Pulling " + provision.getObjectClass().getObjectClassValue());
            SyncopePullResultHandler handler;
            switch(provision.getAnyType().getKind()) {
                case USER:
                    handler = uhandler;
                    break;
                case GROUP:
                    handler = ghandler;
                    break;
                case ANY_OBJECT:
                default:
                    handler = ahandler;
            }
            try {
                Set<MappingItem> linkingMappingItems = virSchemaDAO.findByProvision(provision).stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet());
                Iterator<MappingItem> mapItems = new IteratorChain<>(provision.getMapping().getItems().iterator(), linkingMappingItems.iterator());
                OperationOptions options = MappingUtils.buildOperationOptions(mapItems);
                switch(pullTask.getPullMode()) {
                    case INCREMENTAL:
                        if (!dryRun) {
                            latestSyncTokens.put(provision.getObjectClass(), provision.getSyncToken());
                        }
                        connector.sync(provision.getObjectClass(), provision.getSyncToken(), handler, options);
                        if (!dryRun) {
                            provision.setSyncToken(latestSyncTokens.get(provision.getObjectClass()));
                            resourceDAO.save(provision.getResource());
                        }
                        break;
                    case FILTERED_RECONCILIATION:
                        ReconFilterBuilder filterBuilder = ImplementationManager.build(pullTask.getReconFilterBuilder());
                        connector.filteredReconciliation(provision.getObjectClass(), filterBuilder, handler, options);
                        break;
                    case FULL_RECONCILIATION:
                    default:
                        connector.fullReconciliation(provision.getObjectClass(), handler, options);
                        break;
                }
            } catch (Throwable t) {
                throw new JobExecutionException("While pulling from connector", t);
            }
        }
    }
    try {
        setGroupOwners(ghandler);
    } catch (Exception e) {
        LOG.error("While setting group owners", e);
    }
    if (!profile.isDryRun()) {
        for (PullActions action : actions) {
            action.afterAll(profile);
        }
    }
    status.set("Pull done");
    String result = createReport(profile.getResults(), pullTask.getResource(), dryRun);
    LOG.debug("Pull result: {}", result);
    return result;
}
Also used : OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) ReconFilterBuilder(org.apache.syncope.core.provisioning.api.pushpull.ReconFilterBuilder) ProvisioningProfile(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) SyncopePullExecutor(org.apache.syncope.core.provisioning.api.pushpull.SyncopePullExecutor) UserPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.UserPullResultHandler) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) GroupPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.GroupPullResultHandler) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Map(java.util.Map) OperationOptions(org.identityconnectors.framework.common.objects.OperationOptions) OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) SyncopePullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.SyncopePullResultHandler) SyncToken(org.identityconnectors.framework.common.objects.SyncToken) Iterator(java.util.Iterator) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) ConflictResolutionAction(org.apache.syncope.common.lib.types.ConflictResolutionAction) Set(java.util.Set) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Name(org.identityconnectors.framework.common.objects.Name) ImplementationManager(org.apache.syncope.core.spring.ImplementationManager) JobExecutionException(org.quartz.JobExecutionException) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) Connector(org.apache.syncope.core.provisioning.api.Connector) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AnyObjectPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.AnyObjectPullResultHandler) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) RealmPullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.RealmPullResultHandler) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) SyncopePullResultHandler(org.apache.syncope.core.provisioning.api.pushpull.SyncopePullResultHandler) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) IteratorChain(org.apache.syncope.common.lib.collections.IteratorChain) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) JobExecutionException(org.quartz.JobExecutionException) ReconFilterBuilder(org.apache.syncope.core.provisioning.api.pushpull.ReconFilterBuilder)

Example 4 with Connector

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

the class ConnectorManager method createConnector.

@Override
public Connector createConnector(final ConnInstance connInstance) {
    Connector connector = new ConnectorFacadeProxy(connInstance);
    ApplicationContextProvider.getBeanFactory().autowireBean(connector);
    return connector;
}
Also used : Connector(org.apache.syncope.core.provisioning.api.Connector)

Example 5 with Connector

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

the class ConnectorManager method registerConnector.

@Override
public void registerConnector(final ExternalResource resource) {
    ConnInstance connInstance = buildConnInstanceOverride(connInstanceDataBinder.getConnInstanceTO(resource.getConnector()), resource.getConfOverride(), resource.isOverrideCapabilities() ? resource.getCapabilitiesOverride() : null);
    Connector connector = createConnector(connInstance);
    LOG.debug("Connector to be registered: {}", connector);
    String beanName = getBeanName(resource);
    if (ApplicationContextProvider.getBeanFactory().containsSingleton(beanName)) {
        unregisterConnector(beanName);
    }
    ApplicationContextProvider.getBeanFactory().registerSingleton(beanName, connector);
    LOG.debug("Successfully registered bean {}", beanName);
}
Also used : Connector(org.apache.syncope.core.provisioning.api.Connector) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance)

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