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

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


            }
        }

        // assume administrators groupID and principalName are the same.
        // and avoid retrieving group by principal.
        Group admins = (Group) userManager.getAuthorizable(SecurityConstants.ADMINISTRATORS_NAME);
        if (admins == null) {
            admins = userManager.createGroup(new PrincipalImpl(SecurityConstants.ADMINISTRATORS_NAME));
            if (!userManager.isAutoSave()) {
                session.save();
            }
            log.info("... created administrators group with name '"+SecurityConstants.ADMINISTRATORS_NAME+"'");
        }

        try {
            if (admins != null && admins.addMember(admin)) {
                if (!userManager.isAutoSave()) {
                    session.save();
                }
                log.info("... added admin '" + adminId + "' as member of the administrators group.");
            }
View Full Code Here


            }
        } finally {
            Authorizable a = userMgr.getAuthorizable(otherUID);
            if (a != null) {
                for (Iterator<Group> it = a.memberOf(); it.hasNext();) {
                    Group gr = it.next();
                    if (!gr.getPrincipal().equals(EveryonePrincipal.getInstance())) {
                        gr.removeMember(a);
                    }
                }
                a.remove();
            }
            a = userMgr.getAuthorizable(uID);
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));
            // conditial save call omitted.
        } catch (RepositoryException e) {
            // success as well.
        } finally {
            // clean up using the superuser
View Full Code Here

        User parentUser = (User) umgr.getAuthorizable(uID);
        if (parentUser == null) {
            throw new NotExecutableException();
        } else {
            Group gr = getGroupAdminGroup(umgr);
            try {
                assertFalse("A UserAdmin must not be allowed to modify group memberships", gr.addMember(parentUser));
            } catch (RepositoryException e) {
                // success
            }
        }

        Principal cp = getTestPrincipal();
        User childU = null;
        try {
            childU = umgr.createUser(cp.getName(), buildPassword(cp));
            save(otherSession);

            Group gr = getGroupAdminGroup(umgr);
            try {
                assertFalse("A UserAdmin must not be allowed to modify group " +
                        "memberships", gr.addMember(childU));
                // con-save call omitted.
            } catch (RepositoryException e) {
                // success
            }
        } finally {
View Full Code Here

    public void testCreateGroup() throws RepositoryException, NotExecutableException {
        UserManager umgr = getUserManager(otherSession);
        String grId = null;
        try {
            Group testGroup = umgr.createGroup(getTestPrincipal());
            save(otherSession);
            grId = testGroup.getID();

            fail("UserAdmin should not be allowed to create a new Group.");

        } catch (RepositoryException e) {
            // success.
View Full Code Here

    public void testCreateGroupWithIntermediatePath() throws RepositoryException, NotExecutableException {
        UserManager umgr = getUserManager(otherSession);
        String grId = null;
        try {
            Group testGroup = umgr.createGroup(getTestPrincipal(), "/any/intermediate/path");
            save(otherSession);
            grId = testGroup.getID();

            fail("UserAdmin should not be allowed to create a new Group with intermediate path.");

        } catch (RepositoryException e) {
            // success.
View Full Code Here

        }
    }

    public void testRemoveGroup() throws NotExecutableException, RepositoryException {
        UserManager umgr = getUserManager(otherSession);
        Group g = null;
        try {
            g = userMgr.createGroup(getTestPrincipal());
            save(superuser);

            umgr.getAuthorizable(g.getID()).remove();
            save(otherSession);

            fail("UserAdmin should not be allowed to remove a Group.");
        } catch (RepositoryException e) {
            // success.
        } finally {
            if (g != null) {
                g.remove();
                save(superuser);
            }
        }
    }
View Full Code Here

        }
    }

    public void testAddToGroup() throws NotExecutableException, RepositoryException {
        UserManager umgr = getUserManager(otherSession);
        Group gr = getGroupAdminGroup(umgr);

        Authorizable auth = umgr.getAuthorizable(uID);
        try {
            assertFalse(gr.addMember(auth));
            // omit cond-save call.
        } catch (AccessDeniedException e) {
            // success as well.
        }

        auth = umgr.getAuthorizable(otherUID);
        try {
            assertFalse(gr.addMember(auth));
            // omit cond-save call.
        } catch (AccessDeniedException e) {
            // success as well.
        }

        // not even user-admin group
        gr = (Group) umgr.getAuthorizable(uAdministrators.getID());
        auth = umgr.getAuthorizable(otherUID);
        try {
            assertFalse(gr.addMember(auth));
            // omit cond-save call.
        } catch (AccessDeniedException e) {
            // success
        }
    }
View Full Code Here

                final Authorizable auth = userManager.getAuthorizable(princ);
                if (auth != null) {
                    addToCache(princ);
                    Iterator<Group> itr = auth.memberOf();
                    while (itr.hasNext()) {
                        Group group = itr.next();
                        Principal gp = group.getPrincipal();
                        addToCache(gp);
                        membership.add(gp);
                    }
                } else {
                    log.debug("Cannot find authorizable for principal " + princ.getName());
View Full Code Here

                    Authorizable a = userManager.getAuthorizable(((Membership) reference).groupId);
                    if (a == null || !a.isGroup()) {
                        throw new RepositoryException(((Membership) reference).groupId + " does not represent a valid group.");
                    }

                    Group gr = (Group) a;
                    // 1. collect members to add and to remove.
                    Map<String, Authorizable> toRemove = new HashMap();
                    for (Iterator<Authorizable> aIt = gr.getDeclaredMembers(); it.hasNext();) {
                        Authorizable dm = aIt.next();
                        toRemove.put(dm.getID(), dm);
                    }

                    List<Authorizable> toAdd = new ArrayList();
                    List<Value> nonExisting = new ArrayList();

                    for (NodeId originalId : ((Membership) reference).ids) {

                        NodeId remapped = referenceTracker.getMappedId(originalId);
                        NodeId id = (remapped == null) ? originalId : remapped;

                        Authorizable authorz = null;
                        try {
                            NodeImpl n = ((SessionImpl) session).getNodeById(id);
                            authorz = userManager.getAuthorizable(n);
                        } catch (RepositoryException e) {
                            // no such node or failed to retrieve authorizable
                            // warning is logged below.
                        }
                        if (authorz != null) {
                            if (toRemove.remove(authorz.getID()) == null) {
                                toAdd.add(authorz);
                            } // else: no need to remove from rep:members
                        } else {
                            handleFailure("Ignoring new member of " + gr + ". No such authorizable (NodeID = " + id + ")");
                            if (importBehavior == ImportBehavior.BESTEFFORT) {
                                nonExisting.add(session.getValueFactory().createValue(id.toString(), PropertyType.WEAKREFERENCE));
                            }
                        }
                    }

                    // 2. adjust members of the group
                    for (Authorizable m : toRemove.values()) {
                        if (!gr.removeMember(m)) {
                            handleFailure("Failed remove existing member (" + m + ") from " + gr);
                        }
                    }
                    for (Authorizable m : toAdd) {
                        if (!gr.addMember(m)) {
                            handleFailure("Failed add member (" + m + ") to " + gr);
                        }
                    }

                    // handling non-existing members in case of best-effort
View Full Code Here

TOP

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

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.