Package org.apache.syncope.client.to

Examples of org.apache.syncope.client.to.RoleTO


        // attributes, derived attributes, virtual attributes and resources
        return fill(role, roleMod, AttributableUtil.getInstance(AttributableType.ROLE), scce);
    }

    public RoleTO getRoleTO(SyncopeRole role) {
        RoleTO roleTO = new RoleTO();
        roleTO.setId(role.getId());
        roleTO.setName(role.getName());
        roleTO.setInheritAttributes(role.isInheritAttributes());
        roleTO.setInheritDerivedAttributes(role.isInheritDerivedAttributes());
        roleTO.setInheritVirtualAttributes(role.isInheritVirtualAttributes());
        roleTO.setInheritPasswordPolicy(role.isInheritPasswordPolicy());
        roleTO.setInheritAccountPolicy(role.isInheritAccountPolicy());

        if (role.getParent() != null) {
            roleTO.setParent(role.getParent().getId());
        }

        // -------------------------
        // Retrieve all [derived/virtual] attributes (inherited and not)
        // -------------------------
        final List<RAttr> allAttributes = role.findInheritedAttributes();
        allAttributes.addAll((List<RAttr>) role.getAttributes());

        final List<RDerAttr> allDerAttributes = role.findInheritedDerivedAttributes();
        allDerAttributes.addAll((List<RDerAttr>) role.getDerivedAttributes());

        final List<RVirAttr> allVirAttributes = role.findInheritedVirtualAttributes();
        allVirAttributes.addAll((List<RVirAttr>) role.getVirtualAttributes());
        // -------------------------

        fillTO(roleTO, allAttributes, allDerAttributes, allVirAttributes, role.getResources());

        for (Entitlement entitlement : role.getEntitlements()) {
            roleTO.addEntitlement(entitlement.getName());
        }

        roleTO.setPasswordPolicy(role.getPasswordPolicy() != null
                ? role.getPasswordPolicy().getId()
                : null);

        roleTO.setAccountPolicy(role.getAccountPolicy() != null
                ? role.getAccountPolicy().getId()
                : null);

        return roleTO;
    }
View Full Code Here


    }

    @Test
    public void testUserSchemaAuthorization() {
        // 0. create a role that can only read schemas
        RoleTO authRoleTO = new RoleTO();
        authRoleTO.setName("authRole");
        authRoleTO.setParent(8L);
        authRoleTO.addEntitlement("SCHEMA_READ");

        authRoleTO = restTemplate.postForObject(BASE_URL + "role/create", authRoleTO, RoleTO.class);
        assertNotNull(authRoleTO);

        // 1. create a schema (as admin)
        SchemaTO schemaTO = new SchemaTO();
        schemaTO.setName("authTestSchema");
        schemaTO.setMandatoryCondition("false");
        schemaTO.setType(SchemaType.String);

        SchemaTO newSchemaTO = restTemplate.postForObject(BASE_URL + "schema/user/create", schemaTO, SchemaTO.class);
        assertEquals(schemaTO, newSchemaTO);

        // 2. create an user with the role created above (as admin)
        UserTO userTO = UserTestITCase.getSampleTO("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);
View Full Code Here

    }

    @Test
    public void issueSYNCOPE48() {
        // Parent role, able to create users with role 1
        RoleTO parentRole = new RoleTO();
        parentRole.setName("parentAdminRole");
        parentRole.addEntitlement("USER_CREATE");
        parentRole.addEntitlement("ROLE_1");
        parentRole.setParent(1L);

        parentRole = restTemplate.postForObject(BASE_URL + "role/create", parentRole, RoleTO.class);
        assertNotNull(parentRole);

        // Child role, with no entitlements
        RoleTO childRole = new RoleTO();
        childRole.setName("childAdminRole");
        childRole.setParent(parentRole.getId());

        childRole = restTemplate.postForObject(BASE_URL + "role/create", childRole, RoleTO.class);
        assertNotNull(childRole);

        // User with child role, created by admin
        UserTO role1Admin = UserTestITCase.getSampleTO("syncope48admin@apache.org");
        role1Admin.setPassword("password");
        MembershipTO membershipTO = new MembershipTO();
        membershipTO.setRoleId(childRole.getId());
        role1Admin.addMembership(membershipTO);

        role1Admin = restTemplate.postForObject(BASE_URL + "user/create", role1Admin, UserTO.class);
        assertNotNull(role1Admin);
View Full Code Here

        SyncopeRole role = roleDAO.find(roleId);
        if (role == null) {
            throw new NotFoundException("Role " + roleId);
        }
       
        RoleTO roleToDelete = roleDataBinder.getRoleTO(role);

        Set<Long> allowedRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
        if (!allowedRoleIds.contains(role.getId())) {
            throw new UnauthorizedRoleException(role.getId());
        }
View Full Code Here

        Set<Long> allowedRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
        if (role.getParent() != null && !allowedRoleIds.contains(role.getParent().getId())) {
            throw new UnauthorizedRoleException(role.getParent().getId());
        }

        RoleTO result = role.getParent() == null
                ? null
                : roleDataBinder.getRoleTO(role.getParent());

        auditManager.audit(Category.role, RoleSubCategory.parent, Result.success,
                result == null
                ? "Role " + role.getId() + " is a root role"
                : "Found parent for role " + role.getId() + ": " + result.getId());

        return result;
    }
View Full Code Here

    public void createWithException() {
        AttributeTO attributeTO = new AttributeTO();
        attributeTO.setSchema("attr1");
        attributeTO.addValue("value1");

        RoleTO newRoleTO = new RoleTO();
        newRoleTO.addAttribute(attributeTO);

        Throwable t = null;
        try {
            restTemplate.postForObject(BASE_URL + "role/create", newRoleTO, RoleTO.class);
            fail();
View Full Code Here

        assertNotNull(t);
    }

    @Test
    public void create() {
        RoleTO roleTO = new RoleTO();
        roleTO.setName("lastRole");
        roleTO.setParent(8L);

        // verify inheritance password and account policies
        roleTO.setInheritAccountPolicy(false);
        // not inherited so setter execution shouldn't be ignored
        roleTO.setAccountPolicy(6L);

        roleTO.setInheritPasswordPolicy(true);
        // inherited so setter execution should be ignored
        roleTO.setPasswordPolicy(2L);

        AttributeTO icon = new AttributeTO();
        icon.setSchema("icon");
        icon.addValue("anIcon");

        RoleTO actual = restTemplate.postForObject(BASE_URL + "role/create", roleTO, RoleTO.class);

        roleTO.setId(actual.getId());

        roleTO.setPasswordPolicy(4L);

        assertEquals(roleTO, actual);

        assertNotNull(actual.getAccountPolicy());
        assertEquals(6L, (long) actual.getAccountPolicy());

        assertNotNull(actual.getPasswordPolicy());
        assertEquals(4L, (long) actual.getPasswordPolicy());
    }
View Full Code Here

        assertEquals(4L, (long) actual.getPasswordPolicy());
    }

    @Test
    public void createWithPasswordPolicy() {
        RoleTO roleTO = new RoleTO();
        roleTO.setName("roleWithPassword");
        roleTO.setParent(8L);
        roleTO.setPasswordPolicy(4L);

        RoleTO actual = restTemplate.postForObject(BASE_URL + "role/create", roleTO, RoleTO.class);

        assertNotNull(actual);

        actual = restTemplate.getForObject(BASE_URL + "role/read/{roleId}.json", RoleTO.class, actual.getId());

        assertNotNull(actual);
        assertNotNull(actual.getPasswordPolicy());
        assertEquals(4L, (long) actual.getPasswordPolicy());
    }
View Full Code Here

            restTemplate.getForObject(BASE_URL + "role/delete/{roleId}", RoleTO.class, 0);
        } catch (HttpStatusCodeException e) {
            assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
        }

        RoleTO deletedRole = restTemplate.getForObject(BASE_URL + "role/delete/{roleId}", RoleTO.class, 5);
        assertNotNull(deletedRole);
        try {
            restTemplate.getForObject(BASE_URL + "role/read/{roleId}.json", RoleTO.class, 2);
        } catch (HttpStatusCodeException e) {
            assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
View Full Code Here

        }
    }

    @Test
    public void parent() {
        RoleTO roleTO = restTemplate.getForObject(BASE_URL + "role/parent/{roleId}.json", RoleTO.class, 7);

        assertNotNull(roleTO);
        assertEquals(roleTO.getId(), 6L);
    }
View Full Code Here

TOP

Related Classes of org.apache.syncope.client.to.RoleTO

Copyright © 2018 www.massapicom. 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.