Search in sources :

Example 11 with AnyTO

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

the class AbstractPullResultHandler method create.

protected void create(final AnyTO anyTO, final SyncDelta delta, final String operation, final Provision provision, final ProvisioningReport result) throws JobExecutionException {
    Object output;
    Result resultStatus;
    try {
        AnyTO created = doCreate(anyTO, delta);
        output = created;
        result.setKey(created.getKey());
        result.setName(getName(created));
        resultStatus = Result.SUCCESS;
        for (PullActions action : profile.getActions()) {
            action.after(profile, delta, created, result);
        }
        LOG.debug("{} {} successfully created", created.getType(), created.getKey());
    } 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 {} {}", anyTO.getType(), 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 create {} {} ", anyTO.getType(), delta.getUid().getUidValue(), e);
        output = e;
        resultStatus = Result.FAILURE;
        if (profile.getTask().isRemediation()) {
            Remediation entity = entityFactory.newEntity(Remediation.class);
            entity.setAnyType(provision.getAnyType());
            entity.setOperation(ResourceOperation.CREATE);
            entity.setPayload(anyTO);
            entity.setError(result.getMessage());
            entity.setInstant(new Date());
            entity.setRemoteName(delta.getObject().getName().getNameValue());
            entity.setPullTask(profile.getTask());
            remediationDAO.save(entity);
        }
    }
    finalize(operation, resultStatus, null, output, delta);
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation) 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) Date(java.util.Date) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Example 12 with AnyTO

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

the class AbstractPullResultHandler method update.

protected List<ProvisioningReport> update(final SyncDelta delta, final List<String> anyKeys, final Provision provision) throws JobExecutionException {
    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(MatchingRule.toEventName(MatchingRule.UPDATE), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to update {}", anyKeys);
    List<ProvisioningReport> results = new ArrayList<>();
    for (String key : anyKeys) {
        LOG.debug("About to update {}", key);
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.UPDATE);
        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));
        } else {
            result.setName(getName(before));
        }
        if (!profile.isDryRun()) {
            Result resultStatus;
            Object output;
            AnyPatch effectivePatch = null;
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                AnyPatch anyPatch = null;
                try {
                    anyPatch = connObjectUtils.getAnyPatch(before.getKey(), delta.getObject(), before, profile.getTask(), provision, getAnyUtils());
                    for (PullActions action : profile.getActions()) {
                        action.beforeUpdate(profile, delta, before, anyPatch);
                    }
                    effectivePatch = doUpdate(before, anyPatch, delta, result);
                    AnyTO updated = AnyOperations.patch(before, effectivePatch);
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, updated, result);
                    }
                    output = updated;
                    resultStatus = Result.SUCCESS;
                    result.setName(getName(updated));
                    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;
                    if (profile.getTask().isRemediation()) {
                        Remediation entity = entityFactory.newEntity(Remediation.class);
                        entity.setAnyType(provision.getAnyType());
                        entity.setOperation(ResourceOperation.UPDATE);
                        entity.setPayload(anyPatch);
                        entity.setError(result.getMessage());
                        entity.setInstant(new Date());
                        entity.setRemoteName(delta.getObject().getName().getNameValue());
                        entity.setPullTask(profile.getTask());
                        remediationDAO.save(entity);
                    }
                }
            }
            finalize(MatchingRule.toEventName(MatchingRule.UPDATE), resultStatus, before, output, delta, effectivePatch);
        }
        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) 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) Date(java.util.Date) 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) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation)

Example 13 with AnyTO

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

the class AbstractPullResultHandler method delete.

protected List<ProvisioningReport> delete(final SyncDelta delta, final List<String> anyKeys, final Provision provision) throws JobExecutionException {
    if (!profile.getTask().isPerformDelete()) {
        LOG.debug("PullTask not configured for delete");
        finalize(ResourceOperation.DELETE.name().toLowerCase(), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to delete {}", anyKeys);
    List<ProvisioningReport> results = new ArrayList<>();
    for (String key : anyKeys) {
        Object output;
        Result resultStatus = Result.FAILURE;
        ProvisioningReport result = new ProvisioningReport();
        try {
            AnyTO before = getAnyTO(key);
            result.setKey(key);
            result.setName(getName(before));
            result.setOperation(ResourceOperation.DELETE);
            result.setAnyType(provision.getAnyType().getKey());
            result.setStatus(ProvisioningReport.Status.SUCCESS);
            if (!profile.isDryRun()) {
                for (PullActions action : profile.getActions()) {
                    action.beforeDelete(profile, delta, before);
                }
                try {
                    doDelete(provision.getAnyType().getKind(), key);
                    output = null;
                    resultStatus = Result.SUCCESS;
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, before, result);
                    }
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);
                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not delete {} {}", provision.getAnyType().getKey(), key, e);
                    output = e;
                    if (profile.getTask().isRemediation()) {
                        Remediation entity = entityFactory.newEntity(Remediation.class);
                        entity.setAnyType(provision.getAnyType());
                        entity.setOperation(ResourceOperation.DELETE);
                        entity.setPayload(key);
                        entity.setError(result.getMessage());
                        entity.setInstant(new Date());
                        entity.setRemoteName(delta.getObject().getName().getNameValue());
                        entity.setPullTask(profile.getTask());
                        remediationDAO.save(entity);
                    }
                }
                finalize(ResourceOperation.DELETE.name().toLowerCase(), resultStatus, before, output, delta);
            }
            results.add(result);
        } catch (NotFoundException e) {
            LOG.error("Could not find {} {}", provision.getAnyType().getKey(), key, e);
        } catch (DelegatedAdministrationException e) {
            LOG.error("Not allowed to read {} {}", provision.getAnyType().getKey(), key, e);
        } catch (Exception e) {
            LOG.error("Could not delete {} {}", provision.getAnyType().getKey(), key, e);
        }
    }
    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) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) 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) Date(java.util.Date) Result(org.apache.syncope.common.lib.types.AuditElements.Result) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation)

Example 14 with AnyTO

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

the class JEXLItemTransformerImpl method beforePull.

@Override
public List<Object> beforePull(final Item item, final EntityTO entityTO, final List<Object> values) {
    if (StringUtils.isNotBlank(pullJEXL) && values != null) {
        List<Object> newValues = new ArrayList<>(values.size());
        values.forEach(value -> {
            JexlContext jexlContext = new MapContext();
            jexlContext.set("value", value);
            if (entityTO instanceof AnyTO) {
                JexlUtils.addFieldsToContext((AnyTO) entityTO, jexlContext);
                JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getPlainAttrs(), jexlContext);
                JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getDerAttrs(), jexlContext);
                JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getVirAttrs(), jexlContext);
            } else if (entityTO instanceof RealmTO) {
                JexlUtils.addFieldsToContext((RealmTO) entityTO, jexlContext);
                newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext));
            }
            newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext));
        });
        return newValues;
    }
    return JEXLItemTransformer.super.beforePull(item, entityTO, values);
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) ArrayList(java.util.ArrayList) JexlContext(org.apache.commons.jexl3.JexlContext) RealmTO(org.apache.syncope.common.lib.to.RealmTO) MapContext(org.apache.commons.jexl3.MapContext)

Example 15 with AnyTO

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

the class DefaultUserPushResultHandler method provision.

@Override
protected void provision(final Any<?> any, final Boolean enabled, final ProvisioningReport result) {
    AnyTO before = getAnyTO(any.getKey());
    List<String> noPropResources = new ArrayList<>(before.getResources());
    noPropResources.remove(profile.getTask().getResource().getKey());
    PropagationByResource propByRes = new PropagationByResource();
    propByRes.add(ResourceOperation.CREATE, profile.getTask().getResource().getKey());
    PropagationReporter reporter = taskExecutor.execute(propagationManager.getUserCreateTasks(before.getKey(), null, enabled, propByRes, before.getVirAttrs(), noPropResources), false);
    reportPropagation(result, reporter);
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) ArrayList(java.util.ArrayList) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter)

Aggregations

AnyTO (org.apache.syncope.common.lib.to.AnyTO)20 ArrayList (java.util.ArrayList)11 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)7 GroupTO (org.apache.syncope.common.lib.to.GroupTO)6 UserTO (org.apache.syncope.common.lib.to.UserTO)6 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)6 AnyPatch (org.apache.syncope.common.lib.patch.AnyPatch)5 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)5 AttrTO (org.apache.syncope.common.lib.to.AttrTO)5 Result (org.apache.syncope.common.lib.types.AuditElements.Result)5 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)5 Date (java.util.Date)4 List (java.util.List)4 Optional (java.util.Optional)4 StringUtils (org.apache.commons.lang3.StringUtils)4 RealmTO (org.apache.syncope.common.lib.to.RealmTO)4 Realm (org.apache.syncope.core.persistence.api.entity.Realm)4 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)4 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)4 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)4