Search in sources :

Example 6 with Remediation

use of org.apache.syncope.core.persistence.api.entity.Remediation 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 7 with Remediation

use of org.apache.syncope.core.persistence.api.entity.Remediation in project syncope by apache.

the class RemediationLogic method remedy.

@PreAuthorize("hasRole('" + StandardEntitlement.REMEDIATION_REMEDY + "')")
public ProvisioningResult<?> remedy(final String key, final AnyPatch anyPatch, final boolean nullPriorityAsync) {
    Remediation remediation = remediationDAO.find(key);
    if (remediation == null) {
        LOG.error("Could not find remediation '" + key + "'");
        throw new NotFoundException(key);
    }
    ProvisioningResult<?> result;
    switch(remediation.getAnyType().getKind()) {
        case USER:
        default:
            result = userLogic.update((UserPatch) anyPatch, nullPriorityAsync);
            break;
        case GROUP:
            result = groupLogic.update((GroupPatch) anyPatch, nullPriorityAsync);
            break;
        case ANY_OBJECT:
            result = anyObjectLogic.update((AnyObjectPatch) anyPatch, nullPriorityAsync);
    }
    remediationDAO.delete(remediation);
    return result;
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with Remediation

use of org.apache.syncope.core.persistence.api.entity.Remediation in project syncope by apache.

the class RemediationLogic method remedy.

@PreAuthorize("hasRole('" + StandardEntitlement.REMEDIATION_REMEDY + "')")
public ProvisioningResult<?> remedy(final String key, final String anyKey, final boolean nullPriorityAsync) {
    Remediation remediation = remediationDAO.find(key);
    if (remediation == null) {
        LOG.error("Could not find remediation '" + key + "'");
        throw new NotFoundException(key);
    }
    ProvisioningResult<?> result;
    switch(remediation.getAnyType().getKind()) {
        case USER:
        default:
            result = userLogic.delete(anyKey, nullPriorityAsync);
            break;
        case GROUP:
            result = groupLogic.delete(anyKey, nullPriorityAsync);
            break;
        case ANY_OBJECT:
            result = anyObjectLogic.delete(anyKey, nullPriorityAsync);
    }
    remediationDAO.delete(remediation);
    return result;
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 9 with Remediation

use of org.apache.syncope.core.persistence.api.entity.Remediation in project syncope by apache.

the class JPARemediationDAO method delete.

@Override
public void delete(final String key) {
    Remediation remediation = find(key);
    if (remediation == null) {
        return;
    }
    delete(remediation);
}
Also used : JPARemediation(org.apache.syncope.core.persistence.jpa.entity.JPARemediation) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation)

Aggregations

Remediation (org.apache.syncope.core.persistence.api.entity.Remediation)9 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)7 Date (java.util.Date)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 AnyTO (org.apache.syncope.common.lib.to.AnyTO)3 Result (org.apache.syncope.common.lib.types.AuditElements.Result)3 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)3 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)3 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)3 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)3 JobExecutionException (org.quartz.JobExecutionException)3 ArrayList (java.util.ArrayList)2 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)2 Set (java.util.Set)1 AnyObjectPatch (org.apache.syncope.common.lib.patch.AnyObjectPatch)1 AnyPatch (org.apache.syncope.common.lib.patch.AnyPatch)1 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)1 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)1 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)1 GroupTO (org.apache.syncope.common.lib.to.GroupTO)1