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

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


        UserManager userManager = AccessControlUtil.getUserManager(session);
        Authorizable authorizable = userManager.getAuthorizable(name);
        if (authorizable == null) {
            //principal does not exist yet, so create it
            Group group = userManager.createGroup(new Principal() {
                                                      public String getName() {
                                                          return name;
                                                      }
                                                  },
                hashPath(name)
            );
            authorizable = group;
        } else {
            //principal already exists, check to make sure it is the expected type
            if (!authorizable.isGroup()) {
                throw new RepositoryException("A user already exists with the requested name: " + name);
            }
            //group already exists so just update it below
        }
        //update the group members
        if (members != null) {
            Group group = (Group) authorizable;
            for (String member : members) {
                Authorizable memberAuthorizable = userManager.getAuthorizable(member);
                if (memberAuthorizable != null) {
                    group.addMember(memberAuthorizable);
                }
            }
        }
        if (extraProperties != null) {
            ValueFactory valueFactory = session.getValueFactory();
View Full Code Here


    private String[] getMemberships(Authorizable authorizable, boolean includeAll) throws RepositoryException {
        List<String> results = new ArrayList<String>();
        for (Iterator<Group> it = includeAll ? authorizable.memberOf() : authorizable.declaredMemberOf();
                it.hasNext();) {
            Group group = it.next();
            results.add(AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX + group.getID());
        }
        return results.toArray(new String[results.size()]);
    }
View Full Code Here

        groupMembers.add(user2);

        ResourceResolver resolver = mock(ResourceResolver.class);
        Resource groupRes = mock(Resource.class);
        Authorizable groupAuth = mock(Authorizable.class);
        Group userGroup = mock(Group.class);

        when(resolver.getResource(groupPath)).thenReturn(groupRes);
        when(groupRes.adaptTo(Authorizable.class)).thenReturn(groupAuth);

        when(groupAuth.isGroup()).thenReturn(true);
        when(groupRes.adaptTo(Group.class)).thenReturn(userGroup);
        when(userGroup.getMembers()).thenReturn(groupMembers.iterator());

        String[] emails = SendTemplatedEmailUtils.getEmailAddrsFromUserPath(resolver, groupPath);
        assertEquals(2, emails.length);
        assertEquals("user1@adobe.com", emails[0]);
        assertEquals("user2@adobe.com", emails[1]);
View Full Code Here

           
            if (principal != null) {
              setPrincipal(groupNode, principal);
            }

            Group group = createGroup(groupNode);
            onCreate(group);
            if (isAutoSave()) {
                session.save();
            }
View Full Code Here

    @CheckForNull
    private Group createGroup(ExternalGroup externalGroup) throws RepositoryException, SyncException {
        if (mode.contains(SyncMode.MODE_CREATE_GROUPS)) {
            // TODO: what intermediate path to use for the group creation?
            Group group = userManager.createGroup(externalGroup.getId(), externalGroup.getPrincipal(), null);
            syncAuthorizable(externalGroup, group);
            return group;
        } else {
            return null;
        }
View Full Code Here

    }

    private void syncAuthorizable(ExternalUser externalUser, Authorizable authorizable) throws RepositoryException, SyncException {
        for (ExternalGroup externalGroup : externalUser.getGroups()) {
            String groupId = externalGroup.getId();
            Group group;
            Authorizable a = userManager.getAuthorizable(groupId);
            if (a == null) {
                group = createGroup(externalGroup);
            } else {
                group = (a.isGroup()) ? (Group) a : null;
            }

            if (group != null) {
                group.addMember(authorizable);
            } else {
                log.debug("No such group " + groupId + "; Ignoring group membership.");
            }
        }
View Full Code Here

            } 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

     * @throws javax.jcr.RepositoryException
     * @throws org.apache.jackrabbit.test.NotExecutableException
     */
    public void testRemoveListedAuthorizable() throws RepositoryException, NotExecutableException {
        String newUserId = null;
        Group newGroup = null;

        try {
            Principal uP = getTestPrincipal();
            User newUser = userMgr.createUser(uP.getName(), uP.getName());
            superuser.save();
            newUserId = newUser.getID();

            newGroup = userMgr.createGroup(getTestPrincipal());
            newGroup.addMember(newUser);
            superuser.save();

            // remove the new user that is still listed as member.
            newUser.remove();
            superuser.save();
        } finally {
            if (newUserId != null) {
                Authorizable u = userMgr.getAuthorizable(newUserId);
                if (u != null) {
                    if (newGroup != null) {
                        newGroup.removeMember(u);
                    }
                    u.remove();
                }
            }
            if (newGroup != null) {
                newGroup.remove();
            }
            superuser.save();
        }
    }
View Full Code Here

    protected void setupAuthorizables() throws RepositoryException {
        for (JackrabbitSession s : writeSessions) {
            UserManager userManager = s.getUserManager();
            User user = userManager.createUser(userId, userId);

            Group group = userManager.createGroup("group1");
            group.addMember(user);

            Group group2 = userManager.createGroup("group2");
            group2.addMember(user);

            s.save();
        }
    }
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.