Search in sources :

Example 6 with PropagationTaskTO

use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.

the class DeleteProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    String key = exchange.getIn().getBody(String.class);
    Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
    Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
    if (null != getAnyTypeKind()) {
        List<PropagationTaskTO> tasks;
        PropagationReporter propagationReporter;
        switch(getAnyTypeKind()) {
            case USER:
                PropagationByResource propByRes = new PropagationByResource();
                propByRes.set(ResourceOperation.DELETE, userDAO.findAllResourceKeys(key));
                // Note here that we can only notify about "delete", not any other
                // task defined in workflow process definition: this because this
                // information could only be available after uwfAdapter.delete(), which
                // will also effectively remove user from db, thus making virtually
                // impossible by NotificationManager to fetch required user information
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.USER, key, propByRes, excludedResources);
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.setProperty("statuses", propagationReporter.getStatuses());
                break;
            case GROUP:
                tasks = new ArrayList<>();
                // resources only because of the reason being deleted (see SYNCOPE-357)
                for (Map.Entry<String, PropagationByResource> entry : groupDataBinder.findUsersWithTransitiveResources(key).entrySet()) {
                    tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.USER, entry.getKey(), entry.getValue(), excludedResources));
                }
                for (Map.Entry<String, PropagationByResource> entry : groupDataBinder.findAnyObjectsWithTransitiveResources(key).entrySet()) {
                    tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, entry.getKey(), entry.getValue(), excludedResources));
                }
                // Generate propagation tasks for deleting this group from resources
                tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.GROUP, key, null, null));
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.setProperty("statuses", propagationReporter.getStatuses());
                break;
            case ANY_OBJECT:
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, key, null, excludedResources);
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.setProperty("statuses", propagationReporter.getStatuses());
                break;
            default:
                break;
        }
    }
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Map(java.util.Map)

Example 7 with PropagationTaskTO

use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.

the class DeprovisionProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    String key = exchange.getIn().getBody(String.class);
    List<String> resources = exchange.getProperty("resources", List.class);
    Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
    if (null != getAnyTypeKind()) {
        PropagationByResource propByRes = new PropagationByResource();
        List<PropagationTaskTO> tasks;
        PropagationReporter propagationReporter;
        switch(getAnyTypeKind()) {
            case USER:
                propByRes.set(ResourceOperation.DELETE, resources);
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.USER, key, propByRes, userDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(propagationReporter.getStatuses());
                break;
            case GROUP:
                propByRes.addAll(ResourceOperation.DELETE, resources);
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.GROUP, key, propByRes, groupDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(propagationReporter.getStatuses());
                break;
            case ANY_OBJECT:
                propByRes.addAll(ResourceOperation.DELETE, resources);
                tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, key, propByRes, anyObjectDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
                propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(propagationReporter.getStatuses());
                break;
            default:
                break;
        }
    }
}
Also used : AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) List(java.util.List) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Exchange(org.apache.camel.Exchange) Endpoint(org.apache.camel.Endpoint) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) Collectors(java.util.stream.Collectors) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)

Example 8 with PropagationTaskTO

use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.

the class UpdateProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
        Object actual = exchange.getProperty("actual");
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
        if (actual instanceof UserPatch || isPull()) {
            WorkflowResult<Pair<UserPatch, Boolean>> updated = (WorkflowResult<Pair<UserPatch, Boolean>>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks;
            if (isPull()) {
                boolean passwordNotNull = updated.getResult().getKey().getPassword() != null;
                tasks = getPropagationManager().getUserUpdateTasks(updated, passwordNotNull, excludedResources);
            } else {
                tasks = getPropagationManager().getUserUpdateTasks(updated);
            }
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(updated.getResult().getLeft(), propagationReporter.getStatuses()));
        } else if (actual instanceof AnyPatch) {
            WorkflowResult<? extends AnyPatch> updated = (WorkflowResult<? extends AnyPatch>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(actual instanceof AnyObjectPatch ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, updated.getResult().getKey(), false, null, updated.getPropByRes(), ((AnyPatch) actual).getVirAttrs(), excludedResources);
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
        }
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) List(java.util.List) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) Pair(org.apache.commons.lang3.tuple.Pair)

Example 9 with PropagationTaskTO

use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.

the class DefaultPropagationReporter method onPriorityResourceFailure.

@Override
public void onPriorityResourceFailure(final String failingResource, final Collection<PropagationTaskTO> tasks) {
    LOG.debug("Propagation error: {} priority resource failed to propagate", failingResource);
    Optional<PropagationTaskTO> propagationTask = tasks.stream().filter(task -> task.getResource().equals(failingResource)).findFirst();
    if (propagationTask.isPresent()) {
        PropagationStatus status = new PropagationStatus();
        status.setResource(propagationTask.get().getResource());
        status.setStatus(PropagationTaskExecStatus.FAILURE);
        status.setFailureReason("Propagation error: " + failingResource + " priority resource failed to propagate.");
        add(status);
    } else {
        LOG.error("Could not find {} for {}", PropagationTask.class.getName(), failingResource);
    }
}
Also used : Logger(org.slf4j.Logger) PropagationTaskExecStatus(org.apache.syncope.common.lib.types.PropagationTaskExecStatus) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) ArrayList(java.util.ArrayList) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) List(java.util.List) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ConnObjectUtils(org.apache.syncope.core.provisioning.java.utils.ConnObjectUtils) Optional(java.util.Optional) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) Collections(java.util.Collections) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus)

Example 10 with PropagationTaskTO

use of org.apache.syncope.common.lib.to.PropagationTaskTO 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)

Aggregations

PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)48 PropagationReporter (org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)29 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)21 Transactional (org.springframework.transaction.annotation.Transactional)11 Pair (org.apache.commons.lang3.tuple.Pair)10 ArrayList (java.util.ArrayList)9 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)9 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)9 List (java.util.List)8 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)8 Map (java.util.Map)7 Test (org.junit.jupiter.api.Test)7 RealmTO (org.apache.syncope.common.lib.to.RealmTO)6 Realm (org.apache.syncope.core.persistence.api.entity.Realm)6 HashSet (java.util.HashSet)5 Collectors (java.util.stream.Collectors)5 UserTO (org.apache.syncope.common.lib.to.UserTO)5 TaskQuery (org.apache.syncope.common.rest.api.beans.TaskQuery)5 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)5