Search in sources :

Example 11 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.

the class AuthenticationITCase method issueSYNCOPE434.

@Test
public void issueSYNCOPE434() {
    assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
    // 1. create user with group 'groupForWorkflowApproval'
    // (users with group groupForWorkflowApproval are defined in workflow as subject to approval)
    UserTO userTO = UserITCase.getUniqueSampleTO("createWithReject@syncope.apache.org");
    userTO.getMemberships().add(new MembershipTO.Builder().group("0cbcabd2-4410-4b6b-8f05-a052b451d18f").build());
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    assertEquals("createApproval", userTO.getStatus());
    // 2. try to authenticate: fail
    try {
        clientFactory.create(userTO.getUsername(), "password123").self();
        fail("This should not happen");
    } catch (AccessControlException e) {
        assertNotNull(e);
    }
    // 3. approve user
    WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
    form = userWorkflowService.claimForm(form.getTaskId());
    form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
    userTO = userWorkflowService.submitForm(form);
    assertNotNull(userTO);
    assertEquals("active", userTO.getStatus());
    // 4. try to authenticate again: success
    Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(userTO.getUsername(), "password123").self();
    assertNotNull(self);
    assertNotNull(self.getLeft());
    assertNotNull(self.getRight());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AccessControlException(java.security.AccessControlException) Map(java.util.Map) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Test(org.junit.jupiter.api.Test)

Example 12 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.

the class IdentityRecertificationITCase method recertification.

@Test
public void recertification() {
    execTask(taskService, TaskType.SCHEDULED, "e95555d2-1b09-42c8-b25b-f4c4ec598989", "JOB_FIRED", 50, false);
    List<WorkflowFormTO> forms = userWorkflowService.getForms();
    assertFalse(forms.isEmpty());
    for (WorkflowFormTO form : forms) {
        userWorkflowService.claimForm(form.getTaskId());
        WorkflowFormPropertyTO approve = form.getProperty("approve").get();
        approve.setValue("true");
        userWorkflowService.submitForm(form);
    }
    forms = userWorkflowService.getForms();
    assertTrue(forms.isEmpty());
}
Also used : WorkflowFormPropertyTO(org.apache.syncope.common.lib.to.WorkflowFormPropertyTO) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Test(org.junit.jupiter.api.Test)

Example 13 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.

the class UserSelfITCase method createAndApprove.

@Test
public void createAndApprove() {
    assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
    // self-create user with membership: goes 'createApproval' with resources and membership but no propagation
    UserTO userTO = UserITCase.getUniqueSampleTO("anonymous@syncope.apache.org");
    userTO.getMemberships().add(new MembershipTO.Builder().group("29f96485-729e-4d31-88a1-6fc60e4677f3").build());
    userTO.getResources().add(RESOURCE_NAME_TESTDB);
    SyncopeClient anonClient = clientFactory.create();
    userTO = anonClient.getService(UserSelfService.class).create(userTO, true).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
    }).getEntity();
    assertNotNull(userTO);
    assertEquals("createApproval", userTO.getStatus());
    assertFalse(userTO.getMemberships().isEmpty());
    assertFalse(userTO.getResources().isEmpty());
    try {
        resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userTO.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    // now approve and verify that propagation has happened
    WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
    form = userWorkflowService.claimForm(form.getTaskId());
    form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
    userTO = userWorkflowService.submitForm(form);
    assertNotNull(userTO);
    assertEquals("active", userTO.getStatus());
    assertNotNull(resourceService.readConnObject(RESOURCE_NAME_TESTDB, AnyTypeKind.USER.name(), userTO.getKey()));
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Test(org.junit.jupiter.api.Test)

Example 14 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO 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)

Example 15 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.

the class FlowableUserWorkflowAdapter method getForms.

@Transactional(readOnly = true)
@Override
public List<WorkflowFormTO> getForms() {
    List<WorkflowFormTO> forms = new ArrayList<>();
    String authUser = AuthContextUtils.getUsername();
    if (adminUser.equals(authUser)) {
        forms.addAll(getForms(engine.getTaskService().createTaskQuery().taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE)));
    } else {
        User user = userDAO.findByUsername(authUser);
        if (user == null) {
            throw new NotFoundException("Syncope User " + authUser);
        }
        forms.addAll(getForms(engine.getTaskService().createTaskQuery().taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).taskCandidateOrAssigned(user.getKey())));
        List<String> candidateGroups = new ArrayList<>();
        userDAO.findAllGroupNames(user).forEach(group -> {
            candidateGroups.add(group);
        });
        if (!candidateGroups.isEmpty()) {
            forms.addAll(getForms(engine.getTaskService().createTaskQuery().taskVariableValueEquals(TASK_IS_FORM, Boolean.TRUE).taskCandidateGroupIn(candidateGroups)));
        }
    }
    return forms;
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) ArrayList(java.util.ArrayList) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

WorkflowFormTO (org.apache.syncope.common.lib.to.WorkflowFormTO)16 UserTO (org.apache.syncope.common.lib.to.UserTO)11 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 Test (org.junit.jupiter.api.Test)8 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)7 ArrayList (java.util.ArrayList)5 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)5 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)5 Map (java.util.Map)4 WorkflowFormPropertyTO (org.apache.syncope.common.lib.to.WorkflowFormPropertyTO)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)4 FlowableException (org.flowable.engine.common.api.FlowableException)4 Task (org.flowable.task.api.Task)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 Collections (java.util.Collections)3