Search in sources :

Example 16 with WorkflowResult

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

the class DefaultUserProvisioningManager method internalSuspend.

@Override
public void internalSuspend(final String key) {
    Pair<WorkflowResult<String>, Boolean> updated = uwfAdapter.internalSuspend(key);
    // propagate suspension if and only if it is required by policy
    if (updated != null && updated.getRight()) {
        UserPatch userPatch = new UserPatch();
        userPatch.setKey(updated.getLeft().getResult());
        List<PropagationTaskTO> tasks = propagationManager.getUserUpdateTasks(new WorkflowResult<>(Pair.of(userPatch, Boolean.FALSE), updated.getLeft().getPropByRes(), updated.getLeft().getPerformedTasks()));
        taskExecutor.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)

Example 17 with WorkflowResult

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

the class DefaultUserProvisioningManager method update.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public Pair<UserPatch, List<PropagationStatus>> update(final UserPatch userPatch, final ProvisioningReport result, final Boolean enabled, final Set<String> excludedResources, final boolean nullPriorityAsync) {
    WorkflowResult<Pair<UserPatch, Boolean>> updated;
    try {
        updated = uwfAdapter.update(userPatch);
    } catch (Exception e) {
        LOG.error("Update of user {} failed, trying to pull its status anyway (if configured)", userPatch.getKey(), e);
        result.setStatus(ProvisioningReport.Status.FAILURE);
        result.setMessage("Update failed, trying to pull status anyway (if configured)\n" + e.getMessage());
        updated = new WorkflowResult<>(Pair.of(userPatch, false), new PropagationByResource(), new HashSet<>());
    }
    if (enabled != null) {
        User user = userDAO.find(userPatch.getKey());
        WorkflowResult<String> enableUpdate = null;
        if (user.isSuspended() == null) {
            enableUpdate = uwfAdapter.activate(userPatch.getKey(), null);
        } else if (enabled && user.isSuspended()) {
            enableUpdate = uwfAdapter.reactivate(userPatch.getKey());
        } else if (!enabled && !user.isSuspended()) {
            enableUpdate = uwfAdapter.suspend(userPatch.getKey());
        }
        if (enableUpdate != null) {
            if (enableUpdate.getPropByRes() != null) {
                updated.getPropByRes().merge(enableUpdate.getPropByRes());
                updated.getPropByRes().purge();
            }
            updated.getPerformedTasks().addAll(enableUpdate.getPerformedTasks());
        }
    }
    List<PropagationTaskTO> tasks = propagationManager.getUserUpdateTasks(updated, updated.getResult().getLeft().getPassword() != null, excludedResources);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
    return Pair.of(updated.getResult().getLeft(), propagationReporter.getStatuses());
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) User(org.apache.syncope.core.persistence.api.entity.user.User) 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) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with WorkflowResult

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

the class DefaultUserProvisioningManager method provision.

@Override
public List<PropagationStatus> provision(final String key, final boolean changePwd, final String password, final Collection<String> resources, final boolean nullPriorityAsync) {
    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.toSet()));
    if (changePwd) {
        PasswordPatch passwordPatch = new PasswordPatch();
        passwordPatch.setOnSyncope(false);
        passwordPatch.getResources().addAll(resources);
        passwordPatch.setValue(password);
        userPatch.setPassword(passwordPatch);
    }
    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 = propagationManager.getUserUpdateTasks(wfResult, changePwd, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
    return 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) 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) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 19 with WorkflowResult

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

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

the class CamelUserProvisioningManager method suspend.

@Override
@SuppressWarnings("unchecked")
public Pair<String, List<PropagationStatus>> suspend(final StatusPatch statusPatch, final boolean nullPriorityAsync) {
    PollingConsumer pollingConsumer = getConsumer("direct:statusPort");
    Map<String, Object> props = new HashMap<>();
    props.put("key", statusPatch.getKey());
    props.put("statusPatch", statusPatch);
    props.put("nullPriorityAsync", nullPriorityAsync);
    if (statusPatch.isOnSyncope()) {
        sendMessage("direct:suspendUser", statusPatch.getKey(), props);
    } else {
        WorkflowResult<String> updated = new WorkflowResult<>(statusPatch.getKey(), null, statusPatch.getType().name().toLowerCase());
        sendMessage("direct:userStatusPropagation", updated, props);
    }
    Exchange exchange = pollingConsumer.receive();
    if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
        throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    }
    return exchange.getIn().getBody(Pair.class);
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) HashMap(java.util.HashMap)

Aggregations

WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)32 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)18 User (org.apache.syncope.core.persistence.api.entity.user.User)14 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)11 Pair (org.apache.commons.lang3.tuple.Pair)8 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)8 HashMap (java.util.HashMap)7 PropagationReporter (org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)6 Exchange (org.apache.camel.Exchange)4 PollingConsumer (org.apache.camel.PollingConsumer)4 List (java.util.List)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)3 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)3 AttrTO (org.apache.syncope.common.lib.to.AttrTO)3 AnyObjectPatch (org.apache.syncope.common.lib.patch.AnyObjectPatch)2 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)2 GroupTO (org.apache.syncope.common.lib.to.GroupTO)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 WorkflowException (org.apache.syncope.core.workflow.api.WorkflowException)2 FlowableException (org.flowable.engine.common.api.FlowableException)2