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

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


        // create a second user and make it group-admin
        p = getTestPrincipal();
        String pw = buildPassword(p);
        Credentials creds = buildCredentials(p.getName(), pw);
        User user = userMgr.createUser(p.getName(), pw);
        save(superuser);
        uID = user.getID();

        // make other user a group-administrator:
        Authorizable grAdmin = userMgr.getAuthorizable(UserConstants.GROUP_ADMIN_GROUP_NAME);
        if (grAdmin == null || !grAdmin.isGroup()) {
            throw new NotExecutableException("Cannot execute test. No group-administrator group found.");
View Full Code Here


    }

    public void testAddMembersToCreatedGroup() throws RepositoryException, NotExecutableException {
        UserManager umgr = getUserManager(uSession);
        Group testGroup = null;
        User self = (User) umgr.getAuthorizable(uID);
        try {
            // let groupadmin create a new group
            testGroup = umgr.createGroup(getTestPrincipal(), "/a/b/c/d");
            save(uSession);
View Full Code Here

        if (auth == null || !auth.isGroup()) {
            throw new NotExecutableException("Cannot execute test. No User-Admin group found.");
        }
        Group userAdmin = (Group) auth;
        Group testGroup = null;
        User self = (User) umgr.getAuthorizable(uID);
        try {

            userAdmin.addMember(self);
            save(uSession);
View Full Code Here

        }
    }

    public void testRemoveMembersOfForeignGroup() throws RepositoryException, NotExecutableException {
        Group nGr = null;
        User nUs = null;
        User nUs2 = null;

        try {
            // let superuser create a group and a user a make user member of group
            nGr = userMgr.createGroup(getTestPrincipal());
            save(superuser);

            Principal p = getTestPrincipal();
            nUs = userMgr.createUser(p.getName(), buildPassword(p));
            save(superuser);

            p = getTestPrincipal();
            nUs2 = userMgr.createUser(p.getName(), buildPassword(p));
            save(superuser);
            nGr.addMember(nUs);
            nGr.addMember(nUs2);
            save(superuser);

            UserManager umgr = getUserManager(uSession);
            Group gr = (Group) umgr.getAuthorizable(nGr.getID());

            // removing any member must fail unless the testuser is user-admin
            Iterator<Authorizable> it = gr.getMembers();
            if (it.hasNext()) {
                Authorizable auth = it.next();

                String msg = "GroupAdmin must be able to modify group membership.";
                assertTrue(msg, gr.removeMember(auth));
                save(uSession);
            } else {
                fail("Must contain members....");
            }

        } catch (AccessDeniedException e) {
            // fine as well.
        } finally {
            // let superuser remove authorizables again
            if (nGr != null) {
                nGr.removeMember(nUs);
                nGr.removeMember(nUs2);
                nGr.remove();
            }
            if (nUs != null) nUs.remove();
            if (nUs2 != null) nUs2.remove();
            save(superuser);
        }
    }
View Full Code Here

        }
    }

    public void testRemoveAllMembersOfForeignGroup() throws RepositoryException, NotExecutableException {
        Group nGr = null;
        User nUs = null;

        try {
            // let superuser create a group and a user a make user member of group
            nGr = userMgr.createGroup(getTestPrincipal());
            save(superuser);
            Principal p = getTestPrincipal();
            nUs = userMgr.createUser(p.getName(), buildPassword(p));
            nGr.addMember(nUs);
            save(superuser);

            UserManager umgr = getUserManager(uSession);
            Group gr = (Group) umgr.getAuthorizable(nGr.getID());

            // since only 1 single member -> removal rather than modification.
            // since uSession is not user-admin this must fail.
            for (Iterator<Authorizable> it = gr.getMembers(); it.hasNext();) {
                Authorizable auth = it.next();

                String msg = "GroupAdmin must be able to remove a member of another group.";
                assertTrue(msg, gr.removeMember(auth));
                save(uSession);
            }
        } catch (AccessDeniedException e) {
            // fine as well.
        } finally {
            // let superuser remove authorizables again
            if (nGr != null && nUs != null) nGr.removeMember(nUs);
            if (nGr != null) nGr.remove();
            if (nUs != null) nUs.remove();
            save(superuser);
        }
    }
View Full Code Here

    public void testImpersonationOfOtherUser() throws RepositoryException, NotExecutableException {
        UserManager umgr = getUserManager(uSession);
        Principal selfPrinc = umgr.getAuthorizable(uID).getPrincipal();

        User child = (User) umgr.getAuthorizable(getYetAnotherID());
        Impersonation impers = child.getImpersonation();
        assertFalse(impers.allows(buildSubject(selfPrinc)));
        try {
            assertFalse(impers.grantImpersonation(selfPrinc));
            save(uSession);
        } catch (AccessDeniedException e) {
            // ok.
        }
        assertFalse(impers.allows(buildSubject(selfPrinc)));

        User parent = (User) umgr.getAuthorizable(otherUID);
        impers = parent.getImpersonation();
        assertFalse(impers.allows(buildSubject(selfPrinc)));
        try {
            assertFalse(impers.grantImpersonation(selfPrinc));
            save(uSession);
        } catch (AccessDeniedException e) {
View Full Code Here

    }

    public void testSetSpecialProperties() throws NotExecutableException, RepositoryException {
        Value v = superuser.getValueFactory().createValue("any_value");

        User u = getTestUser(superuser);
        for (String pName : protectedUserProps) {
            try {
                u.setProperty(pName, v);
                save(superuser);
                fail("changing the '" + pName + "' property on a User should fail.");
            } catch (RepositoryException e) {
                // success
            }
View Full Code Here

            }
        }
    }

    public void testRemoveSpecialProperties() throws NotExecutableException, RepositoryException {
        User u = getTestUser(superuser);
        for (String pName : protectedUserProps) {
            try {
                u.removeProperty(pName);
                save(superuser);
                fail("removing the '" + pName + "' property on a User should fail.");
            } catch (RepositoryException e) {
                // success
            }
View Full Code Here

        if (altWsp == null) {
            throw new NotExecutableException();
        }

        Session s = getHelper().getSuperuserSession(altWsp);
        User u = null;
        try {
            // other users created in the default workspace...
            u = ((JackrabbitSession) superuser).getUserManager().createUser("testUser", "testUser");
            superuser.save();

            // ... must not be present in the alternate-workspace
            UserManager umgr = ((JackrabbitSession) s).getUserManager();
            assertNull(umgr.getAuthorizable("testUser"));

            try {
                Session us = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()), altWsp);
                us.logout();
                fail("testUser must not be able to login to a workspace without this user.");
            } catch (LoginException e) {
                // success
            }

        } finally {
            s.logout();
            if (u != null) {
                u.remove();
                superuser.save();
            }
        }
    }
View Full Code Here

        }

        UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();

        Session s = getHelper().getSuperuserSession(altWsp);
        User u = null;
        try {
            // other users created in the default workspace...
            u = uMgr.createUser("testUser", "testUser");
            superuser.save();

            String userPath = null;
            if (u.getPrincipal() instanceof ItemBasedPrincipal) {
                userPath = ((ItemBasedPrincipal) u.getPrincipal()).getPath();
                assertTrue(superuser.nodeExists(userPath));
            } else {
                throw new NotExecutableException();
            }

            // ... must not be present in the alternate-workspace
            UserManager umgr = ((JackrabbitSession) s).getUserManager();
            assertNull(umgr.getAuthorizable("testUser"));
            assertFalse(s.nodeExists(userPath));

            String clonePath = userPath;
            String parentPath = Text.getRelativeParent(clonePath, 1);
            while (!s.nodeExists(parentPath)) {
                clonePath = parentPath;
                parentPath = Text.getRelativeParent(parentPath, 1);
            }

            // clone the user into the second workspace
            s.getWorkspace().clone(superuser.getWorkspace().getName(), clonePath, clonePath, true);

            // ... now the user must be visible
            assertNotNull(umgr.getAuthorizable("testUser"));
            if (userPath != null) {
                assertTrue(s.nodeExists(userPath));               
            }
            // ... and able to login to that workspace
            Session us = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()), altWsp);
            us.logout();

        } finally {
            // remove the test user in the second workspace
            Authorizable dest = ((JackrabbitSession) s).getUserManager().getAuthorizable("testUser");
            if (dest != null) {
                dest.remove();
                s.save();
            }
            // logout the session
            s.logout();
            if (u != null) {
                // remove as well in the first workspace
                u.remove();
                superuser.save();
            }
        }
    }
View Full Code Here

TOP

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

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.