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

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


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


                fail("removing the '" + pName + "' property on a User should fail.");
            } catch (RepositoryException e) {
                // success
            }
        }
        Group g = getTestGroup(superuser);
        for (String pName : protectedGroupProps) {
            try {
                g.removeProperty(pName);
                save(superuser);
                fail("removing the '" + pName + "' property on a Group should fail.");
            } catch (RepositoryException e) {
                // success
            }
View Full Code Here

            }
        }
    }

    public void testFindGroup() throws RepositoryException, NotExecutableException {
        Group gr = null;
        try {
            Principal p = getTestPrincipal();
            gr = userMgr.createGroup(p);
            save(superuser);

            boolean found = false;
            Iterator<Authorizable> it = userMgr.findAuthorizables(pPrincipalName, null, UserManager.SEARCH_TYPE_GROUP);
            while (it.hasNext() && !found) {
                Group ng = (Group) it.next();
                found = ng.getPrincipal().getName().equals(p.getName());
            }
            assertTrue("Searching for \"\" must find the created group.", found);

            it = userMgr.findAuthorizables(pPrincipalName, p.getName(), UserManager.SEARCH_TYPE_GROUP);
            assertTrue(it.hasNext());
            Group ng = (Group) it.next();
            assertEquals("Searching for principal-name must find the created group.", p.getName(), ng.getPrincipal().getName());
            assertFalse("Only a single group must be found for a given principal name.", it.hasNext());

            // but search users should not find anything
            it = userMgr.findAuthorizables(pPrincipalName, p.getName(), UserManager.SEARCH_TYPE_USER);
            assertFalse(it.hasNext());
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

    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

        if (refs != null) {
            while (refs.hasNext()) {
                try {
                    NodeImpl n = (NodeImpl) refs.nextProperty().getParent();
                    if (n.isNodeType(NT_REP_GROUP)) {
                        Group group = userManager.createGroup(n);
                        // only retrieve indirect membership if the group is not
                        // yet present (detected eventual circular membership).
                        if (groups.add(group) && includeIndirect) {
                            ((AuthorizableImpl) group).collectMembership(groups, true);
                        }
                    } else {
                        // weak-ref property 'rep:members' that doesn't reside under an
                        // group node -> doesn't represent a valid group member.
                        log.debug("Invalid member reference to '" + this + "' -> Not included in membership set.");
                    }
                } catch (ItemNotFoundException e) {
                    // group node doesn't exist  -> -> ignore exception
                    // and skip this reference from membership list.
                } catch (AccessDeniedException e) {
                    // not allowed to see the group node -> ignore exception
                    // and skip this reference from membership list.
                }
            }
        } else {
            // workaround for failure of Node#getWeakReferences
            // traverse the tree below groups-path and collect membership manually.
            log.info("Traversing groups tree to collect membership.");
            ItemVisitor visitor = new TraversingItemVisitor.Default() {
                @Override
                protected void entering(Property property, int level) throws RepositoryException {
                    PropertyImpl pImpl = (PropertyImpl) property;
                    NodeImpl n = (NodeImpl) pImpl.getParent();
                    if (P_MEMBERS.equals(pImpl.getQName()) && n.isNodeType(NT_REP_GROUP)) {
                        for (Value value : property.getValues()) {
                            if (value.getString().equals(node.getIdentifier())) {
                                Group gr = (Group) userManager.getAuthorizable(n);
                                groups.add(gr);
                            }
                        }
                    }
                }
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<String, Authorizable>();
                    for (Iterator<Authorizable> declMembers = gr.getDeclaredMembers(); declMembers.hasNext();) {
                        Authorizable dm = declMembers.next();
                        toRemove.put(dm.getID(), dm);
                    }

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

                    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("New member of " + gr + ": No such authorizable (NodeID = " + id + ")");
                            if (importBehavior == ImportBehavior.BESTEFFORT) {
                                log.info("ImportBehavior.BESTEFFORT: Remember non-existing member for processing.");
                                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

        try {
            String groupID = getGroupId(principal.getName());
            NodeImpl groupNode = (NodeImpl) nodeCreator.createGroupNode(groupID, intermediatePath);
            setPrincipal(groupNode, principal);

            Group group = createGroup(groupNode);
            if (isAutoSave()) {
                session.save();
            }

            log.debug("Group created: " + groupID + "; " + groupNode.getPath());
View Full Code Here

                    used to deliver principals with this provider implementation.
                    */
                    addToCache(auth.getPrincipal());
                    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

            intermediatePath = namePathMapper.getOakPathKeepIndex(intermediatePath);
        }
        Tree groupTree = userProvider.createGroup(groupID, intermediatePath);
        setPrincipal(groupTree, principal);

        Group group = new GroupImpl(groupID, groupTree, this);
        onCreate(group);

        log.debug("Group created: " + groupID);
        return group;
    }
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.