use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class DeprovisionProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
String key = exchange.getIn().getBody(String.class);
List<String> resources = exchange.getProperty("resources", List.class);
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
if (null != getAnyTypeKind()) {
PropagationByResource propByRes = new PropagationByResource();
List<PropagationTaskTO> tasks;
PropagationReporter propagationReporter;
switch(getAnyTypeKind()) {
case USER:
propByRes.set(ResourceOperation.DELETE, resources);
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.USER, key, propByRes, userDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(propagationReporter.getStatuses());
break;
case GROUP:
propByRes.addAll(ResourceOperation.DELETE, resources);
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.GROUP, key, propByRes, groupDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(propagationReporter.getStatuses());
break;
case ANY_OBJECT:
propByRes.addAll(ResourceOperation.DELETE, resources);
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, key, propByRes, anyObjectDAO.findAllResourceKeys(key).stream().filter(resource -> !resources.contains(resource)).collect(Collectors.toList()));
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(propagationReporter.getStatuses());
break;
default:
break;
}
}
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class StatusProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
if (getAnyTypeKind() == AnyTypeKind.USER && isPull()) {
WorkflowResult<Map.Entry<UserPatch, Boolean>> updated = (WorkflowResult<Entry<UserPatch, Boolean>>) exchange.getIn().getBody();
Boolean enabled = exchange.getProperty("enabled", Boolean.class);
String key = exchange.getProperty("key", String.class);
if (enabled != null) {
User user = userDAO.find(key);
WorkflowResult<String> enableUpdate = null;
if (user.isSuspended() == null) {
enableUpdate = uwfAdapter.activate(key, null);
} else if (enabled && user.isSuspended()) {
enableUpdate = uwfAdapter.reactivate(key);
} else if (!enabled && !user.isSuspended()) {
enableUpdate = uwfAdapter.suspend(key);
}
if (enableUpdate != null) {
if (enableUpdate.getPropByRes() != null) {
updated.getPropByRes().merge(enableUpdate.getPropByRes());
updated.getPropByRes().purge();
}
updated.getPerformedTasks().addAll(enableUpdate.getPerformedTasks());
}
}
} else if (getAnyTypeKind() == AnyTypeKind.USER) {
WorkflowResult<Long> updated = (WorkflowResult<Long>) exchange.getIn().getBody();
StatusPatch statusPatch = exchange.getProperty("statusPatch", StatusPatch.class);
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
PropagationByResource propByRes = new PropagationByResource();
propByRes.addAll(ResourceOperation.UPDATE, statusPatch.getResources());
List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(AnyTypeKind.USER, statusPatch.getKey(), false, statusPatch.getType() != StatusPatchType.SUSPEND, propByRes, null, null);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
}
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class PropagationManagerImpl method createTasks.
/**
* Create propagation tasks.
*
* @param any to be provisioned
* @param password clear text password to be provisioned
* @param changePwd whether password should be included for propagation attributes or not
* @param enable whether user must be enabled or not
* @param deleteOnResource whether any must be deleted anyway from external resource or not
* @param propByRes operation to be performed per resource
* @param vAttrs virtual attributes to be set
* @return list of propagation tasks created
*/
protected List<PropagationTaskTO> createTasks(final Any<?> any, final String password, final boolean changePwd, final Boolean enable, final boolean deleteOnResource, final PropagationByResource propByRes, final Collection<AttrTO> vAttrs) {
LOG.debug("Provisioning {}:\n{}", any, propByRes);
// Avoid duplicates - see javadoc
propByRes.purge();
LOG.debug("After purge {}:\n{}", any, propByRes);
// Virtual attributes
Set<String> virtualResources = new HashSet<>();
virtualResources.addAll(propByRes.get(ResourceOperation.CREATE));
virtualResources.addAll(propByRes.get(ResourceOperation.UPDATE));
virtualResources.addAll(dao(any.getType().getKind()).findAllResourceKeys(any.getKey()));
Map<String, Set<Attribute>> vAttrMap = new HashMap<>();
if (vAttrs != null) {
vAttrs.forEach(vAttr -> {
VirSchema schema = virSchemaDAO.find(vAttr.getSchema());
if (schema == null) {
LOG.warn("Ignoring invalid {} {}", VirSchema.class.getSimpleName(), vAttr.getSchema());
} else if (schema.isReadonly()) {
LOG.warn("Ignoring read-only {} {}", VirSchema.class.getSimpleName(), vAttr.getSchema());
} else if (anyUtilsFactory.getInstance(any).getAllowedSchemas(any, VirSchema.class).contains(schema) && virtualResources.contains(schema.getProvision().getResource().getKey())) {
Set<Attribute> values = vAttrMap.get(schema.getProvision().getResource().getKey());
if (values == null) {
values = new HashSet<>();
vAttrMap.put(schema.getProvision().getResource().getKey(), values);
}
values.add(AttributeBuilder.build(schema.getExtAttrName(), vAttr.getValues()));
propByRes.add(ResourceOperation.UPDATE, schema.getProvision().getResource().getKey());
} else {
LOG.warn("{} not owned by or {} not allowed for {}", schema.getProvision().getResource(), schema, any);
}
});
}
LOG.debug("With virtual attributes {}:\n{}\n{}", any, propByRes, vAttrMap);
List<PropagationTaskTO> tasks = new ArrayList<>();
propByRes.asMap().forEach((resourceKey, operation) -> {
ExternalResource resource = resourceDAO.find(resourceKey);
Provision provision = resource == null ? null : resource.getProvision(any.getType()).orElse(null);
List<? extends Item> mappingItems = provision == null ? Collections.<Item>emptyList() : MappingUtils.getPropagationItems(provision.getMapping().getItems());
if (resource == null) {
LOG.error("Invalid resource name specified: {}, ignoring...", resourceKey);
} else if (provision == null) {
LOG.error("No provision specified on resource {} for type {}, ignoring...", resource, any.getType());
} else if (mappingItems.isEmpty()) {
LOG.warn("Requesting propagation for {} but no propagation mapping provided for {}", any.getType(), resource);
} else {
PropagationTaskTO task = new PropagationTaskTO();
task.setResource(resource.getKey());
task.setObjectClassName(provision.getObjectClass().getObjectClassValue());
task.setAnyTypeKind(any.getType().getKind());
task.setAnyType(any.getType().getKey());
if (!deleteOnResource) {
task.setEntityKey(any.getKey());
}
task.setOperation(operation);
task.setOldConnObjectKey(propByRes.getOldConnObjectKey(resource.getKey()));
Pair<String, Set<Attribute>> preparedAttrs = mappingManager.prepareAttrs(any, password, changePwd, enable, provision);
task.setConnObjectKey(preparedAttrs.getKey());
// Check if any of mandatory attributes (in the mapping) is missing or not received any value:
// if so, add special attributes that will be evaluated by PropagationTaskExecutor
List<String> mandatoryMissing = new ArrayList<>();
List<String> mandatoryNullOrEmpty = new ArrayList<>();
mappingItems.stream().filter(item -> (!item.isConnObjectKey() && JexlUtils.evaluateMandatoryCondition(item.getMandatoryCondition(), any))).forEachOrdered(item -> {
Attribute attr = AttributeUtil.find(item.getExtAttrName(), preparedAttrs.getValue());
if (attr == null) {
mandatoryMissing.add(item.getExtAttrName());
} else if (attr.getValue() == null || attr.getValue().isEmpty()) {
mandatoryNullOrEmpty.add(item.getExtAttrName());
}
});
if (!mandatoryMissing.isEmpty()) {
preparedAttrs.getValue().add(AttributeBuilder.build(PropagationTaskExecutor.MANDATORY_MISSING_ATTR_NAME, mandatoryMissing));
}
if (!mandatoryNullOrEmpty.isEmpty()) {
preparedAttrs.getValue().add(AttributeBuilder.build(PropagationTaskExecutor.MANDATORY_NULL_OR_EMPTY_ATTR_NAME, mandatoryNullOrEmpty));
}
if (vAttrMap.containsKey(resource.getKey())) {
preparedAttrs.getValue().addAll(vAttrMap.get(resource.getKey()));
}
task.setAttributes(POJOHelper.serialize(preparedAttrs.getValue()));
tasks.add(task);
LOG.debug("PropagationTask created: {}", task);
}
});
return tasks;
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class AbstractPullResultHandler method doDelete.
protected void doDelete(final AnyTypeKind kind, final String key) {
PropagationByResource propByRes = new PropagationByResource();
propByRes.add(ResourceOperation.DELETE, profile.getTask().getResource().getKey());
try {
taskExecutor.execute(propagationManager.getDeleteTasks(kind, key, propByRes, null), false);
} catch (Exception 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 anyObject " + key, e);
}
getProvisioningManager().delete(key, Collections.singleton(profile.getTask().getResource().getKey()), true);
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource 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;
}
Aggregations