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;
}
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);
}
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());
}
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);
}
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;
}
Aggregations