use of org.apache.syncope.common.lib.to.WorkflowFormTO 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.to.WorkflowFormTO 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.to.WorkflowFormTO 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);
}
use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.
the class UserWorkflowITCase method updateApproval.
@Test
public void updateApproval() {
assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
// read forms *before* any operation
List<WorkflowFormTO> forms = userWorkflowService.getForms();
assertNotNull(forms);
int preForms = forms.size();
UserTO created = createUser(UserITCase.getUniqueSampleTO("updateApproval@syncope.apache.org")).getEntity();
assertNotNull(created);
assertEquals("/", created.getRealm());
assertEquals(0, created.getMemberships().size());
UserPatch patch = new UserPatch();
patch.setKey(created.getKey());
patch.getMemberships().add(new MembershipPatch.Builder().group("b1f7c12d-ec83-441f-a50e-1691daaedf3b").build());
SyncopeClient client = clientFactory.create(created.getUsername(), "password123");
Response response = client.getService(UserSelfService.class).update(patch);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals("updateApproval", userService.read(created.getKey()).getStatus());
forms = userWorkflowService.getForms();
assertNotNull(forms);
assertEquals(preForms + 1, forms.size());
WorkflowFormTO form = userWorkflowService.getFormForUser(created.getKey());
assertNotNull(form);
assertNotNull(form.getTaskId());
assertNull(form.getOwner());
assertNotNull(form.getUserTO());
assertNotNull(form.getUserPatch());
assertEquals(patch, form.getUserPatch());
// as admin, request for more changes: still pending approval
patch.setRealm(new StringReplacePatchItem.Builder().value("/even/two").build());
response = userService.update(patch);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals("updateApproval", userService.read(created.getKey()).getStatus());
// the patch is updated in the approval form
form = userWorkflowService.getFormForUser(created.getKey());
assertEquals(patch, form.getUserPatch());
// approve the user
form = userWorkflowService.claimForm(form.getTaskId());
form.getProperty("approveUpdate").get().setValue(Boolean.TRUE.toString());
userWorkflowService.submitForm(form);
// verify that the approved user bears both original and further changes
UserTO approved = userService.read(created.getKey());
assertNotNull(approved);
assertEquals("/even/two", approved.getRealm());
assertEquals(1, approved.getMemberships().size());
assertNotNull(approved.getMembership("b1f7c12d-ec83-441f-a50e-1691daaedf3b").get());
}
use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.
the class ApprovalDirectoryPanel method getActions.
@Override
public ActionsPanel<WorkflowFormTO> getActions(final IModel<WorkflowFormTO> model) {
final ActionsPanel<WorkflowFormTO> panel = super.getActions(model);
panel.add(new ActionLink<WorkflowFormTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
claimForm(model.getObject().getTaskId());
SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
target.add(container);
}
}, ActionLink.ActionType.CLAIM, StandardEntitlement.WORKFLOW_FORM_CLAIM);
panel.add(new ActionLink<WorkflowFormTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
manageApprovalModal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
target.add(manageApprovalModal.setContent(new ApprovalModal(manageApprovalModal, pageRef, model.getObject()) {
private static final long serialVersionUID = 5546519445061007248L;
@Override
public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
try {
super.onSubmit(target, form);
ApprovalDirectoryPanel.this.getTogglePanel().close(target);
} catch (SyncopeClientException e) {
SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage());
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
}));
manageApprovalModal.header(new Model<>(getString("approval.manage", new Model<>(model.getObject()))));
manageApprovalModal.show(true);
}
@Override
protected boolean statusCondition(final WorkflowFormTO modelObject) {
return SyncopeConsoleSession.get().getSelfTO().getUsername().equals(model.getObject().getOwner());
}
}, ActionLink.ActionType.MANAGE_APPROVAL, StandardEntitlement.WORKFLOW_FORM_READ);
// SYNCOPE-1200 edit user while in approval state
panel.add(new ActionLink<WorkflowFormTO>() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target, final WorkflowFormTO ignore) {
modal.setFormModel(new CompoundPropertyModel<>(model.getObject()));
WorkflowFormTO formTO = model.getObject();
UserTO newUserTO;
UserTO previousUserTO;
if (formTO.getUserPatch() == null) {
newUserTO = formTO.getUserTO();
previousUserTO = null;
} else if (formTO.getUserTO() == null) {
// make it stronger by handling possible NPE
previousUserTO = new UserTO();
previousUserTO.setKey(formTO.getUserPatch().getKey());
newUserTO = AnyOperations.patch(previousUserTO, formTO.getUserPatch());
} else {
previousUserTO = formTO.getUserTO();
formTO.getUserTO().setKey(formTO.getUserPatch().getKey());
formTO.getUserTO().setPassword(null);
newUserTO = AnyOperations.patch(formTO.getUserTO(), formTO.getUserPatch());
}
AjaxWizard.EditItemActionEvent<UserTO> editItemActionEvent = new AjaxWizard.EditItemActionEvent<>(newUserTO, target);
editItemActionEvent.forceModalPanel(new ApprovalUserWizardBuilder(model.getObject(), previousUserTO, newUserTO, new AnyTypeRestClient().read(AnyTypeKind.USER.name()).getClasses(), FormLayoutInfoUtils.fetch(Collections.singletonList(AnyTypeKind.USER.name())).getLeft(), pageRef).build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT));
send(ApprovalDirectoryPanel.this, Broadcast.EXACT, editItemActionEvent);
}
@Override
protected boolean statusCondition(final WorkflowFormTO modelObject) {
return SyncopeConsoleSession.get().getSelfTO().getUsername().equals(model.getObject().getOwner());
}
}, ActionLink.ActionType.EDIT_APPROVAL, StandardEntitlement.WORKFLOW_FORM_SUBMIT);
return panel;
}
Aggregations