Search in sources :

Example 1 with UserWorkflowService

use of org.apache.syncope.common.rest.api.service.UserWorkflowService 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);
}
Also used : UserWorkflowService(org.apache.syncope.common.rest.api.service.UserWorkflowService) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Test(org.junit.jupiter.api.Test)

Example 2 with UserWorkflowService

use of org.apache.syncope.common.rest.api.service.UserWorkflowService in project syncope by apache.

the class UserWorkflowITCase method issueSYNCOPE15.

@Test
public void issueSYNCOPE15() {
    assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
    // read forms *before* any operation
    List<WorkflowFormTO> forms = userWorkflowService.getForms();
    assertNotNull(forms);
    int preForms = forms.size();
    UserTO userTO = UserITCase.getUniqueSampleTO("issueSYNCOPE15@syncope.apache.org");
    userTO.getResources().clear();
    userTO.getVirAttrs().clear();
    userTO.getDerAttrs().clear();
    userTO.getMemberships().clear();
    // Users 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 with group 9 (and verify that no propagation occurred)
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertNotEquals(0L, userTO.getKey());
    assertNotNull(userTO.getCreationDate());
    assertNotNull(userTO.getCreator());
    assertNotNull(userTO.getLastChangeDate());
    assertNotNull(userTO.getLastModifier());
    assertEquals(userTO.getCreationDate(), userTO.getLastChangeDate());
    // 2. request if there is any pending form for user just created
    forms = userWorkflowService.getForms();
    assertEquals(preForms + 1, forms.size());
    WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
    assertNotNull(form);
    // 3. first claim by bellini ....
    UserWorkflowService userService3 = clientFactory.create("bellini", ADMIN_PWD).getService(UserWorkflowService.class);
    form = userService3.claimForm(form.getTaskId());
    assertNotNull(form);
    assertNotNull(form.getTaskId());
    assertNotNull(form.getOwner());
    // 4. second claim task by admin
    form = userWorkflowService.claimForm(form.getTaskId());
    assertNotNull(form);
    // 5. approve user
    form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
    // 6. submit approve
    userTO = userWorkflowService.submitForm(form);
    assertNotNull(userTO);
    assertEquals(preForms, userWorkflowService.getForms().size());
    assertNull(userWorkflowService.getFormForUser(userTO.getKey()));
    // 7.check that no more forms are still to be processed
    forms = userWorkflowService.getForms();
    assertEquals(preForms, forms.size());
}
Also used : UserWorkflowService(org.apache.syncope.common.rest.api.service.UserWorkflowService) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Test(org.junit.jupiter.api.Test)

Aggregations

MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)2 UserTO (org.apache.syncope.common.lib.to.UserTO)2 WorkflowFormTO (org.apache.syncope.common.lib.to.WorkflowFormTO)2 UserWorkflowService (org.apache.syncope.common.rest.api.service.UserWorkflowService)2 Test (org.junit.jupiter.api.Test)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1