Package org.rhq.enterprise.server.auth

Examples of org.rhq.enterprise.server.auth.SubjectManagerLocal


            getTransactionManager().begin();

            // Setup
            // --------------------------------------------
            RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
            SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
            Subject overlord = subjectManager.getOverlord();

            // -> Add an already imported repo to the system so it already exists when the report introduces it
            Repo existingImportedRepo = new Repo(TestContentProvider.EXISTING_IMPORTED_REPO_NAME);
            existingImportedRepo.setCandidate(false);
            repoManager.createRepo(overlord, existingImportedRepo);
View Full Code Here


        assert all_users_with_principals.contains(rhqadmin.getName());
        assert !subjectManager.isUserWithPrincipal(superuser.getName());
        assert subjectManager.isUserWithPrincipal(rhqadmin.getName());

        // get all subjects, whether or not they have a principal
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        Subject subject = null;
        try {
            subject = subjectManager.loginUnauthenticated(RHQADMIN);
        } catch (Exception e) {
            assert false : "There must be at least rhqadmin user";
        }

        SubjectCriteria c = new SubjectCriteria();
        c.addFilterFsystem(false);
        c.addSortName(PageOrdering.ASC);
        PageList<Subject> all_subjects = subjectManager.findSubjectsByCriteria(subject, c);

        assert all_subjects.size() >= 1 : "There must be at least rhqadmin user";
        assert !all_subjects.contains(superuser) : "The superuser should not have been returned in the list";
        assert all_subjects.contains(rhqadmin) : "Missing user [" + rhqadmin + "] from: " + all_subjects;

        // create, modify then delete the user
        new_user = new Subject();
        new_user.setFsystem(false);
        new_user.setFactive(true);
        new_user.setName("dummy-user");
        new_user.setFirstName("my-firstname");
        new_user.setLastName("my-lastname");
        new_user.setEmailAddress("email@address.com");
        new_user.setPhoneNumber("1-800-555-1212");
        new_user.setSmsAddress("sms address");
        new_user.setDepartment("my-department");

        new_user = subjectManager.createSubject(rhqadmin, new_user);
        new_user = createSession(new_user);
        assert !subjectManager.isUserWithPrincipal(new_user.getName());
        subjectManager.createPrincipal(subjectManager.getOverlord(), new_user.getName(), "my-password");
        assert subjectManager.isUserWithPrincipal(new_user.getName());

        // make sure it was persisted and you can actually login with it
        assert new_user.getId() != 0;
        Subject login_new_user = subjectManager.loginUnauthenticated(new_user.getName());
        assert login_new_user.equals(new_user);
        new_user = login_new_user; // login_new_user was given a new session ID

        subjectManager.changePassword(new_user, new_user.getName(), "my-new-password");
        subjectManager.changePassword(rhqadmin, new_user.getName(), "my-new-password"); // see that rhqadmin can change it too

        getTransactionManager().commit();
        getTransactionManager().begin();

        try {
            subjectManager.changePassword(new_user, rhqadmin.getName(), "not-allowed");
            assert false : "The new user does not have permission to change another's password";
        } catch (PermissionException se) {
        } finally {
            // PermissionException causes a rollback, let's start a new tx
            getTransactionManager().rollback();
        }

        getTransactionManager().begin();

        // this new user has no roles - therefore, no global permissions
        assert authorizationManager.getExplicitGlobalPermissions(new_user).size() == 0;

        try {
            subjectManager.deleteUsers(new_user, new int[] { new_user.getId() });
            assert false : "The new user should not have had the permission to delete itself";
        } catch (PermissionException e) {
        } finally {
            // PermissionException causes a rollback, let's start a new tx
            getTransactionManager().rollback();
        }

        getTransactionManager().begin();

        // delete the new user
        assert subjectManager.getSubjectByName(new_user.getName()).equals(new_user);
        assert subjectManager.isUserWithPrincipal(new_user.getName());
        subjectManager.deleteUsers(rhqadmin, new int[] { new_user.getId() });
        assert subjectManager.getSubjectByName(new_user.getName()) == null;
        assert !subjectManager.isUserWithPrincipal(new_user.getName());

        getTransactionManager().commit();
    }
View Full Code Here

     * @throws NotSupportedException
     */
    public void testFindSubjectsWithRoles() throws NotSupportedException, SystemException {
        getTransactionManager().begin();
        EntityManager entityMgr = getEntityManager();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        RoleManagerLocal roleManager = LookupUtil.getRoleManager();
        Subject overlord = subjectManager.getOverlord();

        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;
View Full Code Here

        log.trace("modifying user properties action");

        EditForm userForm = (EditForm) form;
        ActionForward forward = checkSubmit(request, mapping, form, Constants.USER_PARAM, userForm.getId());

        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        Subject user = subjectManager.loadUserConfiguration(userForm.getId());

        if (forward != null) {
            request.setAttribute(Constants.USER_ATTR, user);
            return forward;
        }

        user.setFirstName(userForm.getFirstName());
        user.setLastName(userForm.getLastName());
        user.setDepartment(userForm.getDepartment());
        user.setName(userForm.getName());
        user.setEmailAddress(userForm.getEmailAddress());
        user.setPhoneNumber(userForm.getPhoneNumber());
        user.setSmsAddress(userForm.getSmsAddress());
        user.setFactive(userForm.getEnableLogin().equals("yes"));

        // a user can only edit his own configuration
        WebUser currentUser = RequestUtils.getWebUser(request);
        if (currentUser.getId().equals(userForm.getId())) {
            // update the in-memory preferences of the webuser so it takes effect for this session
            try {
                WebUserPreferences webPreferences = currentUser.getWebPreferences();
                int pageRefreshPeriod = Integer.valueOf(userForm.getPageRefreshPeriod());
                webPreferences.setPageRefreshPeriod(pageRefreshPeriod);
            } catch (NumberFormatException e) {
                throw new RuntimeException(
                    "pageRefreshPeriod is not an integer, this should have been caught earlier by the form validation.");
            }

            try {
                SubjectPreferences corePreferences = currentUser.getSubjectPreferences();
                int timeoutPeriod = Integer.valueOf(userForm.getGroupConfigurationTimeout());
                corePreferences.setGroupConfigurationTimeoutPeriod(timeoutPeriod);
            } catch (NumberFormatException e) {
                throw new RuntimeException(
                    "groupConfigurationTimeout is not an integer, this should have been caught earlier by the form validation.");
            }
        }

        subjectManager.updateSubject(currentUser.getSubject(), user);

        return returnSuccess(request, mapping, Constants.USER_PARAM, userForm.getId());
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.auth.SubjectManagerLocal

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.