use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class DefaultUserProvisioningManager method delete.
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public List<PropagationStatus> delete(final String key, final Set<String> excludedResources, final boolean nullPriorityAsync) {
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
List<PropagationTaskTO> tasks = propagationManager.getDeleteTasks(AnyTypeKind.USER, key, propByRes, excludedResources);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
try {
uwfAdapter.delete(key);
} catch (PropagationException e) {
throw e;
}
return propagationReporter.getStatuses();
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class DefaultUserProvisioningManager method propagateStatus.
protected List<PropagationStatus> propagateStatus(final StatusPatch statusPatch, final boolean nullPriorityAsync) {
PropagationByResource propByRes = new PropagationByResource();
propByRes.addAll(ResourceOperation.UPDATE, statusPatch.getResources());
List<PropagationTaskTO> tasks = propagationManager.getUpdateTasks(AnyTypeKind.USER, statusPatch.getKey(), false, statusPatch.getType() != StatusPatchType.SUSPEND, propByRes, null, null);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
return propagationReporter.getStatuses();
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class DefaultUserProvisioningManager method update.
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public Pair<UserPatch, List<PropagationStatus>> update(final UserPatch userPatch, final ProvisioningReport result, final Boolean enabled, final Set<String> excludedResources, final boolean nullPriorityAsync) {
WorkflowResult<Pair<UserPatch, Boolean>> updated;
try {
updated = uwfAdapter.update(userPatch);
} catch (Exception e) {
LOG.error("Update of user {} failed, trying to pull its status anyway (if configured)", userPatch.getKey(), e);
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage("Update failed, trying to pull status anyway (if configured)\n" + e.getMessage());
updated = new WorkflowResult<>(Pair.of(userPatch, false), new PropagationByResource(), new HashSet<>());
}
if (enabled != null) {
User user = userDAO.find(userPatch.getKey());
WorkflowResult<String> enableUpdate = null;
if (user.isSuspended() == null) {
enableUpdate = uwfAdapter.activate(userPatch.getKey(), null);
} else if (enabled && user.isSuspended()) {
enableUpdate = uwfAdapter.reactivate(userPatch.getKey());
} else if (!enabled && !user.isSuspended()) {
enableUpdate = uwfAdapter.suspend(userPatch.getKey());
}
if (enableUpdate != null) {
if (enableUpdate.getPropByRes() != null) {
updated.getPropByRes().merge(enableUpdate.getPropByRes());
updated.getPropByRes().purge();
}
updated.getPerformedTasks().addAll(enableUpdate.getPerformedTasks());
}
}
List<PropagationTaskTO> tasks = propagationManager.getUserUpdateTasks(updated, updated.getResult().getLeft().getPassword() != null, excludedResources);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
return Pair.of(updated.getResult().getLeft(), propagationReporter.getStatuses());
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class DefaultUserProvisioningManager method provision.
@Override
public List<PropagationStatus> provision(final String key, final boolean changePwd, final String password, final Collection<String> resources, final boolean nullPriorityAsync) {
UserPatch userPatch = new UserPatch();
userPatch.setKey(key);
userPatch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(resource).build()).collect(Collectors.toSet()));
if (changePwd) {
PasswordPatch passwordPatch = new PasswordPatch();
passwordPatch.setOnSyncope(false);
passwordPatch.getResources().addAll(resources);
passwordPatch.setValue(password);
userPatch.setPassword(passwordPatch);
}
PropagationByResource propByRes = new PropagationByResource();
propByRes.addAll(ResourceOperation.UPDATE, resources);
WorkflowResult<Pair<UserPatch, Boolean>> wfResult = new WorkflowResult<>(ImmutablePair.of(userPatch, (Boolean) null), propByRes, "update");
List<PropagationTaskTO> tasks = propagationManager.getUserUpdateTasks(wfResult, changePwd, null);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
return propagationReporter.getStatuses();
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class AbstractAnyDataBinder method fill.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected PropagationByResource fill(final Any any, final AnyPatch anyPatch, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
PropagationByResource propByRes = new PropagationByResource();
// 1. anyTypeClasses
for (StringPatchItem patch : anyPatch.getAuxClasses()) {
AnyTypeClass auxClass = anyTypeClassDAO.find(patch.getValue());
if (auxClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", patch.getValue());
} else {
switch(patch.getOperation()) {
case ADD_REPLACE:
any.add(auxClass);
break;
case DELETE:
default:
any.getAuxClasses().remove(auxClass);
}
}
}
// 2. resources
for (StringPatchItem patch : anyPatch.getResources()) {
ExternalResource resource = resourceDAO.find(patch.getValue());
if (resource == null) {
LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", patch.getValue());
} else {
switch(patch.getOperation()) {
case ADD_REPLACE:
propByRes.add(ResourceOperation.CREATE, resource.getKey());
any.add(resource);
break;
case DELETE:
default:
propByRes.add(ResourceOperation.DELETE, resource.getKey());
any.getResources().remove(resource);
}
}
}
Set<ExternalResource> resources = anyUtils.getAllResources(any);
SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
// 3. plain attributes
anyPatch.getPlainAttrs().stream().filter(patch -> patch.getAttrTO() != null).forEach(patch -> {
PlainSchema schema = getPlainSchema(patch.getAttrTO().getSchema());
if (schema == null) {
LOG.debug("Invalid " + PlainSchema.class.getSimpleName() + " {}, ignoring...", patch.getAttrTO().getSchema());
} else {
PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
if (attr == null) {
LOG.debug("No plain attribute found for schema {}", schema);
if (patch.getOperation() == PatchOperation.ADD_REPLACE) {
attr = anyUtils.newPlainAttr();
((PlainAttr) attr).setOwner(any);
attr.setSchema(schema);
any.add(attr);
}
}
if (attr != null) {
processAttrPatch(any, patch, schema, attr, anyUtils, resources, propByRes, invalidValues);
}
}
});
if (!invalidValues.isEmpty()) {
scce.addException(invalidValues);
}
SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
requiredValuesMissing = checkMandatoryOnResources(any, resources);
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
return propByRes;
}
Aggregations