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

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


    public void testCreateUserIdDifferentFromPrincipalName() throws RepositoryException {
        Principal p = getTestPrincipal();
        String uid = getTestUserId(p);
        String pw = buildPassword(uid, true);

        User u = null;
        Session uSession = null;
        try {
            u = userMgr.createUser(uid, pw, p, null);

            String msg = "Creating a User with principal-name distinct from Principal-name must succeed as long as both are unique.";
            assertEquals(msg, u.getID(), uid);
            assertEquals(msg, p.getName(), u.getPrincipal().getName());
            assertFalse(msg, u.getID().equals(u.getPrincipal().getName()));

            // make sure the userID exposed by a Session corresponding to that
            // user is equal to the users ID.
            uSession = superuser.getRepository().login(new SimpleCredentials(uid, pw.toCharArray()));
            assertEquals(uid, uSession.getUserID());
        } finally {
            if (uSession != null) {
                uSession.logout();
            }
            if (u != null) {
                u.remove();
            }
        }
    }
View Full Code Here


    public void testCreatingGroupWithNameMatchingExistingUserId() throws RepositoryException {
        Principal p = getTestPrincipal();
        String uid = getTestUserId(p);

        User u = null;
        Group gr = null;
        try {
            u = userMgr.createUser(uid, buildPassword(uid, true), p, null);
            gr = userMgr.createGroup(new TestPrincipal(uid));

            String msg = "Creating a Group with a principal-name that exists as UserID -> must create new GroupID but keep PrincipalName.";
            assertFalse(msg, gr.getID().equals(gr.getPrincipal().getName()));
            assertFalse(msg, gr.getID().equals(uid));
            assertFalse(msg, gr.getID().equals(u.getID()));
            assertEquals(msg, uid, gr.getPrincipal().getName());
        } finally {
            if (u != null) {
                u.remove();
            }
            if (gr != null) {
                gr.remove();
            }
        }
View Full Code Here

            }
        }
    }

    public void testFindUser() throws RepositoryException {
        User u = null;
        try {
            Principal p = getTestPrincipal();
            String uid = "UID" + p.getName();
            u = userMgr.createUser(uid, buildPassword(uid, false), p, null);

            boolean found = false;
            Iterator it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_USER);
            while (it.hasNext() && !found) {
                User nu = (User) it.next();
                found = nu.getID().equals(uid);
            }
            assertTrue("Searching for 'null' must find the created user.", found);

            it = userMgr.findAuthorizables(pPrincipalName, p.getName(), UserManager.SEARCH_TYPE_USER);
            found = false;
            while (it.hasNext() && !found) {
                User nu = (User) it.next();
                found = nu.getPrincipal().getName().equals(p.getName());
            }
            assertTrue("Searching for principal-name must find the created user.", found);

            it = userMgr.findAuthorizables(pUserID, uid, UserManager.SEARCH_TYPE_USER);
            found = false;
            while (it.hasNext() && !found) {
                User nu = (User) it.next();
                found = nu.getID().equals(uid);
            }
            assertTrue("Searching for user id must find the created user.", found);

            // but search groups should not find anything
            it = userMgr.findAuthorizables(pPrincipalName, p.getName(), UserManager.SEARCH_TYPE_GROUP);
View Full Code Here

    public void testNewUserCanLogin() throws RepositoryException {
        String uid = getTestPrincipal().getName();
        String pw = buildPassword(uid, false);

        User u = null;
        Session s = null;
        try {
            u = userMgr.createUser(uid, pw);
            Credentials creds = new SimpleCredentials(uid, pw.toCharArray());
            s = superuser.getRepository().login(creds);
        } finally {
            if (u != null) {
                u.remove();
            }
            if (s != null) {
                s.logout();
            }
        }
View Full Code Here

        // create a second user 'below' the first user.
        p = getTestPrincipal();
        String pw = buildPassword(p);
        Credentials otherCreds = buildCredentials(p.getName(), pw);
        User other = userMgr.createUser(p.getName(), pw, p, u.getNode().getPath());
        otherUID = other.getID();
        otherPath = ((UserImpl) other).getNode().getPath();

        // make other user a user-administrator:
        Authorizable ua = userMgr.getAuthorizable(UserConstants.USER_ADMIN_GROUP_NAME);
        if (ua == null || !ua.isGroup()) {
View Full Code Here

    public void testModifyImpersonationOfChildUser() throws RepositoryException, NotExecutableException {
        UserManager umgr = getUserManager(otherSession);
        Principal otherP = umgr.getAuthorizable(otherUID).getPrincipal();

        User u = null;
        // create a new user -> must succeed and user must be create below 'other'
        try {
            Principal p = getTestPrincipal();
            u = umgr.createUser(p.getName(), buildPassword(p));

            Impersonation impers = u.getImpersonation();
            assertFalse(impers.allows(buildSubject(otherP)));
            assertTrue(impers.grantImpersonation(otherP));
            assertTrue(impers.allows(buildSubject(otherP)));
        } finally {
            // impersonation get removed while removing the user u.
            if (u != null) {
                u.remove();
            }
        }
    }
View Full Code Here

        }
    }

    public void testModifyImpersonationOfParentUser() throws RepositoryException, NotExecutableException {
        UserManager umgr = getUserManager(otherSession);
        User u = (User) umgr.getAuthorizable(uID);
        Impersonation uImpl = u.getImpersonation();

        Principal otherP = umgr.getAuthorizable(otherUID).getPrincipal();

        if (!uImpl.allows(buildSubject(otherP))) {
            // ... trying to modify 'impersonators of 'uid' must not succeed.
View Full Code Here

    }

    public void testModifyGroupForHimSelf() throws RepositoryException, NotExecutableException {
        UserManager umgr = getUserManager(otherSession);

        User userHimSelf = (User) umgr.getAuthorizable(otherUID);
        Group gr = getGroupAdminGroup(umgr);
        try {
            assertFalse(gr.addMember(userHimSelf));
        } catch (RepositoryException e) {
            // success as well.
View Full Code Here

    }

    public void testModifyGroupForParentUser() throws RepositoryException, NotExecutableException {
        UserManager umgr = getUserManager(otherSession);

        User parentUser = (User) umgr.getAuthorizable(uID);
        if (parentUser == null) {
            throw new NotExecutableException();
        } else {
            Group gr = getGroupAdminGroup(umgr);
            try {
View Full Code Here

    }

    public void testModifyGroupForChildUser() throws RepositoryException, NotExecutableException {
        UserManager umgr = getUserManager(otherSession);
        Principal cp = getTestPrincipal();
        User childU = null;
        try {
            childU = umgr.createUser(cp.getName(), buildPassword(cp));
            Group gr = getGroupAdminGroup(umgr);
            try {
                assertFalse(gr.addMember(childU));
            } catch (RepositoryException e) {
                // success
            }
        } finally {
            if (childU != null) {
                childU.remove();
            }
        }
    }
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.