use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class ProvisionProducer 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 (getAnyTypeKind() == AnyTypeKind.USER) {
Boolean changePwd = exchange.getProperty("changePwd", Boolean.class);
String password = exchange.getProperty("password", String.class);
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.toList()));
if (changePwd) {
userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).value(password).resources(resources).build());
}
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 = getPropagationManager().getUserUpdateTasks(wfResult, changePwd, null);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(propagationReporter.getStatuses());
} else {
PropagationByResource propByRes = new PropagationByResource();
propByRes.addAll(ResourceOperation.UPDATE, resources);
AnyTypeKind anyTypeKind = AnyTypeKind.GROUP;
if (getAnyTypeKind() != null) {
anyTypeKind = getAnyTypeKind();
}
List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(anyTypeKind, key, false, null, propByRes, null, null);
PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
exchange.getOut().setBody(propagationReporter.getStatuses());
}
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class PropagationManagerImpl method getUserUpdateTasks.
@Override
public List<PropagationTaskTO> getUserUpdateTasks(final WorkflowResult<Pair<UserPatch, Boolean>> wfResult) {
UserPatch userPatch = wfResult.getResult().getKey();
// Propagate password update only to requested resources
List<PropagationTaskTO> tasks = new ArrayList<>();
if (userPatch.getPassword() == null) {
// a. no specific password propagation request: generate propagation tasks for any resource associated
tasks = getUserUpdateTasks(wfResult, false, null);
} else {
// b. generate the propagation task list in two phases: first the ones containing password,
// the the rest (with no password)
WorkflowResult<Pair<UserPatch, Boolean>> pwdWFResult = new WorkflowResult<>(wfResult.getResult(), new PropagationByResource(), wfResult.getPerformedTasks());
Set<String> pwdResourceNames = new HashSet<>(userPatch.getPassword().getResources());
Collection<String> allResourceNames = userDAO.findAllResourceKeys(userPatch.getKey());
pwdResourceNames.retainAll(allResourceNames);
pwdWFResult.getPropByRes().addAll(ResourceOperation.UPDATE, pwdResourceNames);
if (!pwdWFResult.getPropByRes().isEmpty()) {
Set<String> toBeExcluded = new HashSet<>(allResourceNames);
toBeExcluded.addAll(userPatch.getResources().stream().map(patchItem -> patchItem.getValue()).collect(Collectors.toList()));
toBeExcluded.removeAll(pwdResourceNames);
tasks.addAll(getUserUpdateTasks(pwdWFResult, true, toBeExcluded));
}
WorkflowResult<Pair<UserPatch, Boolean>> noPwdWFResult = new WorkflowResult<>(wfResult.getResult(), new PropagationByResource(), wfResult.getPerformedTasks());
noPwdWFResult.getPropByRes().merge(wfResult.getPropByRes());
noPwdWFResult.getPropByRes().removeAll(pwdResourceNames);
noPwdWFResult.getPropByRes().purge();
if (!noPwdWFResult.getPropByRes().isEmpty()) {
tasks.addAll(getUserUpdateTasks(noPwdWFResult, false, pwdResourceNames));
}
}
return tasks;
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class PropagationManagerImpl method getDeleteTasks.
@Override
public List<PropagationTaskTO> getDeleteTasks(final AnyTypeKind kind, final String key, final PropagationByResource propByRes, final Collection<String> noPropResourceKeys) {
Any<?> any = dao(kind).authFind(key);
PropagationByResource localPropByRes = new PropagationByResource();
if (propByRes == null || propByRes.isEmpty()) {
localPropByRes.addAll(ResourceOperation.DELETE, dao(kind).findAllResourceKeys(key));
} else {
localPropByRes.merge(propByRes);
}
if (noPropResourceKeys != null) {
localPropByRes.removeAll(noPropResourceKeys);
}
return getDeleteTasks(any, localPropByRes, noPropResourceKeys);
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class GroupDataBinderImpl method update.
@Override
public PropagationByResource update(final Group toBeUpdated, final GroupPatch groupPatch) {
// Re-merge any pending change from workflow tasks
Group group = groupDAO.save(toBeUpdated);
PropagationByResource propByRes = new PropagationByResource();
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.GROUP);
// fetch connObjectKeys before update
Map<String, String> oldConnObjectKeys = getConnObjectKeys(group, anyUtils);
// realm
setRealm(group, groupPatch);
// name
if (groupPatch.getName() != null && StringUtils.isNotBlank(groupPatch.getName().getValue())) {
propByRes.addAll(ResourceOperation.UPDATE, groupDAO.findAllResourceKeys(group.getKey()));
group.setName(groupPatch.getName().getValue());
}
// owner
if (groupPatch.getUserOwner() != null) {
group.setUserOwner(groupPatch.getUserOwner().getValue() == null ? null : userDAO.find(groupPatch.getUserOwner().getValue()));
}
if (groupPatch.getGroupOwner() != null) {
group.setGroupOwner(groupPatch.getGroupOwner().getValue() == null ? null : groupDAO.find(groupPatch.getGroupOwner().getValue()));
}
// attributes and resources
propByRes.merge(fill(group, groupPatch, anyUtils, scce));
// check if some connObjectKey was changed by the update above
Map<String, String> newConnObjectKeys = getConnObjectKeys(group, anyUtils);
oldConnObjectKeys.entrySet().stream().filter(entry -> newConnObjectKeys.containsKey(entry.getKey()) && !entry.getValue().equals(newConnObjectKeys.get(entry.getKey()))).forEach(entry -> {
propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
propByRes.add(ResourceOperation.UPDATE, entry.getKey());
});
group = groupDAO.save(group);
// dynamic membership
if (groupPatch.getUDynMembershipCond() == null) {
if (group.getUDynMembership() != null) {
group.getUDynMembership().setGroup(null);
group.setUDynMembership(null);
groupDAO.clearUDynMembers(group);
}
} else {
setDynMembership(group, anyTypeDAO.findUser(), groupPatch.getUDynMembershipCond());
}
for (Iterator<? extends ADynGroupMembership> itor = group.getADynMemberships().iterator(); itor.hasNext(); ) {
ADynGroupMembership memb = itor.next();
memb.setGroup(null);
itor.remove();
}
groupDAO.clearADynMembers(group);
for (Map.Entry<String, String> entry : groupPatch.getADynMembershipConds().entrySet()) {
AnyType anyType = anyTypeDAO.find(entry.getKey());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), entry.getKey());
} else {
setDynMembership(group, anyType, entry.getValue());
}
}
// type extensions
for (TypeExtensionTO typeExtTO : groupPatch.getTypeExtensions()) {
AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
} else {
TypeExtension typeExt = group.getTypeExtension(anyType).orElse(null);
if (typeExt == null) {
typeExt = entityFactory.newEntity(TypeExtension.class);
typeExt.setAnyType(anyType);
typeExt.setGroup(group);
group.add(typeExt);
}
// add all classes contained in the TO
for (String name : typeExtTO.getAuxClasses()) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
if (anyTypeClass == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
} else {
typeExt.add(anyTypeClass);
}
}
// remove all classes not contained in the TO
typeExt.getAuxClasses().removeIf(anyTypeClass -> !typeExtTO.getAuxClasses().contains(anyTypeClass.getKey()));
// only consider non-empty type extensions
if (typeExt.getAuxClasses().isEmpty()) {
group.getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
}
// remove all type extensions not contained in the TO
group.getTypeExtensions().removeIf(typeExt -> !groupPatch.getTypeExtension(typeExt.getAnyType().getKey()).isPresent());
// Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
return propByRes;
}
use of org.apache.syncope.core.provisioning.api.PropagationByResource in project syncope by apache.
the class DefaultRealmPushResultHandler method update.
private Realm update(final RealmTO realmTO, final ProvisioningReport result) {
Realm realm = realmDAO.findByFullPath(realmTO.getFullPath());
PropagationByResource propByRes = binder.update(realm, realmTO);
realm = realmDAO.save(realm);
PropagationReporter reporter = taskExecutor.execute(propagationManager.createTasks(realm, propByRes, null), false);
reportPropagation(result, reporter);
return realm;
}
Aggregations