use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.
the class DeleteProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
String key = exchange.getIn().getBody(String.class);
Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
if (null != getAnyTypeKind()) {
List<PropagationTaskTO> tasks;
PropagationReporter propagationReporter;
switch(getAnyTypeKind()) {
case USER:
PropagationByResource propByRes = new PropagationByResource();
propByRes.set(ResourceOperation.DELETE, userDAO.findAllResourceKeys(key));
// Note here that we can only notify about "delete", not any other
// task defined in workflow process definition: this because this
// information could only be available after uwfAdapter.delete(), which
// will also effectively remove user from db, thus making virtually
// impossible by NotificationManager to fetch required user information
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.USER, key, propByRes, excludedResources);
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.setProperty("statuses", propagationReporter.getStatuses());
break;
case GROUP:
tasks = new ArrayList<>();
// resources only because of the reason being deleted (see SYNCOPE-357)
for (Map.Entry<String, PropagationByResource> entry : groupDataBinder.findUsersWithTransitiveResources(key).entrySet()) {
tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.USER, entry.getKey(), entry.getValue(), excludedResources));
}
for (Map.Entry<String, PropagationByResource> entry : groupDataBinder.findAnyObjectsWithTransitiveResources(key).entrySet()) {
tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, entry.getKey(), entry.getValue(), excludedResources));
}
// Generate propagation tasks for deleting this group from resources
tasks.addAll(getPropagationManager().getDeleteTasks(AnyTypeKind.GROUP, key, null, null));
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.setProperty("statuses", propagationReporter.getStatuses());
break;
case ANY_OBJECT:
tasks = getPropagationManager().getDeleteTasks(AnyTypeKind.ANY_OBJECT, key, null, excludedResources);
propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.setProperty("statuses", propagationReporter.getStatuses());
break;
default:
break;
}
}
}
use of org.apache.syncope.common.lib.to.PropagationTaskTO 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.common.lib.to.PropagationTaskTO in project syncope by apache.
the class UpdateProducer method process.
@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
Object actual = exchange.getProperty("actual");
Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
if (actual instanceof UserPatch || isPull()) {
WorkflowResult<Pair<UserPatch, Boolean>> updated = (WorkflowResult<Pair<UserPatch, Boolean>>) exchange.getIn().getBody();
List<PropagationTaskTO> tasks;
if (isPull()) {
boolean passwordNotNull = updated.getResult().getKey().getPassword() != null;
tasks = getPropagationManager().getUserUpdateTasks(updated, passwordNotNull, excludedResources);
} else {
tasks = getPropagationManager().getUserUpdateTasks(updated);
}
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(updated.getResult().getLeft(), propagationReporter.getStatuses()));
} else if (actual instanceof AnyPatch) {
WorkflowResult<? extends AnyPatch> updated = (WorkflowResult<? extends AnyPatch>) exchange.getIn().getBody();
List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(actual instanceof AnyObjectPatch ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, updated.getResult().getKey(), false, null, updated.getPropByRes(), ((AnyPatch) actual).getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
}
}
}
use of org.apache.syncope.common.lib.to.PropagationTaskTO in project syncope by apache.
the class DefaultPropagationReporter method onPriorityResourceFailure.
@Override
public void onPriorityResourceFailure(final String failingResource, final Collection<PropagationTaskTO> tasks) {
LOG.debug("Propagation error: {} priority resource failed to propagate", failingResource);
Optional<PropagationTaskTO> propagationTask = tasks.stream().filter(task -> task.getResource().equals(failingResource)).findFirst();
if (propagationTask.isPresent()) {
PropagationStatus status = new PropagationStatus();
status.setResource(propagationTask.get().getResource());
status.setStatus(PropagationTaskExecStatus.FAILURE);
status.setFailureReason("Propagation error: " + failingResource + " priority resource failed to propagate.");
add(status);
} else {
LOG.error("Could not find {} for {}", PropagationTask.class.getName(), failingResource);
}
}
use of org.apache.syncope.common.lib.to.PropagationTaskTO 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;
}
Aggregations