Search in sources :

Example 21 with UserPatch

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());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 22 with UserPatch

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());
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) BooleanReplacePatchItem(org.apache.syncope.common.lib.patch.BooleanReplacePatchItem) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) UserTO(org.apache.syncope.common.lib.to.UserTO) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 23 with UserPatch

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()));
}
Also used : GenericType(javax.ws.rs.core.GenericType) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Test(org.junit.jupiter.api.Test)

Example 24 with UserPatch

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

Example 25 with UserPatch

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);
}
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)

Aggregations

UserPatch (org.apache.syncope.common.lib.patch.UserPatch)102 UserTO (org.apache.syncope.common.lib.to.UserTO)73 Test (org.junit.jupiter.api.Test)59 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)37 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)18 AttrTO (org.apache.syncope.common.lib.to.AttrTO)17 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 Response (javax.ws.rs.core.Response)16 Map (java.util.Map)12 StringReplacePatchItem (org.apache.syncope.common.lib.patch.StringReplacePatchItem)12 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)11 GroupTO (org.apache.syncope.common.lib.to.GroupTO)11 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)11 WorkflowResult (org.apache.syncope.core.provisioning.api.WorkflowResult)11 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)11 GenericType (javax.ws.rs.core.GenericType)10 Pair (org.apache.commons.lang3.tuple.Pair)10 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)10 List (java.util.List)9 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)9