Package org.apache.jackrabbit.api.security.user

Examples of org.apache.jackrabbit.api.security.user.UserManager


        String[] workspaceNames = superuser.getWorkspace().getAccessibleWorkspaceNames();

        for (String workspaceName1 : workspaceNames) {
            Session s = getHelper().getSuperuserSession(workspaceName1);
            try {
                UserManager umgr = getUserManager(s);
                s.logout();

                // after logging out the session, the user manager must have been
                // released as well and it's underlying session must not be available
                // any more -> accessing users must fail.
                try {
                    umgr.getAuthorizable("any userid");
                    fail("After having logged out the original session, the user manager must not be live any more.");
                } catch (RepositoryException e) {
                    // success
                }
            } finally {
View Full Code Here


        xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_IMPL)), true);
        umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();

        // assignable from same class as configured
        UserManager um = umc.getUserManager(UserManagerImpl.class, new Class[] {
            SessionImpl.class, String.class}, (SessionImpl) superuser, "admin");
        assertNotNull(um);
        assertTrue(um instanceof UserManagerImpl);
        assertTrue(um.isAutoSave());
        try {
            um.autoSave(false);
            fail("must not be allowed");
        } catch (RepositoryException e) {
            // success
        }

        // derived class expected -> must fail
        xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_IMPL)), true);
        umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();
        try {
            um = umc.getUserManager(UserPerWorkspaceUserManager.class, new Class[] {
                    SessionImpl.class, String.class}, (SessionImpl) superuser, "admin");
            fail("UserManagerImpl is not assignable from derived class");
        } catch (ConfigurationException e) {
            // success
        }

        // passing invalid parameter types
        xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_IMPL)), true);
        umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();
        try {
            um = umc.getUserManager(UserManagerImpl.class, new Class[] {
                    Session.class}, (SessionImpl) superuser, "admin");
            fail("Invalid parameter types -> must fail.");
        } catch (ConfigurationException e) {
            // success
        }

        // passing wrong arguments       
        xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_IMPL)), true);
        umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();
        try {
            um = umc.getUserManager(UserManagerImpl.class, new Class[] {
                    SessionImpl.class, String.class}, superuser, 21);
            fail("Invalid init args -> must fail.");
        } catch (ConfigurationException e) {
            // success
        }

        xml = parseXML(new InputSource(new StringReader(USER_MANAGER_CONFIG_DERIVED)), true);
        umc = parser.parseSecurityConfig(xml).getSecurityManagerConfig().getUserManagerConfig();
        // assignable from defines base class
        um = umc.getUserManager(UserManagerImpl.class, new Class[] {
            SessionImpl.class, String.class}, (SessionImpl) superuser, "admin");
        assertNotNull(um);
        assertTrue(um instanceof UserPerWorkspaceUserManager);
        // but: configured class creates a umgr that requires session.save
        assertTrue(um.isAutoSave());
        // changing autosave behavior must succeed.
        um.autoSave(false);
    }
View Full Code Here

                "target/repository_with_auth");

        // set up a user to authenticate
        SessionImpl session = (SessionImpl) repository
                .login(new SimpleCredentials("admin", "admin".toCharArray()));
        UserManager userManager = session.getUserManager();
        User user = (User) userManager.getAuthorizable("test");
        if (user == null) {
            user = userManager.createUser("test", "quatloos");
        }
        // set up permissions
        String path = session.getRootNode().getPath();
        AccessControlManager accessControlManager = session
                .getAccessControlManager();
View Full Code Here

            throw new NotExecutableException("SessionImpl expected.");
        }

        sImpl = (SessionImpl) superuser;

        UserManager umgr = sImpl.getUserManager();
        if (umgr.isAutoSave()) {
            try {
                umgr.autoSave(false);
            } catch (RepositoryException e) {
                // user manager cannot have the autosave behavior changed
                // -> test not executable
                throw new NotExecutableException("Expected user manager that can have its autosave behavior changed to false.");
            }
        }
        this.umgr = (UserManagerImpl) umgr;
        // avoid collision with testing a-folders that may have been created
        // with another test (but not removed as user/groups got removed)
        String path = this.umgr.getUsersPath() + "/t";
        if (sImpl.nodeExists(path)) {
            sImpl.getNode(path).remove();
        }
        path = this.umgr.getGroupsPath() + "/g";
        if (sImpl.nodeExists(path)) {
            sImpl.getNode(path).remove();
        }
        sImpl.save();

        Authorizable administrators = umgr.getAuthorizable(SecurityConstants.ADMINISTRATORS_NAME);
        if (administrators == null) {
            groupIdToRemove = umgr.createGroup(new PrincipalImpl(SecurityConstants.ADMINISTRATORS_NAME)).getID();
            sImpl.save();
        } else if (!administrators.isGroup()) {
            throw new NotExecutableException("Expected " + administrators.getID() + " to be a group.");
        }
    }
View Full Code Here

        public PrincipalManager getPrincipalManager() throws AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
            return null;
        }

        public UserManager getUserManager() throws AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
            return new UserManager() {

                public Authorizable getAuthorizable(String id) throws RepositoryException {
                    return null;
                }
View Full Code Here

        }
    }

    public void testSingleToMultiValued() throws Exception {
        AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
        UserManager uMgr = getUserManager(superuser);
        try {
            Value v = superuser.getValueFactory().createValue("anyValue");
            user.setProperty("someProp", v);
            if (!uMgr.isAutoSave()) {
                superuser.save();
            }
            Value[] vs = new Value[] {v, v};
            user.setProperty("someProp", vs);
            if (!uMgr.isAutoSave()) {
                superuser.save();
            }
        } finally {
            if (user.removeProperty("someProp") && !uMgr.isAutoSave()) {
                superuser.save();
            }
        }
    }
View Full Code Here

        }
    }

    public void testMultiValuedToSingle() throws Exception {
        AuthorizableImpl user = (AuthorizableImpl) getTestUser(superuser);
        UserManager uMgr = getUserManager(superuser);
        try {
            Value v = superuser.getValueFactory().createValue("anyValue");
            Value[] vs = new Value[] {v, v};
            user.setProperty("someProp", vs);
            if (!uMgr.isAutoSave()) {
                superuser.save();
            }
            user.setProperty("someProp", v);
            if (!uMgr.isAutoSave()) {
                superuser.save();
            }
        } finally {
            if (user.removeProperty("someProp") && !uMgr.isAutoSave()) {
                superuser.save();
            }
        }
    }
View Full Code Here

    }

    public void testCleanup() throws RepositoryException, NotExecutableException {
        Session s = getHelper().getSuperuserSession();
        try {
            UserManager umgr = getUserManager(s);
            s.logout();

            // after logging out the session, the user manager must have been
            // released as well and it's underlying session must not be available
            // any more -> accessing users must fail.
            try {
                umgr.getAuthorizable("any userid");
                fail("After having logged out the original session, the user manager must not be live any more.");
            } catch (RepositoryException e) {
                // success
            }
        } finally {
View Full Code Here

        String[] workspaceNames = superuser.getWorkspace().getAccessibleWorkspaceNames();

        for (String workspaceName1 : workspaceNames) {
            Session s = getHelper().getSuperuserSession(workspaceName1);
            try {
                UserManager umgr = getUserManager(s);
                s.logout();

                // after logging out the session, the user manager must have been
                // released as well and it's underlying session must not be available
                // any more -> accessing users must fail.
                try {
                    umgr.getAuthorizable("any userid");
                    fail("After having logged out the original session, the user manager must not be live any more.");
                } catch (RepositoryException e) {
                    // success
                }
            } finally {
View Full Code Here

            if (isWorkspaceImport) {
                log.debug("Only Session-Import is supported when importing users or groups.");
                return false;
            }
            try {
                UserManager uMgr = session.getUserManager();
                if (uMgr instanceof UserPerWorkspaceUserManager) {
                    // make sure the user managers autosave flag can be changed to false.
                    if (uMgr.isAutoSave()) {
                        uMgr.autoSave(false);
                        resetAutoSave = true;
                        log.debug("Changed autosave behavior of UserManager to 'false'.");
                    }
                    userManager = (UserPerWorkspaceUserManager) uMgr;
                    initialized = true;
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.api.security.user.UserManager

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.