Package org.rhq.core.domain.authz

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


    public void testRoles() throws Exception {
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        RoleManagerLocal roleManager = LookupUtil.getRoleManager();
        Subject overlord = subjectManager.getOverlord();

        Role superuserRole = roleManager.getRole(overlord, 1);
        Set<Permission> superuserRoleOriginalPermissions = superuserRole.getPermissions();
        assertTrue("[Superuser] role does not have all global permissions.",
            superuserRoleOriginalPermissions.containsAll(Permission.GLOBAL_ALL));
        assertTrue("[Superuser] role does not have all Resource permissions.",
            superuserRoleOriginalPermissions.containsAll(Permission.RESOURCE_ALL));
               
        Role allResourcesRole = roleManager.getRole(overlord, 2);
        Set<Permission> allResourcesRoleOriginalPermissions = allResourcesRole.getPermissions();
        assertTrue("[All Resources] role does not have MANAGE_INVENTORY permission.",
            allResourcesRoleOriginalPermissions.contains(Permission.MANAGE_INVENTORY));
        assertTrue("[All Resources] role does not have all Resource permissions.",
            allResourcesRoleOriginalPermissions.containsAll(Permission.RESOURCE_ALL));
    }
View Full Code Here


    public void testUpgradeToV2_119() throws Exception {
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        RoleManagerLocal roleManager = LookupUtil.getRoleManager();
        Subject overlord = subjectManager.getOverlord();

        Role customRole = new Role("role" + UUID.randomUUID());
        customRole.addPermission(Permission.MANAGE_REPOSITORIES);
        customRole.addPermission(Permission.MANAGE_MEASUREMENTS);
        customRole = roleManager.createRole(overlord, customRole);
        Set<Permission> customRoleOriginalPermissions = customRole.getPermissions();       
        assertFalse(customRoleOriginalPermissions.contains(Permission.VIEW_USERS));

        Role superuserRole = roleManager.getRole(overlord, 1);
        Set<Permission> superuserRoleOriginalPermissions = superuserRole.getPermissions();
        assertFalse(superuserRoleOriginalPermissions.contains(Permission.VIEW_USERS));
               
        Role allResourcesRole = roleManager.getRole(overlord, 2);
        Set<Permission> allResourcesRoleOriginalPermissions = allResourcesRole.getPermissions();
        assertFalse(allResourcesRoleOriginalPermissions.contains(Permission.VIEW_USERS));
       
        // Now upgrade the DB schema to v2.119, which introduces the VIEW_USERS global permission and adds it to any
        // existing roles.
        DbSetupUtility.dbupgrade("2.119");
       
        customRole = roleManager.getRole(overlord, customRole.getId());
        Set<Permission> customRoleNewPermissions = customRole.getPermissions();
        customRoleOriginalPermissions.add(Permission.VIEW_USERS);
        assertEquals(customRoleOriginalPermissions, customRoleNewPermissions);

        superuserRole = roleManager.getRole(overlord, 1);
        Set<Permission> superuserRoleNewPermissions = superuserRole.getPermissions();
        superuserRoleOriginalPermissions.add(Permission.VIEW_USERS);
        assertEquals(superuserRoleOriginalPermissions, superuserRoleNewPermissions);

        allResourcesRole = roleManager.getRole(overlord, 2);
        Set<Permission> allResourcesRoleNewPermissions = allResourcesRole.getPermissions();
        allResourcesRoleOriginalPermissions.add(Permission.VIEW_USERS);
        assertEquals(allResourcesRoleOriginalPermissions, allResourcesRoleNewPermissions);
    }
View Full Code Here

    public void testPurgeEventsForResourceGroupContext() {
        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 group");
                Resource resource = SessionTestHelper.createNewResourceForGroup(em, resourceGroup, "fake resource");
                EventDefinition eventDefinition = createEventDefinition(resource);
                em.persist(eventDefinition);
                EventSource eventSource = createEventSource(eventDefinition, resource);
View Full Code Here

    public void testGetEventCountsBySeverityForGroup() {
        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 group");
                Resource resource = SessionTestHelper.createNewResourceForGroup(em, resourceGroup, "fake resource");
                EventDefinition eventDefinition = createEventDefinition(resource);
                em.persist(eventDefinition);
                EventSource eventSource = createEventSource(eventDefinition, resource);
View Full Code Here

            public TestData execute() throws Exception {

                TestData newTestData = new TestData();
                Subject subject = SessionTestHelper.createNewSubject(em, subjectName);
                newTestData.setSubject(subject);
                Role role = SessionTestHelper.createNewRoleForSubject(em, subject, roleName, Permission.MANAGE_ALERTS);
                newTestData.setRole(role);
                ResourceType resourceType = SessionTestHelper.createNewResourceType(em);

                // To test bug 949048 we need a metric on the type
                MeasurementDefinition dynamicMeasuremenDef = new MeasurementDefinition(resourceType, measurementDefName);
                dynamicMeasuremenDef.setDefaultOn(true);
                dynamicMeasuremenDef.setDataType(MEASUREMENT);
                dynamicMeasuremenDef.setMeasurementType(DYNAMIC);
                em.persist(dynamicMeasuremenDef);

                newTestData.setResourceType(resourceType);
                ResourceGroup resourceGroup = new ResourceGroup(groupName, resourceType);
                resourceGroup = resourceGroupManager.createPrivateResourceGroup(subject, resourceGroup);
                newTestData.setResourceGroup(resourceGroup);
                roleManager.setAssignedResourceGroups(subjectManager.getOverlord(), role.getId(),
                    new int[] { resourceGroup.getId() });
                Resource resource = SessionTestHelper.createNewResourceForGroup(em, resourceGroup, resourceName);
                newTestData.setResource(resource);
                return newTestData;
            }
View Full Code Here

        try {
            //create new subject
            Subject subject = SessionTestHelper.createNewSubject(entityMgr, "testSubject");
            //create new role for subject
            Role roleWithSubject = SessionTestHelper.createNewRoleForSubject(entityMgr, subject, "role with subject");
            roleWithSubject.addPermission(Permission.VIEW_RESOURCE);
            Role newRole = new Role("role without subject");
            Role roleWithoutSubject = roleManager.createRole(overlord, newRole);

            //exercise findAvailableSubjectsForRole
            Integer[] pendingSubjectIds = new Integer[0];
            PageList<Subject> subjects = subjectManager.findAvailableSubjectsForRole(subjectManager.getOverlord(),
                roleWithoutSubject.getId(), pendingSubjectIds, PageControl.getUnlimitedInstance());
            assert subjects.size() > 0 : "Unable to locate subject(s) available for role with id '"
                + roleWithSubject.getId() + "'.";//Should be at least one.
            //            boolean located = false;
            Subject locatedSubject = null;
            for (Subject s : subjects) {
View Full Code Here

            Subject overlord = subjectManager.getOverlord();

            Subject new_user = new Subject("dummy-user", true, false);
            new_user = subjectManager.createSubject(overlord, new_user);

            Role new_role = new Role("dummy-role");
            RoleManagerLocal roleManager = LookupUtil.getRoleManager();
            new_role = roleManager.createRole(overlord, new_role);

            //            new_user.addRole(new_role);
            int[] subjectIds = new int[] { new_user.getId() };
            roleManager.addSubjectsToRole(overlord, new_role.getId(), subjectIds);
            assert new_role.getSubjects().contains(new_user) : "New_role does not contain new_user";
            int count = new_role.getSubjects().size();

            subjectManager.deleteUsers(overlord, subjectIds);

            assert new_role.getSubjects().size() == count - 1 : "User was not deleted from new_role";
        } finally {
            getTransactionManager().rollback();
        }

    }
View Full Code Here

        try {
            Subject overlord = subjectManager.getOverlord();
            Subject rhqadmin = subjectManager.getSubjectByName(RHQADMIN);

            Role roleWithViewUsersPerm = new Role("role" + UUID.randomUUID());
            roleWithViewUsersPerm.addPermission(Permission.VIEW_USERS);
            roleWithViewUsersPerm = roleManager.createRole(overlord, roleWithViewUsersPerm);

            Subject subjectWithViewUsersRole = new Subject("subject" + UUID.randomUUID(), true, false);
            subjectWithViewUsersRole.addRole(roleWithViewUsersPerm);
            subjectWithViewUsersRole = subjectManager.createSubject(overlord, subjectWithViewUsersRole, "password");
View Full Code Here

        getTransactionManager().begin();

        try {
            Subject overlord = subjectManager.getOverlord();

            Role roleWithoutViewUsersPerm = new Role("role" + UUID.randomUUID());
            roleWithoutViewUsersPerm = roleManager.createRole(overlord, roleWithoutViewUsersPerm);

            Subject subjectWithNonViewUsersRole = new Subject("subject" + UUID.randomUUID(), true, false);
            subjectWithNonViewUsersRole.addRole(roleWithoutViewUsersPerm);
            subjectWithNonViewUsersRole = subjectManager.createSubject(overlord, subjectWithNonViewUsersRole,
View Full Code Here

        }

        log.trace("getting role [" + roleId + "]");

        RoleManagerLocal roleManager = LookupUtil.getRoleManager();
        Role role = roleManager.getRoleById(roleId);
        role.setName(editForm.getName());
        role.setDescription(editForm.getDescription());
        role.setPermissions(new HashSet<Permission>(editForm.getPermissions()));

        log.trace("saving role [" + roleId + "]");

        try {
            roleManager.updateRole(RequestUtils.getSubject(request), 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.