Search in sources :

Example 1 with Result

use of org.apache.syncope.common.lib.types.AuditElements.Result in project syncope by apache.

the class AuditLoggerName method parseEventCategory.

public static Pair<EventCategoryTO, Result> parseEventCategory(final String event) {
    EventCategoryTO eventCategoryTO = new EventCategoryTO();
    Result condition = null;
    if (StringUtils.isNotEmpty(event)) {
        final String[] elements = event.substring(1, event.length() - 1).split("\\]:\\[");
        if (elements.length == 1) {
            eventCategoryTO.setType(EventCategoryType.CUSTOM);
            condition = Result.SUCCESS;
            eventCategoryTO.getEvents().add(event);
        } else {
            EventCategoryType type;
            if (EventCategoryType.PROPAGATION.toString().equals(elements[0])) {
                type = EventCategoryType.PROPAGATION;
            } else if (EventCategoryType.PULL.toString().equals(elements[0])) {
                type = EventCategoryType.PULL;
            } else if (EventCategoryType.PUSH.toString().equals(elements[0])) {
                type = EventCategoryType.PUSH;
            } else {
                try {
                    type = EventCategoryType.valueOf(elements[0]);
                } catch (Exception e) {
                    type = EventCategoryType.CUSTOM;
                }
            }
            eventCategoryTO.setType(type);
            eventCategoryTO.setCategory(StringUtils.isNotEmpty(elements[1]) ? elements[1] : null);
            eventCategoryTO.setSubcategory(StringUtils.isNotEmpty(elements[2]) ? elements[2] : null);
            if (elements.length > 3 && StringUtils.isNotEmpty(elements[3])) {
                eventCategoryTO.getEvents().add(elements[3]);
            }
            if (elements.length > 4) {
                condition = Result.valueOf(elements[4].toUpperCase());
            }
        }
    }
    return Pair.of(eventCategoryTO, condition);
}
Also used : EventCategoryType(org.apache.syncope.common.lib.types.AuditElements.EventCategoryType) EventCategoryTO(org.apache.syncope.common.lib.log.EventCategoryTO) ParseException(java.text.ParseException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Example 2 with Result

use of org.apache.syncope.common.lib.types.AuditElements.Result 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 Result

use of org.apache.syncope.common.lib.types.AuditElements.Result in project syncope by apache.

the class AbstractPushResultHandler method doHandle.

protected void doHandle(final Any<?> any) throws JobExecutionException {
    AnyUtils anyUtils = anyUtilsFactory.getInstance(any);
    ProvisioningReport result = new ProvisioningReport();
    profile.getResults().add(result);
    result.setKey(any.getKey());
    result.setAnyType(any.getType().getKey());
    result.setName(getName(any));
    Boolean enabled = any instanceof User && profile.getTask().isSyncStatus() ? ((User) any).isSuspended() ? Boolean.FALSE : Boolean.TRUE : null;
    LOG.debug("Propagating {} with key {} towards {}", anyUtils.getAnyTypeKind(), any.getKey(), profile.getTask().getResource());
    Object output = null;
    Result resultStatus = null;
    // Try to read remote object BEFORE any actual operation
    Optional<? extends Provision> provision = profile.getTask().getResource().getProvision(any.getType());
    Optional<MappingItem> connObjectKey = MappingUtils.getConnObjectKeyItem(provision.get());
    Optional<String> connObjecKeyValue = mappingManager.getConnObjectKeyValue(any, provision.get());
    ConnectorObject beforeObj = null;
    if (connObjectKey.isPresent() && connObjecKeyValue.isPresent()) {
        beforeObj = getRemoteObject(provision.get().getObjectClass(), connObjectKey.get().getExtAttrName(), connObjecKeyValue.get(), provision.get().getMapping().getItems().iterator());
    } else {
        LOG.debug("ConnObjectKeyItem {} or its value {} are null", connObjectKey, connObjecKeyValue);
    }
    Boolean status = profile.getTask().isSyncStatus() ? enabled : null;
    if (profile.isDryRun()) {
        if (beforeObj == null) {
            result.setOperation(toResourceOperation(profile.getTask().getUnmatchingRule()));
        } else {
            result.setOperation(toResourceOperation(profile.getTask().getMatchingRule()));
        }
        result.setStatus(ProvisioningReport.Status.SUCCESS);
    } else {
        String operation = beforeObj == null ? UnmatchingRule.toEventName(profile.getTask().getUnmatchingRule()) : MatchingRule.toEventName(profile.getTask().getMatchingRule());
        boolean notificationsAvailable = notificationManager.notificationsAvailable(AuditElements.EventCategoryType.PUSH, any.getType().getKind().name().toLowerCase(), profile.getTask().getResource().getKey(), operation);
        boolean auditRequested = auditManager.auditRequested(AuditElements.EventCategoryType.PUSH, any.getType().getKind().name().toLowerCase(), profile.getTask().getResource().getKey(), operation);
        try {
            if (beforeObj == null) {
                result.setOperation(toResourceOperation(profile.getTask().getUnmatchingRule()));
                switch(profile.getTask().getUnmatchingRule()) {
                    case ASSIGN:
                        for (PushActions action : profile.getActions()) {
                            action.beforeAssign(profile, any);
                        }
                        if (!profile.getTask().isPerformCreate()) {
                            LOG.debug("PushTask not configured for create");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            assign(any, status, result);
                        }
                        break;
                    case PROVISION:
                        for (PushActions action : profile.getActions()) {
                            action.beforeProvision(profile, any);
                        }
                        if (!profile.getTask().isPerformCreate()) {
                            LOG.debug("PushTask not configured for create");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            provision(any, status, result);
                        }
                        break;
                    case UNLINK:
                        for (PushActions action : profile.getActions()) {
                            action.beforeUnlink(profile, any);
                        }
                        if (!profile.getTask().isPerformUpdate()) {
                            LOG.debug("PushTask not configured for update");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            link(any, true, result);
                        }
                        break;
                    case IGNORE:
                        LOG.debug("Ignored any: {}", any);
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                        break;
                    default:
                }
            } else {
                result.setOperation(toResourceOperation(profile.getTask().getMatchingRule()));
                switch(profile.getTask().getMatchingRule()) {
                    case UPDATE:
                        for (PushActions action : profile.getActions()) {
                            action.beforeUpdate(profile, any);
                        }
                        if (!profile.getTask().isPerformUpdate()) {
                            LOG.debug("PushTask not configured for update");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            update(any, result);
                        }
                        break;
                    case DEPROVISION:
                        for (PushActions action : profile.getActions()) {
                            action.beforeDeprovision(profile, any);
                        }
                        if (!profile.getTask().isPerformDelete()) {
                            LOG.debug("PushTask not configured for delete");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            deprovision(any, result);
                        }
                        break;
                    case UNASSIGN:
                        for (PushActions action : profile.getActions()) {
                            action.beforeUnassign(profile, any);
                        }
                        if (!profile.getTask().isPerformDelete()) {
                            LOG.debug("PushTask not configured for delete");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            unassign(any, result);
                        }
                        break;
                    case LINK:
                        for (PushActions action : profile.getActions()) {
                            action.beforeLink(profile, any);
                        }
                        if (!profile.getTask().isPerformUpdate()) {
                            LOG.debug("PushTask not configured for update");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            link(any, false, result);
                        }
                        break;
                    case UNLINK:
                        for (PushActions action : profile.getActions()) {
                            action.beforeUnlink(profile, any);
                        }
                        if (!profile.getTask().isPerformUpdate()) {
                            LOG.debug("PushTask not configured for update");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            link(any, true, result);
                        }
                        break;
                    case IGNORE:
                        LOG.debug("Ignored any: {}", any);
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                        break;
                    default:
                }
            }
            for (PushActions action : profile.getActions()) {
                action.after(profile, any, result);
            }
            if (result.getStatus() == null) {
                result.setStatus(ProvisioningReport.Status.SUCCESS);
            }
            resultStatus = AuditElements.Result.SUCCESS;
            if (connObjectKey.isPresent() && connObjecKeyValue.isPresent()) {
                output = getRemoteObject(provision.get().getObjectClass(), connObjectKey.get().getExtAttrName(), connObjecKeyValue.get(), provision.get().getMapping().getItems().iterator());
            }
        } catch (IgnoreProvisionException e) {
            throw e;
        } catch (Exception e) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(ExceptionUtils.getRootCauseMessage(e));
            resultStatus = AuditElements.Result.FAILURE;
            output = e;
            LOG.warn("Error pushing {} towards {}", any, profile.getTask().getResource(), e);
            for (PushActions action : profile.getActions()) {
                action.onError(profile, any, result, e);
            }
            throw new JobExecutionException(e);
        } finally {
            if (notificationsAvailable || auditRequested) {
                Map<String, Object> jobMap = new HashMap<>();
                jobMap.put(AfterHandlingEvent.JOBMAP_KEY, new AfterHandlingEvent(AuditElements.EventCategoryType.PUSH, any.getType().getKind().name().toLowerCase(), profile.getTask().getResource().getKey(), operation, resultStatus, beforeObj, output, any));
                AfterHandlingJob.schedule(scheduler, jobMap);
            }
        }
    }
}
Also used : MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) User(org.apache.syncope.core.persistence.api.entity.user.User) HashMap(java.util.HashMap) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) AfterHandlingEvent(org.apache.syncope.core.provisioning.api.event.AfterHandlingEvent) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) TimeoutException(org.apache.syncope.core.provisioning.api.TimeoutException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result) JobExecutionException(org.quartz.JobExecutionException) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) PushActions(org.apache.syncope.core.provisioning.api.pushpull.PushActions) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils)

Example 4 with Result

use of org.apache.syncope.common.lib.types.AuditElements.Result 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)

Example 5 with Result

use of org.apache.syncope.common.lib.types.AuditElements.Result in project syncope by apache.

the class DefaultRealmPushResultHandler method doHandle.

private void doHandle(final Realm realm) throws JobExecutionException {
    ProvisioningReport result = new ProvisioningReport();
    profile.getResults().add(result);
    result.setKey(realm.getKey());
    result.setAnyType(REALM_TYPE);
    result.setName(realm.getFullPath());
    LOG.debug("Propagating Realm with key {} towards {}", realm.getKey(), profile.getTask().getResource());
    Object output = null;
    Result resultStatus = null;
    // Try to read remote object BEFORE any actual operation
    OrgUnit orgUnit = profile.getTask().getResource().getOrgUnit();
    Optional<? extends OrgUnitItem> connObjectKey = orgUnit.getConnObjectKeyItem();
    Optional<String> connObjecKeyValue = mappingManager.getConnObjectKeyValue(realm, orgUnit);
    ConnectorObject beforeObj = null;
    if (connObjectKey.isPresent() && connObjecKeyValue.isPresent()) {
        beforeObj = getRemoteObject(orgUnit.getObjectClass(), connObjectKey.get().getExtAttrName(), connObjecKeyValue.get(), orgUnit.getItems().iterator());
    } else {
        LOG.debug("OrgUnitItem {} or its value {} are null", connObjectKey, connObjecKeyValue);
    }
    if (profile.isDryRun()) {
        if (beforeObj == null) {
            result.setOperation(toResourceOperation(profile.getTask().getUnmatchingRule()));
        } else {
            result.setOperation(toResourceOperation(profile.getTask().getMatchingRule()));
        }
        result.setStatus(ProvisioningReport.Status.SUCCESS);
    } else {
        String operation = beforeObj == null ? UnmatchingRule.toEventName(profile.getTask().getUnmatchingRule()) : MatchingRule.toEventName(profile.getTask().getMatchingRule());
        boolean notificationsAvailable = notificationManager.notificationsAvailable(AuditElements.EventCategoryType.PUSH, REALM_TYPE.toLowerCase(), profile.getTask().getResource().getKey(), operation);
        boolean auditRequested = auditManager.auditRequested(AuditElements.EventCategoryType.PUSH, REALM_TYPE.toLowerCase(), profile.getTask().getResource().getKey(), operation);
        try {
            if (beforeObj == null) {
                result.setOperation(toResourceOperation(profile.getTask().getUnmatchingRule()));
                switch(profile.getTask().getUnmatchingRule()) {
                    case ASSIGN:
                        for (PushActions action : profile.getActions()) {
                            action.beforeAssign(profile, realm);
                        }
                        if (!profile.getTask().isPerformCreate()) {
                            LOG.debug("PushTask not configured for create");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            assign(realm, result);
                        }
                        break;
                    case PROVISION:
                        for (PushActions action : profile.getActions()) {
                            action.beforeProvision(profile, realm);
                        }
                        if (!profile.getTask().isPerformCreate()) {
                            LOG.debug("PushTask not configured for create");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            provision(realm, result);
                        }
                        break;
                    case UNLINK:
                        for (PushActions action : profile.getActions()) {
                            action.beforeUnlink(profile, realm);
                        }
                        if (!profile.getTask().isPerformUpdate()) {
                            LOG.debug("PushTask not configured for update");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            link(realm, true, result);
                        }
                        break;
                    case IGNORE:
                        LOG.debug("Ignored any: {}", realm);
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                        break;
                    default:
                }
            } else {
                result.setOperation(toResourceOperation(profile.getTask().getMatchingRule()));
                switch(profile.getTask().getMatchingRule()) {
                    case UPDATE:
                        for (PushActions action : profile.getActions()) {
                            action.beforeUpdate(profile, realm);
                        }
                        if (!profile.getTask().isPerformUpdate()) {
                            LOG.debug("PushTask not configured for update");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            update(binder.getRealmTO(realm, true), result);
                        }
                        break;
                    case DEPROVISION:
                        for (PushActions action : profile.getActions()) {
                            action.beforeDeprovision(profile, realm);
                        }
                        if (!profile.getTask().isPerformDelete()) {
                            LOG.debug("PushTask not configured for delete");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            deprovision(realm, result);
                        }
                        break;
                    case UNASSIGN:
                        for (PushActions action : profile.getActions()) {
                            action.beforeUnassign(profile, realm);
                        }
                        if (!profile.getTask().isPerformDelete()) {
                            LOG.debug("PushTask not configured for delete");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            unassign(realm, result);
                        }
                        break;
                    case LINK:
                        for (PushActions action : profile.getActions()) {
                            action.beforeLink(profile, realm);
                        }
                        if (!profile.getTask().isPerformUpdate()) {
                            LOG.debug("PushTask not configured for update");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            link(realm, false, result);
                        }
                        break;
                    case UNLINK:
                        for (PushActions action : profile.getActions()) {
                            action.beforeUnlink(profile, realm);
                        }
                        if (!profile.getTask().isPerformUpdate()) {
                            LOG.debug("PushTask not configured for update");
                            result.setStatus(ProvisioningReport.Status.IGNORE);
                        } else {
                            link(realm, true, result);
                        }
                        break;
                    case IGNORE:
                        LOG.debug("Ignored any: {}", realm);
                        result.setStatus(ProvisioningReport.Status.IGNORE);
                        break;
                    default:
                }
            }
            for (PushActions action : profile.getActions()) {
                action.after(profile, realm, result);
            }
            if (result.getStatus() == null) {
                result.setStatus(ProvisioningReport.Status.SUCCESS);
            }
            resultStatus = AuditElements.Result.SUCCESS;
            if (connObjectKey.isPresent() && connObjecKeyValue.isPresent()) {
                output = getRemoteObject(orgUnit.getObjectClass(), connObjectKey.get().getExtAttrName(), connObjecKeyValue.get(), orgUnit.getItems().iterator());
            }
        } catch (IgnoreProvisionException e) {
            throw e;
        } catch (Exception e) {
            result.setStatus(ProvisioningReport.Status.FAILURE);
            result.setMessage(ExceptionUtils.getRootCauseMessage(e));
            resultStatus = AuditElements.Result.FAILURE;
            output = e;
            LOG.warn("Error pushing {} towards {}", realm, profile.getTask().getResource(), e);
            for (PushActions action : profile.getActions()) {
                action.onError(profile, realm, result, e);
            }
            throw new JobExecutionException(e);
        } finally {
            if (notificationsAvailable || auditRequested) {
                Map<String, Object> jobMap = new HashMap<>();
                jobMap.put(AfterHandlingEvent.JOBMAP_KEY, new AfterHandlingEvent(AuditElements.EventCategoryType.PUSH, REALM_TYPE.toLowerCase(), profile.getTask().getResource().getKey(), operation, resultStatus, beforeObj, output, realm));
                AfterHandlingJob.schedule(scheduler, jobMap);
            }
        }
    }
}
Also used : OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) HashMap(java.util.HashMap) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) AfterHandlingEvent(org.apache.syncope.core.provisioning.api.event.AfterHandlingEvent) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) TimeoutException(org.apache.syncope.core.provisioning.api.TimeoutException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result) JobExecutionException(org.quartz.JobExecutionException) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) PushActions(org.apache.syncope.core.provisioning.api.pushpull.PushActions)

Aggregations

Result (org.apache.syncope.common.lib.types.AuditElements.Result)15 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)12 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)12 JobExecutionException (org.quartz.JobExecutionException)12 ArrayList (java.util.ArrayList)10 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)10 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)8 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)8 Date (java.util.Date)5 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)5 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)4 AnyTO (org.apache.syncope.common.lib.to.AnyTO)4 RealmTO (org.apache.syncope.common.lib.to.RealmTO)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)4 Realm (org.apache.syncope.core.persistence.api.entity.Realm)4 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)4 TimeoutException (org.apache.syncope.core.provisioning.api.TimeoutException)4 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)4 Remediation (org.apache.syncope.core.persistence.api.entity.Remediation)3 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)3