Search in sources :

Example 1 with IgnoreProvisionException

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

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

the class DefaultRealmPushResultHandler method handle.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public boolean handle(final String realmKey) {
    Realm realm = null;
    try {
        realm = realmDAO.find(realmKey);
        doHandle(realm);
        return true;
    } catch (IgnoreProvisionException e) {
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.NONE);
        result.setAnyType(realm == null ? null : REALM_TYPE);
        result.setStatus(ProvisioningReport.Status.IGNORE);
        result.setKey(realmKey);
        profile.getResults().add(result);
        LOG.warn("Ignoring during push", e);
        return true;
    } catch (JobExecutionException e) {
        LOG.error("Push failed", e);
        return false;
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IgnoreProvisionException

use of org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException 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)

Example 4 with IgnoreProvisionException

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

the class AbstractPushResultHandler method handle.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public boolean handle(final String anyKey) {
    Any<?> any = null;
    try {
        any = getAny(anyKey);
        doHandle(any);
        return true;
    } catch (IgnoreProvisionException e) {
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.NONE);
        result.setAnyType(any == null ? null : any.getType().getKey());
        result.setStatus(ProvisioningReport.Status.IGNORE);
        result.setKey(anyKey);
        profile.getResults().add(result);
        LOG.warn("Ignoring during push", e);
        return true;
    } catch (JobExecutionException e) {
        LOG.error("Push failed", e);
        return false;
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with IgnoreProvisionException

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

the class DefaultRealmPullResultHandler method handle.

@Override
public boolean handle(final SyncDelta delta) {
    try {
        OrgUnit orgUnit = profile.getTask().getResource().getOrgUnit();
        if (orgUnit == null) {
            throw new JobExecutionException("No orgUnit found on " + profile.getTask().getResource() + " for " + delta.getObject().getObjectClass());
        }
        doHandle(delta, orgUnit);
        executor.reportHandled(delta.getObjectClass(), delta.getObject().getName());
        LOG.debug("Successfully handled {}", delta);
        if (profile.getTask().getPullMode() != PullMode.INCREMENTAL) {
            return true;
        }
        boolean shouldContinue;
        synchronized (this) {
            shouldContinue = latestResult == Result.SUCCESS;
            this.latestResult = null;
        }
        if (shouldContinue) {
            executor.setLatestSyncToken(delta.getObjectClass(), delta.getToken());
        }
        return shouldContinue;
    } catch (IgnoreProvisionException e) {
        ProvisioningReport ignoreResult = new ProvisioningReport();
        ignoreResult.setOperation(ResourceOperation.NONE);
        ignoreResult.setStatus(ProvisioningReport.Status.IGNORE);
        ignoreResult.setAnyType(REALM_TYPE);
        ignoreResult.setKey(null);
        ignoreResult.setName(delta.getObject().getName().getNameValue());
        profile.getResults().add(ignoreResult);
        LOG.warn("Ignoring during pull", e);
        executor.setLatestSyncToken(delta.getObjectClass(), delta.getToken());
        executor.reportHandled(delta.getObjectClass(), delta.getObject().getName());
        return true;
    } catch (JobExecutionException e) {
        LOG.error("Pull failed", e);
        return false;
    }
}
Also used : OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) JobExecutionException(org.quartz.JobExecutionException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)

Aggregations

IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)6 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)6 JobExecutionException (org.quartz.JobExecutionException)6 HashMap (java.util.HashMap)2 Result (org.apache.syncope.common.lib.types.AuditElements.Result)2 OrgUnit (org.apache.syncope.core.persistence.api.entity.resource.OrgUnit)2 TimeoutException (org.apache.syncope.core.provisioning.api.TimeoutException)2 AfterHandlingEvent (org.apache.syncope.core.provisioning.api.event.AfterHandlingEvent)2 PushActions (org.apache.syncope.core.provisioning.api.pushpull.PushActions)2 ConnectorObject (org.identityconnectors.framework.common.objects.ConnectorObject)2 Transactional (org.springframework.transaction.annotation.Transactional)2 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)1 Realm (org.apache.syncope.core.persistence.api.entity.Realm)1 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)1 MappingItem (org.apache.syncope.core.persistence.api.entity.resource.MappingItem)1 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)1 User (org.apache.syncope.core.persistence.api.entity.user.User)1