Examples of UserTO


Examples of org.apache.syncope.common.to.UserTO

        throw new NotFoundException("Mandatory attribute " + attrName + " not found");
    }

    @Test
    public void createWithRequiredValueMissing() {
        UserTO userTO = getSampleTO("a.b@c.it");

        AttributeTO type = getManadatoryAttrByName(userTO.getAttributes(), "type");
        userTO.removeAttribute(type);

        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(8L);
        userTO.addMembership(membershipTO);

        SyncopeClientCompositeErrorException ex = null;
        try {
            // 1. create user without type (mandatory by UserSchema)
            createUser(userTO);
        } catch (SyncopeClientCompositeErrorException e) {
            ex = e;
        }
        assertNotNull(ex);
        assertNotNull(ex.getException(SyncopeClientExceptionType.RequiredValuesMissing));

        userTO.addAttribute(attributeTO("type", "F"));

        AttributeTO surname = getManadatoryAttrByName(userTO.getAttributes(), "surname");
        userTO.removeAttribute(surname);

        // 2. create user without surname (mandatory when type == 'F')
        ex = null;
        try {
            createUser(userTO);
View Full Code Here

Examples of org.apache.syncope.common.to.UserTO

    @Test
    public void createWithReject() {
        Assume.assumeTrue(ActivitiDetector.isActivitiEnabledForUsers());

        UserTO userTO = getUniqueSampleTO("createWithReject@syncope.apache.org");

        // User with role 9 are defined in workflow as subject to approval
        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(9L);
        userTO.addMembership(membershipTO);

        // 1. create user with role 9
        userTO = createUser(userTO);
        assertNotNull(userTO);
        assertEquals(1, userTO.getMemberships().size());
        assertEquals(9, userTO.getMemberships().get(0).getRoleId());
        assertEquals("createApproval", userTO.getStatus());

        // 2. request if there is any pending task for user just created
        WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getId());

        assertNotNull(form);
        assertNotNull(form.getUserId());
        assertEquals(userTO.getId(), form.getUserId());
        assertNotNull(form.getTaskId());
        assertNull(form.getOwner());

        // 3. claim task from rossini, not in role 7 (designated for approval in workflow definition): fail
        UserWorkflowService userService2 =
                setupCredentials(userWorkflowService, UserWorkflowService.class, "rossini", ADMIN_PWD);

        try {
            userService2.claimForm(form.getTaskId());
            fail();
        } catch (SyncopeClientCompositeErrorException scce) {
            assertNotNull(scce.getException(SyncopeClientExceptionType.Workflow));
        }

        // 4. claim task from bellini, in role 7
        UserWorkflowService userService3 =
                setupCredentials(userWorkflowService, UserWorkflowService.class, "bellini", ADMIN_PWD);

        form = userService3.claimForm(form.getTaskId());
        assertNotNull(form);
        assertNotNull(form.getTaskId());
        assertNotNull(form.getOwner());

        // 5. reject user
        Map<String, WorkflowFormPropertyTO> props = form.getPropertyMap();
        props.get("approve").setValue(Boolean.FALSE.toString());
        props.get("rejectReason").setValue("I don't like him.");
        form.setProperties(props.values());
        userTO = userService3.submitForm(form);
        assertNotNull(userTO);
        assertEquals("rejected", userTO.getStatus());

        // reset admin credentials for restTemplate
        super.resetRestTemplate();
    }
View Full Code Here

Examples of org.apache.syncope.common.to.UserTO

    public void createWithApproval() {
        Assume.assumeTrue(ActivitiDetector.isActivitiEnabledForUsers());

        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);

        UserTO userTO = getUniqueSampleTO("createWithApproval@syncope.apache.org");
        userTO.addResource(RESOURCE_NAME_TESTDB);

        // User with role 9 are defined in workflow as subject to approval
        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(9L);
        userTO.addMembership(membershipTO);

        // 1. create user with role 9 (and verify that no propagation occurred)
        userTO = createUser(userTO);
        assertNotNull(userTO);
        assertEquals(1, userTO.getMemberships().size());
        assertEquals(9, userTO.getMemberships().get(0).getRoleId());
        assertEquals("createApproval", userTO.getStatus());
        assertEquals(Collections.singleton(RESOURCE_NAME_TESTDB), userTO.getResources());

        assertTrue(userTO.getPropagationStatusTOs().isEmpty());

        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
        List<WorkflowFormTO> forms = userWorkflowService.getForms();
        assertNotNull(forms);
        assertEquals(1, forms.size());

        WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getId());
        assertNotNull(form);
        assertNotNull(form.getTaskId());
        assertNull(form.getOwner());

        // 4. claim task (from admin)
        form = userWorkflowService.claimForm(form.getTaskId());
        assertNotNull(form);
        assertNotNull(form.getTaskId());
        assertNotNull(form.getOwner());

        // 5. approve user (and verify that propagation occurred)
        Map<String, WorkflowFormPropertyTO> props = form.getPropertyMap();
        props.get("approve").setValue(Boolean.TRUE.toString());
        form.setProperties(props.values());
        userTO = userWorkflowService.submitForm(form);
        assertNotNull(userTO);
        assertEquals("active", userTO.getStatus());
        assertEquals(Collections.singleton(RESOURCE_NAME_TESTDB), userTO.getResources());

        exception = null;
        try {
            final String username = jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", String.class,
                    userTO.getUsername());
            assertEquals(userTO.getUsername(), username);
        } catch (EmptyResultDataAccessException e) {
            exception = e;
        }
        assertNull(exception);

        // 6. update user
        UserMod userMod = new UserMod();
        userMod.setId(userTO.getId());
        userMod.setPassword("anotherPassword123");

        userTO = userService.update(userMod.getId(), userMod);
        assertNotNull(userTO);
    }
View Full Code Here

Examples of org.apache.syncope.common.to.UserTO

            userService.delete(0L);
        } catch (HttpStatusCodeException e) {
            assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
        }

        UserTO userTO = getSampleTO("qqgf.z@nn.com");

        // specify a propagation
        userTO.addResource(RESOURCE_NAME_TESTDB);

        userTO = createUser(userTO);

        long id = userTO.getId();

        userTO = userService.delete(id);

        assertNotNull(userTO);
        assertEquals(id, userTO.getId());
        assertTrue(userTO.getAttributes().isEmpty());

        // check for propagation result
        assertFalse(userTO.getPropagationStatusTOs().isEmpty());
        assertTrue(userTO.getPropagationStatusTOs().get(0).getStatus().isSuccessful());

        try {
            userService.delete(userTO.getId());
        } catch (HttpStatusCodeException e) {
            assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
        }
    }
View Full Code Here

Examples of org.apache.syncope.common.to.UserTO

        }
    }

    @Test
    public void deleteByUsername() {
        UserTO userTO = getSampleTO("delete.by.username@apache.org");

        // specify a propagation
        userTO.addResource(RESOURCE_NAME_TESTDB);

        userTO = createUser(userTO);

        long id = userTO.getId();
        userTO = userService.read(id);
        userTO = userService.delete(userTO.getId());

        assertNotNull(userTO);
        assertEquals(id, userTO.getId());
        assertTrue(userTO.getAttributes().isEmpty());

        // check for propagation result
        assertFalse(userTO.getPropagationStatusTOs().isEmpty());
        assertTrue(userTO.getPropagationStatusTOs().get(0).getStatus().isSuccessful());

        try {
            userService.read(userTO.getId());
        } catch (HttpStatusCodeException e) {
            assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
        }
    }
View Full Code Here

Examples of org.apache.syncope.common.to.UserTO

        response = createSchema(AttributableType.USER, SchemaType.NORMAL, schemaTO);
        SchemaTO newSchemaTO = getObject(response, SchemaTO.class, entitlementService);
        assertEquals(schemaTO, newSchemaTO);

        // 2. create an user with the role created above (as admin)
        UserTO userTO = UserTestITCase.getUniqueSampleTO("auth@test.org");

        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(authRoleTO.getId());
        AttributeTO testAttributeTO = new AttributeTO();
        testAttributeTO.setSchema("testAttribute");
        testAttributeTO.addValue("a value");
        membershipTO.addAttribute(testAttributeTO);
        userTO.addMembership(membershipTO);

        userTO = createUser(userTO);
        assertNotNull(userTO);

        // 3. read the schema created above (as admin) - success
        schemaTO = schemaService.read(AttributableType.USER, SchemaType.NORMAL, schemaName);
        assertNotNull(schemaTO);

        // 4. read the schema created above (as user) - success
        SchemaService schemaService2 = setupCredentials(schemaService, SchemaService.class,
                userTO.getUsername(), "password123");

        schemaTO = schemaService2.read(AttributableType.USER, SchemaType.NORMAL, schemaName);
        assertNotNull(schemaTO);

        // 5. update the schema create above (as user) - failure
        try {
            schemaService2.update(AttributableType.ROLE, SchemaType.NORMAL, schemaName, schemaTO);
            fail("Schemaupdate as user schould not work");
        } catch (HttpClientErrorException e) {
            assertNotNull(e);
            assertEquals(HttpStatus.FORBIDDEN, e.getStatusCode());
        } catch (AccessControlException e) {
            // CXF Service will throw this exception
            assertNotNull(e);
        }

        // reset admin credentials for restTemplate
        super.resetRestTemplate();
        assertEquals(0, getFailedLogins(userService, userTO.getId()));
    }
View Full Code Here

Examples of org.apache.syncope.common.to.UserTO

        assertEquals(0, getFailedLogins(userService, userTO.getId()));
    }

    @Test
    public void testUserRead() {
        UserTO userTO = UserTestITCase.getUniqueSampleTO("testuserread@test.org");

        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(7L);
        AttributeTO testAttributeTO = new AttributeTO();
        testAttributeTO.setSchema("testAttribute");
        testAttributeTO.addValue("a value");
        membershipTO.addAttribute(testAttributeTO);
        userTO.addMembership(membershipTO);

        userTO = createUser(userTO);
        assertNotNull(userTO);

        UserService userService2 = setupCredentials(userService, UserService.class,
                userTO.getUsername(), "password123");

        UserTO readUserTO = userService2.read(1L);
        assertNotNull(readUserTO);

        UserService userService3 = setupCredentials(userService, UserService.class, "verdi", ADMIN_PWD);

        SyncopeClientException exception = null;
View Full Code Here

Examples of org.apache.syncope.common.to.UserTO

        super.resetRestTemplate();
    }

    @Test
    public void testUserSearch() throws InvalidSearchConditionException {
        UserTO userTO = UserTestITCase.getUniqueSampleTO("testusersearch@test.org");

        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(7L);
        AttributeTO testAttributeTO = new AttributeTO();
        testAttributeTO.setSchema("testAttribute");
        testAttributeTO.addValue("a value");
        membershipTO.addAttribute(testAttributeTO);
        userTO.addMembership(membershipTO);

        userTO = createUser(userTO);
        assertNotNull(userTO);

        UserService userService2 = setupCredentials(userService, UserService.class,
                userTO.getUsername(), "password123");

        AttributeCond isNullCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
        isNullCond.setSchema("loginDate");
        NodeCond searchCondition = NodeCond.getLeafCond(isNullCond);
View Full Code Here

Examples of org.apache.syncope.common.to.UserTO

    @Test
    public void checkFailedLogins() {
        // Workaround for CXF issue.. remove after upgrade to 2.7.3
        CXFAuthenticator.addAuthenticator();
        Authenticator.setDefault(new CXFPatchedAuthenticator());
        UserTO userTO = UserTestITCase.getUniqueSampleTO("checkFailedLogin@syncope.apache.org");

        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(7L);
        AttributeTO testAttributeTO = new AttributeTO();
        testAttributeTO.setSchema("testAttribute");
        testAttributeTO.addValue("a value");
        membershipTO.addAttribute(testAttributeTO);
        userTO.addMembership(membershipTO);

        userTO = createUser(userTO);
        assertNotNull(userTO);
        long userId = userTO.getId();

        UserService userService2 = setupCredentials(userService, UserService.class,
                userTO.getUsername(), "password123");
        assertEquals(0, getFailedLogins(userService2, userId));

        // authentications failed ...
        UserService userService3 = setupCredentials(userService, UserService.class,
                userTO.getUsername(), "wrongpwd1");
        assertReadFails(userService3, userId);
        assertReadFails(userService3, userId);

        // reset admin credentials for restTemplate
        super.resetRestTemplate();
        assertEquals(2, getFailedLogins(userService, userId));

        UserService userService4 = setupCredentials(userService, UserService.class,
                userTO.getUsername(), "password123");
        assertEquals(0, getFailedLogins(userService4, userId));
    }
View Full Code Here

Examples of org.apache.syncope.common.to.UserTO

        assertEquals(0, getFailedLogins(userService4, userId));
    }

    @Test
    public void checkUserSuspension() {
        UserTO userTO = UserTestITCase.getUniqueSampleTO("checkSuspension@syncope.apache.org");

        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(7L);
        AttributeTO testAttributeTO = new AttributeTO();
        testAttributeTO.setSchema("testAttribute");
        testAttributeTO.addValue("a value");
        membershipTO.addAttribute(testAttributeTO);
        userTO.addMembership(membershipTO);

        userTO = createUser(userTO);
        long userId = userTO.getId();
        assertNotNull(userTO);

        UserService userService2 = setupCredentials(userService, UserService.class,
                userTO.getUsername(), "password123");
        assertEquals(0, getFailedLogins(userService2, userId));

        // authentications failed ...
        UserService userService3 = setupCredentials(userService, UserService.class,
                userTO.getUsername(), "wrongpwd1");
        assertReadFails(userService3, userId);
        assertReadFails(userService3, userId);
        assertReadFails(userService3, userId);

        // reset admin credentials for restTemplate
        super.resetRestTemplate();
        assertEquals(3, getFailedLogins(userService, userId));

        // last authentication before suspension
        // TODO remove after CXF migration is complete
        userService3 = setupCredentials(userService, UserService.class, userTO.getUsername(), "wrongpwd1");
        assertReadFails(userService3, userId);

        // reset admin credentials for restTemplate
        super.resetRestTemplate();

        userTO = userService.read(userTO.getId());

        assertNotNull(userTO);
        assertNotNull(userTO.getFailedLogins());
        assertEquals(Integer.valueOf(3), userTO.getFailedLogins());
        assertEquals("suspended", userTO.getStatus());

        // Access with correct credentials should fail as user is suspended
        // TODO remove after CXF migration is complete
        userService2 = setupCredentials(userService, UserService.class, userTO.getUsername(), "password123");
        assertReadFails(userService2, userId);

        // reset admin credentials for restTemplate
        super.resetRestTemplate();
        userTO = userService.reactivate(userTO.getId());
        assertNotNull(userTO);
        assertEquals("active", userTO.getStatus());

        // TODO remove after CXF migration is complete
        userService2 = setupCredentials(userService, UserService.class, userTO.getUsername(), "password123");
        assertEquals(0, getFailedLogins(userService2, userId));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.