Search in sources :

Example 1 with AnyPatch

use of org.apache.syncope.common.lib.patch.AnyPatch 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 2 with AnyPatch

use of org.apache.syncope.common.lib.patch.AnyPatch in project syncope by apache.

the class AbstractPullResultHandler method deprovision.

protected List<ProvisioningReport> deprovision(final SyncDelta delta, final List<String> anyKeys, final Provision provision, final boolean unlink) throws JobExecutionException {
    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to deprovision {}", anyKeys);
    final List<ProvisioningReport> results = new ArrayList<>();
    for (String key : anyKeys) {
        LOG.debug("About to unassign resource {}", key);
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.DELETE);
        result.setAnyType(provision.getAnyType().getKey());
        result.setStatus(ProvisioningReport.Status.SUCCESS);
        result.setKey(key);
        AnyTO before = getAnyTO(key);
        if (before == null) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(String.format("Any '%s(%s)' not found", provision.getAnyType().getKey(), key));
        }
        if (!profile.isDryRun()) {
            Object output;
            Result resultStatus;
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                result.setName(getName(before));
                try {
                    if (unlink) {
                        for (PullActions action : profile.getActions()) {
                            action.beforeUnassign(profile, delta, before);
                        }
                    } else {
                        for (PullActions action : profile.getActions()) {
                            action.beforeDeprovision(profile, delta, before);
                        }
                    }
                    PropagationByResource propByRes = new PropagationByResource();
                    propByRes.add(ResourceOperation.DELETE, profile.getTask().getResource().getKey());
                    taskExecutor.execute(propagationManager.getDeleteTasks(provision.getAnyType().getKind(), key, propByRes, null), false);
                    AnyPatch anyPatch = null;
                    if (unlink) {
                        anyPatch = newPatch(key);
                        anyPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(profile.getTask().getResource().getKey()).build());
                    }
                    if (anyPatch == null) {
                        output = getAnyTO(key);
                    } else {
                        output = doUpdate(before, anyPatch, delta, result);
                    }
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, AnyTO.class.cast(output), result);
                    }
                    resultStatus = Result.SUCCESS;
                    LOG.debug("{} {} successfully updated", provision.getAnyType().getKey(), key);
                } catch (PropagationException e) {
                    // A propagation failure doesn't imply a pull failure.
                    // The propagation exception status will be reported into the propagation task execution.
                    LOG.error("Could not propagate {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);
                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not update {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                }
            }
            finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), resultStatus, before, output, delta);
        }
        results.add(result);
    }
    return results;
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch)

Example 3 with AnyPatch

use of org.apache.syncope.common.lib.patch.AnyPatch in project syncope by apache.

the class AbstractPushResultHandler method unassign.

protected void unassign(final Any<?> any, final ProvisioningReport result) {
    AnyPatch patch = newPatch(any.getKey());
    patch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(profile.getTask().getResource().getKey()).build());
    update(patch);
    deprovision(any, result);
}
Also used : AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder)

Example 4 with AnyPatch

use of org.apache.syncope.common.lib.patch.AnyPatch in project syncope by apache.

the class AbstractPushResultHandler method link.

protected void link(final Any<?> any, final boolean unlink, final ProvisioningReport result) {
    AnyPatch patch = newPatch(any.getKey());
    patch.getResources().add(new StringPatchItem.Builder().operation(unlink ? PatchOperation.DELETE : PatchOperation.ADD_REPLACE).value(profile.getTask().getResource().getKey()).build());
    update(patch);
    result.setStatus(ProvisioningReport.Status.SUCCESS);
}
Also used : AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder)

Example 5 with AnyPatch

use of org.apache.syncope.common.lib.patch.AnyPatch in project syncope by apache.

the class AbstractPushResultHandler method assign.

protected void assign(final Any<?> any, final Boolean enabled, final ProvisioningReport result) {
    AnyPatch patch = newPatch(any.getKey());
    patch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(profile.getTask().getResource().getKey()).build());
    update(patch);
    provision(any, enabled, result);
}
Also used : AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) AttributeBuilder(org.identityconnectors.framework.common.objects.AttributeBuilder)

Aggregations

AnyPatch (org.apache.syncope.common.lib.patch.AnyPatch)8 ArrayList (java.util.ArrayList)4 AnyTO (org.apache.syncope.common.lib.to.AnyTO)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)4 Result (org.apache.syncope.common.lib.types.AuditElements.Result)3 AttributeBuilder (org.identityconnectors.framework.common.objects.AttributeBuilder)3 List (java.util.List)2 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)2 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)2 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)2 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)2 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)2 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)2 JobExecutionException (org.quartz.JobExecutionException)2 ParseException (java.text.ParseException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1