use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class DefaultUserWorkflowAdapter method doUpdate.
@Override
protected WorkflowResult<Pair<UserPatch, Boolean>> doUpdate(final User user, final UserPatch userPatch) {
UserTO original = dataBinder.getUserTO(user, true);
PropagationByResource propByRes = dataBinder.update(user, userPatch);
PasswordPatch password = userPatch.getPassword();
Set<AttrTO> virAttrs = userPatch.getVirAttrs();
UserTO updated = dataBinder.getUserTO(userDAO.save(user), true);
UserPatch effectivePatch = AnyOperations.diff(updated, original, false);
effectivePatch.setPassword(password);
effectivePatch.getVirAttrs().clear();
effectivePatch.getVirAttrs().addAll(virAttrs);
return new WorkflowResult<>(Pair.of(effectivePatch, !user.isSuspended()), propByRes, "update");
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class DefaultUserWorkflowAdapter method doConfirmPasswordReset.
@Override
protected WorkflowResult<Pair<UserPatch, Boolean>> doConfirmPasswordReset(final User user, final String token, final String password) {
if (!user.checkToken(token)) {
throw new WorkflowException(new IllegalArgumentException("Wrong token: " + token + " for " + user));
}
user.removeToken();
UserPatch userPatch = new UserPatch();
userPatch.setKey(user.getKey());
userPatch.setPassword(new PasswordPatch.Builder().onSyncope(true).resources(userDAO.findAllResourceKeys(user.getKey())).value(password).build());
return doUpdate(user, userPatch);
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserITCase method updateMultivalueAttribute.
@Test
public void updateMultivalueAttribute() {
UserTO userTO = getUniqueSampleTO("multivalue@syncope.apache.org");
userTO.getResources().clear();
userTO.getVirAttrs().clear();
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
AttrTO loginDate = userTO.getPlainAttr("loginDate").get();
assertNotNull(loginDate);
assertEquals(1, loginDate.getValues().size());
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
loginDate.getValues().add("2000-01-01");
userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(loginDate).build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
loginDate = userTO.getPlainAttr("loginDate").get();
assertNotNull(loginDate);
assertEquals(2, loginDate.getValues().size());
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserITCase method updateSamePassword.
@Test
public void updateSamePassword() {
assertThrows(SyncopeClientException.class, () -> {
UserTO userTO = getUniqueSampleTO("updatesame@password.com");
userTO.setRealm("/even/two");
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.setPassword(new PasswordPatch.Builder().value("password123").build());
userService.update(userPatch);
});
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserITCase method verifyTaskRegistration.
@SuppressWarnings("unchecked")
@Test
public void verifyTaskRegistration() {
// get task list
PagedResult<PropagationTaskTO> tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
assertNotNull(tasks);
assertFalse(tasks.getResult().isEmpty());
String maxKey = tasks.getResult().iterator().next().getKey();
// --------------------------------------
// Create operation
// --------------------------------------
UserTO userTO = getUniqueSampleTO("t@p.mode");
// add a membership
userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
// 1. create user
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
// get the new task list
tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
assertNotNull(tasks);
assertFalse(tasks.getResult().isEmpty());
String newMaxKey = tasks.getResult().iterator().next().getKey();
// default configuration for ws-target-resource2 during create:
// only failed executions have to be registered
// --> no more tasks/executions should be added
assertEquals(newMaxKey, maxKey);
// --------------------------------------
// Update operation
// --------------------------------------
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "surname2"));
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
// get the new task list
tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
// default configuration for ws-target-resource2 during update:
// all update executions have to be registered
newMaxKey = tasks.getResult().iterator().next().getKey();
PropagationTaskTO taskTO = taskService.read(TaskType.PROPAGATION, newMaxKey, true);
assertNotNull(taskTO);
assertEquals(1, taskTO.getExecutions().size());
// --------------------------------------
// Delete operation
// --------------------------------------
userService.delete(userTO.getKey());
// get the new task list
tasks = taskService.search(new TaskQuery.Builder(TaskType.PROPAGATION).page(1).size(1).build());
maxKey = newMaxKey;
newMaxKey = tasks.getResult().iterator().next().getKey();
// default configuration for ws-target-resource2: no delete executions have to be registered
// --> no more tasks/executions should be added
assertEquals(newMaxKey, maxKey);
}
Aggregations