Search in sources :

Example 11 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class UserIssuesITCase method issueSYNCOPE626.

@Test
public void issueSYNCOPE626() {
    DefaultPasswordRuleConf ruleConf = new DefaultPasswordRuleConf();
    ruleConf.setUsernameAllowed(false);
    ImplementationTO rule = new ImplementationTO();
    rule.setKey("DefaultPasswordRuleConf" + getUUIDString());
    rule.setEngine(ImplementationEngine.JAVA);
    rule.setType(ImplementationType.PASSWORD_RULE);
    rule.setBody(POJOHelper.serialize(ruleConf));
    Response response = implementationService.create(rule);
    rule.setKey(response.getHeaderString(RESTHeaders.RESOURCE_KEY));
    PasswordPolicyTO passwordPolicy = new PasswordPolicyTO();
    passwordPolicy.setDescription("Password Policy for SYNCOPE-626");
    passwordPolicy.getRules().add(rule.getKey());
    passwordPolicy = createPolicy(PolicyType.PASSWORD, passwordPolicy);
    assertNotNull(passwordPolicy);
    RealmTO realm = realmService.list("/even/two").get(0);
    String oldPasswordPolicy = realm.getPasswordPolicy();
    realm.setPasswordPolicy(passwordPolicy.getKey());
    realmService.update(realm);
    try {
        UserTO user = UserITCase.getUniqueSampleTO("syncope626@syncope.apache.org");
        user.setRealm(realm.getFullPath());
        user.setPassword(user.getUsername());
        try {
            createUser(user);
            fail("This should not happen");
        } catch (SyncopeClientException e) {
            assertEquals(ClientExceptionType.InvalidUser, e.getType());
            assertTrue(e.getElements().iterator().next().startsWith("InvalidPassword"));
        }
        user.setPassword("password123");
        user = createUser(user).getEntity();
        assertNotNull(user);
    } finally {
        realm.setPasswordPolicy(oldPasswordPolicy);
        realmService.update(realm);
        policyService.delete(PolicyType.PASSWORD, passwordPolicy.getKey());
    }
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) DefaultPasswordRuleConf(org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf) UserTO(org.apache.syncope.common.lib.to.UserTO) RealmTO(org.apache.syncope.common.lib.to.RealmTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PasswordPolicyTO(org.apache.syncope.common.lib.policy.PasswordPolicyTO) Test(org.junit.jupiter.api.Test)

Example 12 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class UserSelfITCase method passwordResetWithoutSecurityQuestion.

@Test
public void passwordResetWithoutSecurityQuestion() {
    // 0. disable security question for password reset
    configurationService.set(attrTO("passwordReset.securityQuestion", "false"));
    // 1. create an user with security question and answer
    UserTO user = UserITCase.getUniqueSampleTO("pwdResetNoSecurityQuestion@syncope.apache.org");
    createUser(user);
    // 2. verify that new user is able to authenticate
    SyncopeClient authClient = clientFactory.create(user.getUsername(), "password123");
    UserTO read = authClient.self().getRight();
    assertNotNull(read);
    // 3. request password reset (as anonymous) with no security answer
    SyncopeClient anonClient = clientFactory.create();
    anonClient.getService(UserSelfService.class).requestPasswordReset(user.getUsername(), null);
    // 4. get token (normally sent via e-mail, now reading as admin)
    String token = userService.read(read.getKey()).getToken();
    assertNotNull(token);
    // 5. confirm password reset
    try {
        anonClient.getService(UserSelfService.class).confirmPasswordReset("WRONG TOKEN", "newPassword");
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
        assertTrue(e.getMessage().contains("WRONG TOKEN"));
    }
    anonClient.getService(UserSelfService.class).confirmPasswordReset(token, "newPassword123");
    // 6. verify that password was reset and token removed
    authClient = clientFactory.create(user.getUsername(), "newPassword123");
    read = authClient.self().getRight();
    assertNotNull(read);
    assertNull(read.getToken());
    // 7. re-enable security question for password reset
    configurationService.set(attrTO("passwordReset.securityQuestion", "true"));
}
Also used : UserSelfService(org.apache.syncope.common.rest.api.service.UserSelfService) UserTO(org.apache.syncope.common.lib.to.UserTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SyncopeClient(org.apache.syncope.client.lib.SyncopeClient) Test(org.junit.jupiter.api.Test)

Example 13 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException 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 14 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException 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 15 with SyncopeClientException

use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.

the class VirAttrITCase method issueSYNCOPE453.

@Test
public void issueSYNCOPE453() {
    String resourceName = "issueSYNCOPE453Res" + getUUIDString();
    String groupKey = null;
    String groupName = "issueSYNCOPE453Group" + getUUIDString();
    try {
        // -------------------------------------------
        // Create a VirAttrITCase ad-hoc
        // -------------------------------------------
        VirSchemaTO rvirtualdata;
        try {
            rvirtualdata = schemaService.read(SchemaType.VIRTUAL, "rvirtualdata");
        } catch (SyncopeClientException e) {
            LOG.warn("rvirtualdata not found, re-creating", e);
            rvirtualdata = new VirSchemaTO();
            rvirtualdata.setKey("rvirtualdata");
            rvirtualdata.setExtAttrName("businessCategory");
            rvirtualdata.setResource(RESOURCE_NAME_LDAP);
            rvirtualdata.setAnyType(AnyTypeKind.GROUP.name());
            rvirtualdata = createSchema(SchemaType.VIRTUAL, rvirtualdata);
        }
        assertNotNull(rvirtualdata);
        if (!"minimal group".equals(rvirtualdata.getAnyTypeClass())) {
            LOG.warn("rvirtualdata not in minimal group, restoring");
            AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
            minimalGroup.getVirSchemas().add(rvirtualdata.getKey());
            anyTypeClassService.update(minimalGroup);
            rvirtualdata = schemaService.read(SchemaType.VIRTUAL, rvirtualdata.getKey());
            assertEquals("minimal group", rvirtualdata.getAnyTypeClass());
        }
        // -------------------------------------------
        // Create a resource ad-hoc
        // -------------------------------------------
        ResourceTO resourceTO = new ResourceTO();
        resourceTO.setKey(resourceName);
        resourceTO.setConnector("be24b061-019d-4e3e-baf0-0a6d0a45cb9c");
        ProvisionTO provisionTO = new ProvisionTO();
        provisionTO.setAnyType(AnyTypeKind.USER.name());
        provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
        resourceTO.getProvisions().add(provisionTO);
        MappingTO mapping = new MappingTO();
        provisionTO.setMapping(mapping);
        ItemTO item = new ItemTO();
        item.setIntAttrName("fullname");
        item.setExtAttrName("ID");
        item.setPurpose(MappingPurpose.PROPAGATION);
        item.setConnObjectKey(true);
        mapping.setConnObjectKeyItem(item);
        item = new ItemTO();
        item.setIntAttrName("username");
        item.setExtAttrName("USERNAME");
        item.setPurpose(MappingPurpose.PROPAGATION);
        mapping.getItems().add(item);
        item = new ItemTO();
        item.setIntAttrName("groups[" + groupName + "].rvirtualdata");
        item.setExtAttrName("EMAIL");
        item.setPurpose(MappingPurpose.PROPAGATION);
        mapping.getItems().add(item);
        assertNotNull(getObject(resourceService.create(resourceTO).getLocation(), ResourceService.class, ResourceTO.class));
        // -------------------------------------------
        GroupTO groupTO = new GroupTO();
        groupTO.setName(groupName);
        groupTO.setRealm("/");
        groupTO.getVirAttrs().add(attrTO(rvirtualdata.getKey(), "ml@group.it"));
        groupTO.getResources().add(RESOURCE_NAME_LDAP);
        groupTO = createGroup(groupTO).getEntity();
        groupKey = groupTO.getKey();
        assertEquals(1, groupTO.getVirAttrs().size());
        assertEquals("ml@group.it", groupTO.getVirAttrs().iterator().next().getValues().get(0));
        // -------------------------------------------
        // -------------------------------------------
        // Create new user
        // -------------------------------------------
        UserTO userTO = UserITCase.getUniqueSampleTO("syn453@syncope.apache.org");
        userTO.getPlainAttrs().add(attrTO("fullname", "123"));
        userTO.getResources().clear();
        userTO.getResources().add(resourceName);
        userTO.getVirAttrs().clear();
        userTO.getMemberships().clear();
        userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
        ProvisioningResult<UserTO> result = createUser(userTO);
        assertEquals(2, result.getPropagationStatuses().size());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(0).getStatus());
        assertEquals(PropagationTaskExecStatus.SUCCESS, result.getPropagationStatuses().get(1).getStatus());
        userTO = result.getEntity();
        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
        Map<String, Object> actuals = jdbcTemplate.queryForMap("SELECT id, surname, email FROM testpull WHERE id=?", new Object[] { userTO.getPlainAttr("fullname").get().getValues().get(0) });
        assertEquals(userTO.getPlainAttr("fullname").get().getValues().get(0), actuals.get("id").toString());
        assertEquals("ml@group.it", actuals.get("email"));
    // -------------------------------------------
    } catch (Exception e) {
        LOG.error("Unexpected error", e);
    } finally {
        // -------------------------------------------
        // Delete resource and group ad-hoc
        // -------------------------------------------
        resourceService.delete(resourceName);
        if (groupKey != null) {
            groupService.delete(groupKey);
        }
    // -------------------------------------------
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) ResourceService(org.apache.syncope.common.rest.api.service.ResourceService) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ItemTO(org.apache.syncope.common.lib.to.ItemTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) GroupTO(org.apache.syncope.common.lib.to.GroupTO) MappingTO(org.apache.syncope.common.lib.to.MappingTO) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) ProvisionTO(org.apache.syncope.common.lib.to.ProvisionTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Aggregations

SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)240 Test (org.junit.jupiter.api.Test)105 UserTO (org.apache.syncope.common.lib.to.UserTO)50 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)40 Response (javax.ws.rs.core.Response)34 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)20 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)19 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)18 Realm (org.apache.syncope.core.persistence.api.entity.Realm)18 GroupTO (org.apache.syncope.common.lib.to.GroupTO)17 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)16 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 Map (java.util.Map)14 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 ItemTO (org.apache.syncope.common.lib.to.ItemTO)12 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)12 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)11