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

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


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

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

            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();
                save(superuser);
            }
            if (gr != null) {
                gr.remove();
                save(superuser);
View Full Code Here


            }
        }
    }

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

            boolean found = false;
            Iterator<Authorizable> 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);

            // 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, NotExecutableException {
        String uid = getTestPrincipal().getName();
        String pw = buildPassword(uid);

        User u = null;
        Session s = null;
        try {
            u = userMgr.createUser(uid, pw);
            save(superuser);

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

        invalid.add("../../path");
        invalid.add(usersPath + "/../test");

        for (String path : invalid) {
            try {
                User user = userMgr.createUser(uid, buildPassword(uid), p, path);
                save(superuser);

                fail("intermediate path may not point outside of the user tree.");
                user.remove();
                save(superuser);
               
            } catch (Exception e) {
                // success
                assertNull(userMgr.getAuthorizable(uid));
View Full Code Here

    }

    public void testInheritedMemberShip() throws RepositoryException, NotExecutableException {
        Principal up = getTestPrincipal();

        User u = null;
        Group gr1 = null;
        Group gr2 = null;
        try {
            u = userMgr.createUser(up.getName(), buildPassword(up));
            gr1 = userMgr.createGroup(getTestPrincipal());
            gr2 = userMgr.createGroup(getTestPrincipal());
            save(superuser);


            gr1.addMember(gr2);
            gr2.addMember(u);
            save(superuser);

            PrincipalIterator it = principalProvider.getGroupMembership(u.getPrincipal());
            while (it.hasNext()) {
                Principal p = it.nextPrincipal();
                if (p.equals(gr1.getPrincipal())) {
                    // success return
                    return;
                }
            }

            fail("User principal " + up.getName() + " must have inherited group membership for " + gr1.getPrincipal().getName());

        } finally {
            if (gr2 != null && u != null) gr2.removeMember(u);
            if (gr1 != null && gr2 != null) gr1.removeMember(gr2);

            if (gr1 != null) gr1.remove();
            if (gr2 != null) gr2.remove();
            if (u != null) u.remove();
            save(superuser);
        }
    }
View Full Code Here

        Authorizable authrz = userManager.getAuthorizable(principal);
        if (authrz == null || authrz.isGroup()) {
            return false;
        }
        Subject impersSubject = getImpersonatorSubject(credentials);
        User user = (User) authrz;
        if (user.getImpersonation().allows(impersSubject)) {
            return true;
        } else {
            throw new FailedLoginException("attempt to impersonate denied for " + principal.getName());
        }
    }
View Full Code Here

        try {
            NodeImpl userNode = (NodeImpl) nodeCreator.createUserNode(userID, intermediatePath);
            setPrincipal(userNode, principal);
            setProperty(userNode, P_PASSWORD, getValue(UserImpl.buildPasswordValue(password)), true);

            User user = createUser(userNode);
            if (isAutoSave()) {
                session.save();
            }

            log.debug("User created: " + userID + "; " + userNode.getPath());
View Full Code Here

     *
     * @return The admin user.
     * @throws RepositoryException
     */
    private User createAdmin() throws RepositoryException {
        User admin;
        try {
            admin = createUser(adminId, adminId);
            if (!isAutoSave()) {
                session.save();
            }
View Full Code Here

        }
    }

    public void testNodeRemovedForPrincipal() throws RepositoryException, NotExecutableException {
        Principal testPrincipal = getTestPrincipal();
        final User u = getUserManager(superuser).createUser(testPrincipal.getName(), "pw");
        save(superuser);

        Path rootPath = ((SessionImpl) s).getQPath("/");
        CompiledPermissions cp = null;
        try {
            Set<Principal> principals = Collections.singleton(u.getPrincipal());
            cp = provider.compilePermissions(principals);

            assertTrue(cp.canReadAll());
            assertTrue(cp.grants(rootPath, Permission.READ));
            assertNotSame(CompiledPermissions.NO_PERMISSION, cp);
        } finally {

            // remove the user to assert that the path doesn't point to an
            // existing node any more -> userNode cannot be resolved any more -> permissions denied.
            u.remove();
            save(superuser);

            if (cp != null) {
                assertFalse(cp.canReadAll());
                assertFalse(cp.grants(rootPath, Permission.READ));
View Full Code Here

        setPrincipal(userTree, principal);
        if (password != null) {
            setPassword(userTree, password, true);
        }

        User user = new UserImpl(userID, userTree, this);
        onCreate(user, password);

        log.debug("User created: " + userID);
        return user;
    }
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.