use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserIssuesITCase method issueSYNCOPE136Random.
@Test
public void issueSYNCOPE136Random() {
// 1. create user with no resources
UserTO userTO = UserITCase.getUniqueSampleTO("syncope136_Random@apache.org");
userTO.getResources().clear();
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
// 2. update user, assign a propagation priority resource but don't provide any password
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_LDAP).build());
userPatch.setPassword(new PasswordPatch.Builder().onSyncope(false).resource(RESOURCE_NAME_LDAP).build());
ProvisioningResult<UserTO> result = updateUser(userPatch);
assertNotNull(result);
// 3. verify that propagation was successful
List<PropagationStatus> props = result.getPropagationStatuses();
assertNotNull(props);
assertEquals(1, props.size());
PropagationStatus prop = props.iterator().next();
assertNotNull(prop);
assertEquals(RESOURCE_NAME_LDAP, prop.getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, prop.getStatus());
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserSelfITCase method mustChangePassword.
@Test
public void mustChangePassword() {
// PRE: reset vivaldi's password
UserPatch userPatch = new UserPatch();
userPatch.setKey("b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee");
userPatch.setPassword(new PasswordPatch.Builder().value("password321").build());
userService.update(userPatch);
// 0. access as vivaldi -> succeed
SyncopeClient vivaldiClient = clientFactory.create("vivaldi", "password321");
Pair<Map<String, Set<String>>, UserTO> self = vivaldiClient.self();
assertFalse(self.getRight().isMustChangePassword());
// 1. update user vivaldi (3) requirig password update
userPatch = new UserPatch();
userPatch.setKey("b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee");
userPatch.setMustChangePassword(new BooleanReplacePatchItem.Builder().value(true).build());
UserTO vivaldi = updateUser(userPatch).getEntity();
assertTrue(vivaldi.isMustChangePassword());
// 2. attempt to access -> fail
try {
vivaldiClient.getService(ResourceService.class).list();
fail("This should not happen");
} catch (ForbiddenException e) {
assertNotNull(e);
assertEquals("Please change your password first", e.getMessage());
}
// 3. change password
vivaldiClient.getService(UserSelfService.class).changePassword("password123");
// 4. verify it worked
self = clientFactory.create("vivaldi", "password123").self();
assertFalse(self.getRight().isMustChangePassword());
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserSelfITCase method updateWithApproval.
@Test
public void updateWithApproval() {
assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
// 1. create user as admin
UserTO created = createUser(UserITCase.getUniqueSampleTO("anonymous@syncope.apache.org")).getEntity();
assertNotNull(created);
assertFalse(created.getUsername().endsWith("XX"));
// 2. self-update (username + memberships + resource) - works but needs approval
UserPatch userPatch = new UserPatch();
userPatch.setKey(created.getKey());
userPatch.setUsername(new StringReplacePatchItem.Builder().value(created.getUsername() + "XX").build());
userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group("bf825fe1-7320-4a54-bd64-143b5c18ab97").build());
userPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value(RESOURCE_NAME_TESTDB).build());
userPatch.setPassword(new PasswordPatch.Builder().value("newPassword123").onSyncope(false).resource(RESOURCE_NAME_TESTDB).build());
SyncopeClient authClient = clientFactory.create(created.getUsername(), "password123");
UserTO updated = authClient.getService(UserSelfService.class).update(userPatch).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
}).getEntity();
assertNotNull(updated);
assertEquals("updateApproval", updated.getStatus());
assertFalse(updated.getUsername().endsWith("XX"));
assertTrue(updated.getMemberships().isEmpty());
// no propagation happened
assertTrue(updated.getResources().isEmpty());
try {
resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), updated.getKey());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
// 3. approve self-update as admin
WorkflowFormTO form = userWorkflowService.getFormForUser(updated.getKey());
form = userWorkflowService.claimForm(form.getTaskId());
form.getProperty("approveUpdate").get().setValue(Boolean.TRUE.toString());
updated = userWorkflowService.submitForm(form);
assertNotNull(updated);
assertEquals("active", updated.getStatus());
assertTrue(updated.getUsername().endsWith("XX"));
assertEquals(1, updated.getMemberships().size());
// check that propagation also happened
assertTrue(updated.getResources().contains(RESOURCE_NAME_TESTDB));
assertNotNull(resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), updated.getKey()));
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserWorkflowITCase method createWithApproval.
@Test
public void createWithApproval() {
assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
// read forms *before* any operation
List<WorkflowFormTO> forms = userWorkflowService.getForms();
assertNotNull(forms);
int preForms = forms.size();
UserTO userTO = UserITCase.getUniqueSampleTO("createWithApproval@syncope.apache.org");
userTO.getResources().add(RESOURCE_NAME_TESTDB);
// User with group 0cbcabd2-4410-4b6b-8f05-a052b451d18f are defined in workflow as subject to approval
userTO.getMemberships().add(new MembershipTO.Builder().group("0cbcabd2-4410-4b6b-8f05-a052b451d18f").build());
// 1. create user and verify that no propagation occurred)
ProvisioningResult<UserTO> result = createUser(userTO);
assertNotNull(result);
userTO = result.getEntity();
assertEquals(1, userTO.getMemberships().size());
assertEquals("0cbcabd2-4410-4b6b-8f05-a052b451d18f", userTO.getMemberships().get(0).getGroupKey());
assertEquals("createApproval", userTO.getStatus());
assertEquals(Collections.singleton(RESOURCE_NAME_TESTDB), userTO.getResources());
assertTrue(result.getPropagationStatuses().isEmpty());
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
Exception exception = null;
try {
jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", new String[] { userTO.getUsername() }, Integer.class);
} catch (EmptyResultDataAccessException e) {
exception = e;
}
assertNotNull(exception);
// 2. request if there is any pending form for user just created
forms = userWorkflowService.getForms();
assertNotNull(forms);
assertEquals(preForms + 1, forms.size());
// 3. as admin, request for changes: still pending approval
String updatedUsername = "changed-" + UUID.randomUUID().toString();
userTO.setUsername(updatedUsername);
userWorkflowService.executeTask("default", userTO);
WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
assertNotNull(form);
assertNotNull(form.getTaskId());
assertNotNull(form.getUserTO());
assertEquals(updatedUsername, form.getUserTO().getUsername());
assertNull(form.getUserPatch());
assertNull(form.getOwner());
// 4. claim task (as admin)
form = userWorkflowService.claimForm(form.getTaskId());
assertNotNull(form);
assertNotNull(form.getTaskId());
assertNotNull(form.getUserTO());
assertEquals(updatedUsername, form.getUserTO().getUsername());
assertNull(form.getUserPatch());
assertNotNull(form.getOwner());
// 5. approve user (and verify that propagation occurred)
form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
userTO = userWorkflowService.submitForm(form);
assertNotNull(userTO);
assertEquals(updatedUsername, userTO.getUsername());
assertEquals("active", userTO.getStatus());
assertEquals(Collections.singleton(RESOURCE_NAME_TESTDB), userTO.getResources());
String username = queryForObject(jdbcTemplate, 50, "SELECT id FROM test WHERE id=?", String.class, userTO.getUsername());
assertEquals(userTO.getUsername(), username);
// 6. update user
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.setPassword(new PasswordPatch.Builder().value("anotherPassword123").build());
userTO = updateUser(userPatch).getEntity();
assertNotNull(userTO);
}
use of org.apache.syncope.common.lib.patch.UserPatch in project syncope by apache.
the class UserWorkflowITCase method createWithReject.
@Test
public void createWithReject() {
assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
UserTO userTO = UserITCase.getUniqueSampleTO("createWithReject@syncope.apache.org");
userTO.getResources().add(RESOURCE_NAME_TESTDB);
// User with group 9 are defined in workflow as subject to approval
userTO.getMemberships().add(new MembershipTO.Builder().group("0cbcabd2-4410-4b6b-8f05-a052b451d18f").build());
// 1. create user with group 9
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
assertEquals(1, userTO.getMemberships().size());
assertEquals("0cbcabd2-4410-4b6b-8f05-a052b451d18f", userTO.getMemberships().get(0).getGroupKey());
assertEquals("createApproval", userTO.getStatus());
// 2. request if there is any pending task for user just created
WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
assertNotNull(form);
assertNotNull(form.getUsername());
assertEquals(userTO.getUsername(), form.getUsername());
assertNotNull(form.getTaskId());
assertNull(form.getOwner());
// 3. claim task as rossini, with role "User manager" granting entitlement to claim forms but not in group 7,
// designated for approval in workflow definition: fail
UserTO rossini = userService.read("1417acbe-cbf6-4277-9372-e75e04f97000");
if (!rossini.getRoles().contains("User manager")) {
UserPatch userPatch = new UserPatch();
userPatch.setKey("1417acbe-cbf6-4277-9372-e75e04f97000");
userPatch.getRoles().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value("User manager").build());
rossini = updateUser(userPatch).getEntity();
}
assertTrue(rossini.getRoles().contains("User manager"));
UserWorkflowService userService2 = clientFactory.create("rossini", ADMIN_PWD).getService(UserWorkflowService.class);
try {
userService2.claimForm(form.getTaskId());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.Workflow, e.getType());
}
// 4. claim task from bellini, with role "User manager" and in group 7
UserWorkflowService userService3 = clientFactory.create("bellini", ADMIN_PWD).getService(UserWorkflowService.class);
form = userService3.claimForm(form.getTaskId());
assertNotNull(form);
assertNotNull(form.getTaskId());
assertNotNull(form.getOwner());
// 5. reject user
form.getProperty("approveCreate").get().setValue(Boolean.FALSE.toString());
form.getProperty("rejectReason").get().setValue("I don't like him.");
userTO = userService3.submitForm(form);
assertNotNull(userTO);
assertEquals("rejected", userTO.getStatus());
// 6. check that rejected user was not propagated to external resource (SYNCOPE-364)
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
Exception exception = null;
try {
jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", new String[] { userTO.getUsername() }, Integer.class);
} catch (EmptyResultDataAccessException e) {
exception = e;
}
assertNotNull(exception);
}
Aggregations