Search in sources :

Example 1 with PullActions

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

the class AbstractPullResultHandler method provision.

protected List<ProvisioningReport> provision(final SyncDelta delta, final Provision provision, final AnyUtils anyUtils) throws JobExecutionException {
    if (!profile.getTask().isPerformCreate()) {
        LOG.debug("PullTask not configured for create");
        finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    AnyTO anyTO = connObjectUtils.getAnyTO(delta.getObject(), profile.getTask(), provision, anyUtils);
    ProvisioningReport result = new ProvisioningReport();
    result.setOperation(ResourceOperation.CREATE);
    result.setAnyType(provision.getAnyType().getKey());
    result.setStatus(ProvisioningReport.Status.SUCCESS);
    result.setName(getName(anyTO));
    if (profile.isDryRun()) {
        result.setKey(null);
        finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta);
    } else {
        for (PullActions action : profile.getActions()) {
            action.beforeProvision(profile, delta, anyTO);
        }
        create(anyTO, delta, UnmatchingRule.toEventName(UnmatchingRule.PROVISION), provision, result);
    }
    return Collections.singletonList(result);
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)

Example 2 with PullActions

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

the class AbstractPullResultHandler method assign.

protected List<ProvisioningReport> assign(final SyncDelta delta, final Provision provision, final AnyUtils anyUtils) throws JobExecutionException {
    if (!profile.getTask().isPerformCreate()) {
        LOG.debug("PullTask not configured for create");
        finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    AnyTO anyTO = connObjectUtils.getAnyTO(delta.getObject(), profile.getTask(), provision, anyUtils);
    anyTO.getResources().add(profile.getTask().getResource().getKey());
    ProvisioningReport result = new ProvisioningReport();
    result.setOperation(ResourceOperation.CREATE);
    result.setAnyType(provision.getAnyType().getKey());
    result.setStatus(ProvisioningReport.Status.SUCCESS);
    result.setName(getName(anyTO));
    if (profile.isDryRun()) {
        result.setKey(null);
        finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta);
    } else {
        for (PullActions action : profile.getActions()) {
            action.beforeAssign(profile, delta, anyTO);
        }
        create(anyTO, delta, UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), provision, result);
    }
    return Collections.singletonList(result);
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)

Example 3 with PullActions

use of org.apache.syncope.core.provisioning.api.pushpull.PullActions 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 4 with PullActions

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

the class DefaultRealmPullResultHandler method assign.

private List<ProvisioningReport> assign(final SyncDelta delta, final OrgUnit orgUnit) throws JobExecutionException {
    if (!profile.getTask().isPerformCreate()) {
        LOG.debug("PullTask not configured for create");
        finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    RealmTO realmTO = connObjectUtils.getRealmTO(delta.getObject(), profile.getTask(), orgUnit);
    if (realmTO.getFullPath() == null) {
        if (realmTO.getParent() == null) {
            realmTO.setParent(profile.getTask().getDestinatioRealm().getFullPath());
        }
        realmTO.setFullPath(realmTO.getParent() + "/" + realmTO.getName());
    }
    realmTO.getResources().add(profile.getTask().getResource().getKey());
    ProvisioningReport result = new ProvisioningReport();
    result.setOperation(ResourceOperation.CREATE);
    result.setAnyType(REALM_TYPE);
    result.setStatus(ProvisioningReport.Status.SUCCESS);
    result.setName(realmTO.getFullPath());
    if (profile.isDryRun()) {
        result.setKey(null);
        finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta);
    } else {
        for (PullActions action : profile.getActions()) {
            action.beforeAssign(profile, delta, realmTO);
        }
        create(realmTO, delta, UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), result);
    }
    return Collections.singletonList(result);
}
Also used : PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) RealmTO(org.apache.syncope.common.lib.to.RealmTO) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)

Example 5 with PullActions

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

the class DefaultRealmPullResultHandler method link.

private List<ProvisioningReport> link(final SyncDelta delta, final List<String> keys, final boolean unlink) throws JobExecutionException {
    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to link {}", keys);
    final List<ProvisioningReport> results = new ArrayList<>();
    for (String key : keys) {
        LOG.debug("About to unassign resource {}", key);
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.NONE);
        result.setAnyType(REALM_TYPE);
        result.setStatus(ProvisioningReport.Status.SUCCESS);
        result.setKey(key);
        Realm realm = realmDAO.find(key);
        RealmTO before = binder.getRealmTO(realm, true);
        if (before == null) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(String.format("Realm '%s' not found", key));
        } else {
            result.setName(before.getFullPath());
        }
        Object output;
        Result resultStatus;
        if (!profile.isDryRun()) {
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                try {
                    if (unlink) {
                        for (PullActions action : profile.getActions()) {
                            action.beforeUnlink(profile, delta, before);
                        }
                    } else {
                        for (PullActions action : profile.getActions()) {
                            action.beforeLink(profile, delta, before);
                        }
                    }
                    if (unlink) {
                        realm.getResources().remove(profile.getTask().getResource());
                    } else {
                        realm.add(profile.getTask().getResource());
                    }
                    output = update(delta, Collections.singletonList(key));
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, RealmTO.class.cast(output), result);
                    }
                    resultStatus = Result.SUCCESS;
                    LOG.debug("{} successfully updated", realm);
                } 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 Realm {}", 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 Realm {}", delta.getUid().getUidValue(), e);
                    output = e;
                    resultStatus = Result.FAILURE;
                }
            }
            finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before, output, delta);
        }
        results.add(result);
    }
    return results;
}
Also used : PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) RealmTO(org.apache.syncope.common.lib.to.RealmTO) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) Realm(org.apache.syncope.core.persistence.api.entity.Realm) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) 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) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Aggregations

PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)19 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)12 JobExecutionException (org.quartz.JobExecutionException)11 Result (org.apache.syncope.common.lib.types.AuditElements.Result)10 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)10 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)10 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)10 ArrayList (java.util.ArrayList)9 AnyTO (org.apache.syncope.common.lib.to.AnyTO)7 RealmTO (org.apache.syncope.common.lib.to.RealmTO)7 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)6 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)5 Realm (org.apache.syncope.core.persistence.api.entity.Realm)5 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)5 Date (java.util.Date)3 AnyPatch (org.apache.syncope.common.lib.patch.AnyPatch)3 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)3 Remediation (org.apache.syncope.core.persistence.api.entity.Remediation)3 PullTask (org.apache.syncope.core.persistence.api.entity.task.PullTask)3 Implementation (org.apache.syncope.core.persistence.api.entity.Implementation)2