Package org.rhq.core.domain.authz

Examples of org.rhq.core.domain.authz.Role


            @Override
            public void execute() throws Exception {
                Subject subject = SessionTestHelper.createNewSubject(em, "fake subject");
                Set<Permission> originalPermissions = new HashSet<Permission>();
                originalPermissions.addAll(EnumSet.allOf(Permission.class));
                Role originalRole = SessionTestHelper.createNewRoleForSubject(em, subject, "fake role",
                    originalPermissions.toArray(new Permission[originalPermissions.size()]));
                ResourceGroup resourceGroup = SessionTestHelper.createNewCompatibleGroupForRole(em, originalRole,
                    "fake group");

                Role role = new Role();
                role.setId(originalRole.getId());
                role.setName("fake role name modified");
                role.setDescription("fake role description modified");
                Set<Permission> permissions = new HashSet<Permission>(originalRole.getPermissions());
                permissions.remove(Permission.MANAGE_SECURITY);
                permissions.remove(Permission.MANAGE_INVENTORY);
                permissions.remove(Permission.MANAGE_DRIFT);
                role.setPermissions(permissions);
                Subject subject1 = SessionTestHelper.createNewSubject(em, "fake subject 1");
                role.getSubjects().add(subject1);
                Subject subject2 = SessionTestHelper.createNewSubject(em, "fake subject 2");
                role.getSubjects().add(subject2);
                role.getSubjects().remove(subject);
                ResourceGroup resourceGroup1 = SessionTestHelper.createNewCompatibleGroupForRole(em, originalRole,
                    "fake group 1");
                role.getResourceGroups().add(resourceGroup1);
                ResourceGroup resourceGroup2 = SessionTestHelper.createNewCompatibleGroupForRole(em, originalRole,
                    "fake group 2");
                role.getResourceGroups().add(resourceGroup2);
                role.getResourceGroups().remove(resourceGroup);

                role = roleManager.updateRole(subjectManager.getOverlord(), role);

                assertEquals("fake role name modified", role.getName());
                assertEquals("fake role description modified", role.getDescription());
                assertEquals(permissions, role.getPermissions());
                List<Subject> expectedSubjects = Arrays.asList(subject1, subject2);
                assertTrue(role.getSubjects().containsAll(expectedSubjects)
                    && expectedSubjects.containsAll(role.getSubjects()));
                List<ResourceGroup> expectedResourceGroups = Arrays.asList(resourceGroup1, resourceGroup2);
                assertTrue(role.getResourceGroups().containsAll(expectedResourceGroups)
                    && expectedResourceGroups.containsAll(role.getResourceGroups()));
            }
        });
    }
View Full Code Here


    public void testSetAssignedResourceGroups() {
        executeInTransaction(new TransactionCallback() {
            @Override
            public void execute() throws Exception {
                Subject subject = SessionTestHelper.createNewSubject(em, "fake subject");
                Role role = SessionTestHelper.createNewRoleForSubject(em, subject, "fake role");
                List<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>();
                for (int i = 0; i < 17; i++) {
                    resourceGroups.add(SessionTestHelper.createNewCompatibleGroupForRole(em, role, "fake group "
                        + String.valueOf(i)));
                }
                List<ResourceGroup> resourceGroupsToKeep = resourceGroups.subList(5, 14);
                int[] resourceGroupsToKeepIds = new int[resourceGroupsToKeep.size()];
                for (int i = 0; i < resourceGroupsToKeep.size(); i++) {
                    resourceGroupsToKeepIds[i] = resourceGroupsToKeep.get(i).getId();
                }
                roleManager.setAssignedResourceGroups(subjectManager.getOverlord(), role.getId(),
                    resourceGroupsToKeepIds);
                assertTrue(role.getResourceGroups().containsAll(resourceGroupsToKeep)
                    && resourceGroupsToKeep.containsAll(role.getResourceGroups()));
            }
        });
    }
View Full Code Here

    public void testSetAssignedSubjects() {
        executeInTransaction(new TransactionCallback() {
            @Override
            public void execute() throws Exception {
                Subject subject = SessionTestHelper.createNewSubject(em, "fake subject");
                Role role = SessionTestHelper.createNewRoleForSubject(em, subject, "fake role");
                List<Subject> subjects = new ArrayList<Subject>();
                for (int i = 0; i < 17; i++) {
                    subjects.add(SessionTestHelper.createNewSubject(em, "fake subject " + String.valueOf(i)));
                }
                List<Subject> subjectsToKeep = subjects.subList(5, 14);
                int[] subjectsToKeepIds = new int[subjectsToKeep.size()];
                for (int i = 0; i < subjectsToKeep.size(); i++) {
                    subjectsToKeepIds[i] = subjectsToKeep.get(i).getId();
                }
                roleManager.setAssignedSubjects(subjectManager.getOverlord(), role.getId(), subjectsToKeepIds);
                assertTrue(role.getSubjects().containsAll(subjectsToKeep)
                    && subjectsToKeep.containsAll(role.getSubjects()));
            }
        });
    }
View Full Code Here

    public void testSetRolesFromResourceGroup() {
        executeInTransaction(new TransactionCallback() {
            @Override
            public void execute() throws Exception {
                Subject subject = SessionTestHelper.createNewSubject(em, "fake subject");
                Role role = SessionTestHelper.createNewRoleForSubject(em, subject, "fake role");
                ResourceGroup resourceGroup = SessionTestHelper.createNewCompatibleGroupForRole(em, role,
                    "fake resource group");
                List<Integer> rolesIds = new LinkedList<Integer>();
                List<Integer> rolesToRemoveIds = new LinkedList<Integer>();
                List<Role> rolesToKeep = new LinkedList<Role>();
                for (int i = 0; i < 17; i++) {
                    Role newRole = SessionTestHelper.createNewRoleForSubject(em, subject,
                        "fake role " + String.valueOf(i));
                    rolesIds.add(newRole.getId());
                    if (i < 5 || i >= 14) {
                        rolesToRemoveIds.add(newRole.getId());
                    } else {
                        rolesToKeep.add(newRole);
                    }
                }
                rolesToRemoveIds.add(role.getId());
View Full Code Here

        int resourceCount = 700; //assuming 200 per page at least 4 pages of results.

        try {
            final Subject subject = SessionTestHelper.createNewSubject(entityMgr, "testSubject");

            Role roleWithSubject = SessionTestHelper.createNewRoleForSubject(entityMgr, subject, "role with subject");
            roleWithSubject.addPermission(Permission.VIEW_RESOURCE);

            ResourceGroup group = SessionTestHelper.createNewCompatibleGroupForRole(entityMgr, roleWithSubject,
                "accessible group");

            String tuid = "" + new Random().nextInt();
View Full Code Here

        int resourceCount = 344;

        try {
            final Subject subject = SessionTestHelper.createNewSubject(entityMgr, "testSubject");

            Role roleWithSubject = SessionTestHelper.createNewRoleForSubject(entityMgr, subject, "role with subject");
            roleWithSubject.addPermission(Permission.VIEW_RESOURCE);

            ResourceGroup group = SessionTestHelper.createNewCompatibleGroupForRole(entityMgr, roleWithSubject,
                "accessible group");

            String tuid = "" + new Random().nextInt();
View Full Code Here

        int resourceCount = 423;

        try {
            final Subject subject = SessionTestHelper.createNewSubject(entityMgr, "testSubject");

            Role roleWithSubject = SessionTestHelper.createNewRoleForSubject(entityMgr, subject, "role with subject");
            roleWithSubject.addPermission(Permission.VIEW_RESOURCE);

            ResourceGroup group = SessionTestHelper.createNewCompatibleGroupForRole(entityMgr, roleWithSubject,
                "accessible group");

            String tuid = "" + new Random().nextInt();
View Full Code Here

    public static Role createNewRoleForSubject(EntityManager em, Subject subject, String roleName,
        Permission... permissions) {
        roleName = preprocess(roleName);

        Role newRole = new Role(roleName);
        newRole.setFsystem(false);

        for (Permission perm : permissions) {
            newRole.addPermission(perm);
        }

        subject.getRoles().add(newRole);
        newRole.getSubjects().add(subject);

        em.persist(subject);
        em.persist(newRole);
        em.flush();
View Full Code Here

        return tab;
    }

    @Override
    protected Record createNewRecord() {
        Role role = new Role();
        role.addPermission(Permission.VIEW_USERS);
        Record roleRecord = RolesDataSource.getInstance().copyValues(role);
        return roleRecord;
    }
View Full Code Here

                server.setName(universalName);
                server.setOperationMode(OperationMode.NORMAL);

                server.setAgents(Collections.singletonList(agent));

                role = new Role(universalName);
                role.addPermission(Permission.MANAGE_INVENTORY);
                role.addPermission(Permission.MANAGE_SETTINGS);

                subject = new Subject(universalName, true, false);
                subject.addRole(role);
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.authz.Role

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.