Search in sources :

Example 1 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 AnyTO anyTO, 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.create((UserTO) anyTO, true, nullPriorityAsync);
            break;
        case GROUP:
            result = groupLogic.create((GroupTO) anyTO, nullPriorityAsync);
            break;
        case ANY_OBJECT:
            result = anyObjectLogic.create((AnyObjectTO) anyTO, nullPriorityAsync);
    }
    remediationDAO.delete(remediation);
    return result;
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) UserTO(org.apache.syncope.common.lib.to.UserTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation) GroupTO(org.apache.syncope.common.lib.to.GroupTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with Remediation

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

the class RemediationLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.REMEDIATION_DELETE + "')")
public void delete(final String key) {
    Remediation remediation = remediationDAO.find(key);
    if (remediation == null) {
        LOG.error("Could not find remediation '" + key + "'");
        throw new NotFoundException(key);
    }
    remediationDAO.delete(remediation);
}
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 3 with Remediation

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

the class RemediationTest method create.

@Test
public void create() {
    Remediation remediation = entityFactory.newEntity(Remediation.class);
    remediation.setAnyType(anyTypeDAO.find("PRINTER"));
    remediation.setOperation(ResourceOperation.CREATE);
    remediation.setError("Error");
    remediation.setInstant(new Date());
    remediation.setRemoteName("remote");
    remediation.setPullTask(taskDAO.find("38abbf9e-a1a3-40a1-a15f-7d0ac02f47f1"));
    // missing payload
    try {
        remediationDAO.save(remediation);
        fail("This should not happen");
    } catch (InvalidEntityException e) {
        Set<EntityViolationType> violations = e.getViolations().values().iterator().next();
        assertEquals(2, violations.size());
        assertTrue(violations.stream().allMatch(violation -> violation.getPropertyPath().equals("payload")));
    }
    remediation.setPayload(UUID.randomUUID().toString());
    // wrong payload for operation
    try {
        remediationDAO.save(remediation);
        fail("This should not happen");
    } catch (InvalidEntityException e) {
        Set<EntityViolationType> violations = e.getViolations().values().iterator().next();
        assertEquals(1, violations.size());
        assertTrue(violations.stream().anyMatch(violation -> violation.getPropertyPath().equals("payload")));
    }
    remediation.setOperation(ResourceOperation.DELETE);
    remediation = remediationDAO.save(remediation);
    assertNotNull(remediation.getKey());
    assertNotNull(remediation.getPullTask());
    taskDAO.delete(remediation.getPullTask());
    remediationDAO.flush();
    remediation = remediationDAO.find(remediation.getKey());
    assertNull(remediation.getPullTask());
}
Also used : Set(java.util.Set) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation) Date(java.util.Date) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 4 with Remediation

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

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

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