Search in sources :

Example 31 with PropagationTaskTO

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

the class SuspendProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if (getAnyTypeKind() == AnyTypeKind.USER) {
        Pair<WorkflowResult<String>, Boolean> updated = (Pair<WorkflowResult<String>, Boolean>) exchange.getIn().getBody();
        // propagate suspension if and only if it is required by policy
        if (updated != null && updated.getValue()) {
            UserPatch userPatch = new UserPatch();
            userPatch.setKey(updated.getKey().getResult());
            List<PropagationTaskTO> tasks = getPropagationManager().getUserUpdateTasks(new WorkflowResult<>(Pair.of(userPatch, Boolean.FALSE), updated.getKey().getPropByRes(), updated.getKey().getPerformedTasks()));
            getPropagationTaskExecutor().execute(tasks, false);
        }
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Pair(org.apache.commons.lang3.tuple.Pair)

Example 32 with PropagationTaskTO

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

the class ProvisionProducer 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 (getAnyTypeKind() == AnyTypeKind.USER) {
        Boolean changePwd = exchange.getProperty("changePwd", Boolean.class);
        String password = exchange.getProperty("password", String.class);
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(key);
        userPatch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build()).collect(Collectors.toList()));
        if (changePwd) {
            userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).value(password).resources(resources).build());
        }
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, resources);
        WorkflowResult<Pair<UserPatch, Boolean>> wfResult = new WorkflowResult<>(ImmutablePair.of(userPatch, (Boolean) null), propByRes, "update");
        List<PropagationTaskTO> tasks = getPropagationManager().getUserUpdateTasks(wfResult, changePwd, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(propagationReporter.getStatuses());
    } else {
        PropagationByResource propByRes = new PropagationByResource();
        propByRes.addAll(ResourceOperation.UPDATE, resources);
        AnyTypeKind anyTypeKind = AnyTypeKind.GROUP;
        if (getAnyTypeKind() != null) {
            anyTypeKind = getAnyTypeKind();
        }
        List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(anyTypeKind, key, false, null, propByRes, null, null);
        PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
        exchange.getOut().setBody(propagationReporter.getStatuses());
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Example 33 with PropagationTaskTO

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

the class PropagationManagerImpl method getUserUpdateTasks.

@Override
public List<PropagationTaskTO> getUserUpdateTasks(final WorkflowResult<Pair<UserPatch, Boolean>> wfResult) {
    UserPatch userPatch = wfResult.getResult().getKey();
    // Propagate password update only to requested resources
    List<PropagationTaskTO> tasks = new ArrayList<>();
    if (userPatch.getPassword() == null) {
        // a. no specific password propagation request: generate propagation tasks for any resource associated
        tasks = getUserUpdateTasks(wfResult, false, null);
    } else {
        // b. generate the propagation task list in two phases: first the ones containing password,
        // the the rest (with no password)
        WorkflowResult<Pair<UserPatch, Boolean>> pwdWFResult = new WorkflowResult<>(wfResult.getResult(), new PropagationByResource(), wfResult.getPerformedTasks());
        Set<String> pwdResourceNames = new HashSet<>(userPatch.getPassword().getResources());
        Collection<String> allResourceNames = userDAO.findAllResourceKeys(userPatch.getKey());
        pwdResourceNames.retainAll(allResourceNames);
        pwdWFResult.getPropByRes().addAll(ResourceOperation.UPDATE, pwdResourceNames);
        if (!pwdWFResult.getPropByRes().isEmpty()) {
            Set<String> toBeExcluded = new HashSet<>(allResourceNames);
            toBeExcluded.addAll(userPatch.getResources().stream().map(patchItem -> patchItem.getValue()).collect(Collectors.toList()));
            toBeExcluded.removeAll(pwdResourceNames);
            tasks.addAll(getUserUpdateTasks(pwdWFResult, true, toBeExcluded));
        }
        WorkflowResult<Pair<UserPatch, Boolean>> noPwdWFResult = new WorkflowResult<>(wfResult.getResult(), new PropagationByResource(), wfResult.getPerformedTasks());
        noPwdWFResult.getPropByRes().merge(wfResult.getPropByRes());
        noPwdWFResult.getPropByRes().removeAll(pwdResourceNames);
        noPwdWFResult.getPropByRes().purge();
        if (!noPwdWFResult.getPropByRes().isEmpty()) {
            tasks.addAll(getUserUpdateTasks(noPwdWFResult, false, pwdResourceNames));
        }
    }
    return tasks;
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ArrayList(java.util.ArrayList) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Pair(org.apache.commons.lang3.tuple.Pair) HashSet(java.util.HashSet)

Example 34 with PropagationTaskTO

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

the class DefaultAnyObjectProvisioningManager method update.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public Pair<AnyObjectPatch, List<PropagationStatus>> update(final AnyObjectPatch anyObjectPatch, final Set<String> excludedResources, final boolean nullPriorityAsync) {
    WorkflowResult<AnyObjectPatch> updated = awfAdapter.update(anyObjectPatch);
    List<PropagationTaskTO> tasks = propagationManager.getUpdateTasks(AnyTypeKind.ANY_OBJECT, updated.getResult().getKey(), false, null, updated.getPropByRes(), anyObjectPatch.getVirAttrs(), excludedResources);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
    return Pair.of(updated.getResult(), propagationReporter.getStatuses());
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with PropagationTaskTO

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

the class DefaultAnyObjectProvisioningManager method delete.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public List<PropagationStatus> delete(final String key, final Set<String> excludedResources, final boolean nullPriorityAsync) {
    PropagationByResource propByRes = new PropagationByResource();
    propByRes.set(ResourceOperation.DELETE, anyObjectDAO.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 awfAdapter.delete(), which
    // will also effectively remove user from db, thus making virtually
    // impossible by NotificationManager to fetch required user information
    List<PropagationTaskTO> tasks = propagationManager.getDeleteTasks(AnyTypeKind.ANY_OBJECT, key, propByRes, excludedResources);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
    try {
        awfAdapter.delete(key);
    } catch (PropagationException e) {
        throw e;
    }
    return propagationReporter.getStatuses();
}
Also used : PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) 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) Transactional(org.springframework.transaction.annotation.Transactional)

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