use of org.apache.syncope.common.lib.patch.UserPatch 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.common.lib.patch.UserPatch in project syncope by apache.
the class SearchITCase method issueSYNCOPE1223.
@Test
public void issueSYNCOPE1223() {
UserPatch patch = new UserPatch();
patch.setKey("vivaldi");
patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO("ctype", "ou=sample,o=isp")).build());
userService.update(patch);
try {
PagedResult<UserTO> users = userService.search(new AnyQuery.Builder().fiql(SyncopeClient.getUserSearchConditionBuilder().is("ctype").equalTo("ou=sample%252Co=isp").query()).build());
assertEquals(1, users.getTotalCount());
assertEquals("vivaldi", users.getResult().get(0).getUsername());
} finally {
patch.getPlainAttrs().clear();
patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO("ctype", "F")).build());
userService.update(patch);
}
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserITCase method updateWithoutPassword.
@Test
public void updateWithoutPassword() {
UserTO userTO = getUniqueSampleTO("updatewithout@password.com");
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.DELETE).attrTO(new AttrTO.Builder().schema("ctype").build()).build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
assertFalse(userTO.getPlainAttr("ctype").isPresent());
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserITCase method update.
@Test
public void update() {
UserTO userTO = getUniqueSampleTO("g.h@t.com");
userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
userTO = createUser(userTO).getEntity();
assertFalse(userTO.getDerAttrs().isEmpty());
assertEquals(1, userTO.getMemberships().size());
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.setPassword(new PasswordPatch.Builder().value("new2Password").build());
String newUserId = getUUIDString() + "t.w@spre.net";
userPatch.getPlainAttrs().add(attrAddReplacePatch("userId", newUserId));
String newFullName = getUUIDString() + "g.h@t.com";
userPatch.getPlainAttrs().add(attrAddReplacePatch("fullname", newFullName));
userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(userTO.getMemberships().get(0).getGroupKey()).build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
// issue SYNCOPE-15
assertNotNull(userTO.getCreationDate());
assertNotNull(userTO.getCreator());
assertNotNull(userTO.getLastChangeDate());
assertNotNull(userTO.getLastModifier());
assertTrue(userTO.getCreationDate().before(userTO.getLastChangeDate()));
assertEquals(1, userTO.getMemberships().size());
assertFalse(userTO.getDerAttrs().isEmpty());
AttrTO userIdAttr = userTO.getPlainAttr("userId").get();
assertEquals(Collections.singletonList(newUserId), userIdAttr.getValues());
AttrTO fullNameAttr = userTO.getPlainAttr("fullname").get();
assertEquals(Collections.singletonList(newFullName), fullNameAttr.getValues());
// update by username
userPatch = new UserPatch();
userPatch.setKey(userTO.getUsername());
String newUsername = UUID.randomUUID().toString();
userPatch.setUsername(new StringReplacePatchItem.Builder().value(newUsername).build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
assertEquals(newUsername, userTO.getUsername());
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class RESTITCase method ifMatch.
@Test
public void ifMatch() {
UserTO userTO = userService.create(UserITCase.getUniqueSampleTO("ifmatch@syncope.apache.org"), true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(userTO);
assertNotNull(userTO.getKey());
EntityTag etag = adminClient.getLatestEntityTag(userService);
assertNotNull(etag);
assertTrue(StringUtils.isNotBlank(etag.getValue()));
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.setUsername(new StringReplacePatchItem.Builder().value(userTO.getUsername() + "XX").build());
userTO = userService.update(userPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertTrue(userTO.getUsername().endsWith("XX"));
EntityTag etag1 = adminClient.getLatestEntityTag(userService);
assertFalse(etag.getValue().equals(etag1.getValue()));
UserService ifMatchService = adminClient.ifMatch(adminClient.getService(UserService.class), etag);
userPatch.setUsername(new StringReplacePatchItem.Builder().value(userTO.getUsername() + "YY").build());
try {
ifMatchService.update(userPatch);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.ConcurrentModification, e.getType());
}
userTO = userService.read(userTO.getKey());
assertTrue(userTO.getUsername().endsWith("XX"));
}
Aggregations