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

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


                //user is allowed to update it's own properties
                return true;
            }
           
            UserManager userManager = AccessControlUtil.getUserManager(jcrSession);
            Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID());

            if (((User)currentUser).isAdmin()) {
                return true; //admin user has full control
            }

            Authorizable authorizable = userManager.getAuthorizable(principalId);
            if (authorizable instanceof User) {
                //check if the user is a member of the 'User administrator' group
                Authorizable userAdmin = userManager.getAuthorizable(this.userAdminGroupName);
                if (userAdmin instanceof Group) {
                    boolean isMember = ((Group)userAdmin).isMember(currentUser);
                    if (isMember) {
                        return true;
                    }
                }
            } else if (authorizable instanceof Group) {
                //check if the user is a member of the 'Group administrator' group
                Authorizable groupAdmin = userManager.getAuthorizable(this.groupAdminGroupName);
                if (groupAdmin instanceof Group) {
                    boolean isMember = ((Group)groupAdmin).isMember(currentUser);
                    if (isMember) {
                        return true;
                    }
View Full Code Here


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

            try {
                if (this.session instanceof JackrabbitSession && session.getUserID() != null) {
                    JackrabbitSession s =((JackrabbitSession) this.session);
                    final UserManager um = s.getUserManager();
                    if (um != null) {
                        final Authorizable auth = um.getAuthorizable(s.getUserID());
                        if (auth != null) {
                            return (AdapterType) auth.getPrincipal();
                        }
                    }
                }
                log.debug("not able to adapto Resource to Principal, let the base class try to adapt");
            } catch (RepositoryException e) {
View Full Code Here

        final Node parentNode = this.parentNodeStack.peek();
        Session session = parentNode.getSession();

        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);
                }
            }
        }
View Full Code Here

    public void createUser(final String name, String password, Map<String, Object> extraProperties) throws RepositoryException {
        final Node parentNode = this.parentNodeStack.peek();
        Session session = parentNode.getSession();

        UserManager userManager = AccessControlUtil.getUserManager(session);
        Authorizable authorizable = userManager.getAuthorizable(name);
        if (authorizable == null) {
            //principal does not exist yet, so create it
            User user = userManager.createUser(name,
                password,
                new Principal() {
                    public String getName() {
                        return name;
                    }
                },
                hashPath(name)
            );
            authorizable = user;
        } else {
            //principal already exists, check to make sure it is the expected type
            if (authorizable.isGroup()) {
                throw new RepositoryException("A group already exists with the requested name: " + name);
            }
            //user already exists so just update it below
        }
        if (extraProperties != null) {
            ValueFactory valueFactory = session.getValueFactory();
            Set<Entry<String, Object>> entrySet = extraProperties.entrySet();
            for (Entry<String, Object> entry : entrySet) {
                Value value = createValue(valueFactory, entry.getValue());
                authorizable.setProperty(entry.getKey(), value);
            }
        }
    }
View Full Code Here

      Class<AdapterType> type) {
      if ( session instanceof JackrabbitSession) {
        String userID = session.getUserID();
        JackrabbitSession jrSession = (JackrabbitSession) session;
        try {
          Authorizable authorizable = jrSession.getUserManager()
              .getAuthorizable(userID);
          String userHome = authorizable.getPath();

          // tries to get tenant information from user home
          // i.e. /home/users/tenant1/a/admin
          return getAdapter(userHome, type);
        } catch (Exception e) {
View Full Code Here

     *             or an error occurrs looking for the user
     */
    private org.apache.jackrabbit.api.security.user.User getRepoUser(final String name, final ResourceResolver admin) throws FtpException {
        org.apache.jackrabbit.api.security.user.UserManager um = admin.adaptTo(org.apache.jackrabbit.api.security.user.UserManager.class);
        if (um != null) {
            Authorizable a;
            try {
                a = um.getAuthorizable(name);
                return (a != null && !a.isGroup()) ? (org.apache.jackrabbit.api.security.user.User) a : null;
            } catch (RepositoryException e) {
                throw new FtpException(e);
            }
        }
        throw new FtpException("Missing internal user manager; cannot find user");
View Full Code Here

    protected User getUser(final String userId) {
        logger.info("getting user with id '{}'", userId);
        try {
            final Session session = getSession();
            final UserManager userManager = getUserManager(session);
            final Authorizable authorizable = userManager.getAuthorizable(userId);
            if (authorizable != null) {
                if (authorizable instanceof User) {
                    final User user = (User) authorizable;
                    logger.debug("user for id '{}' found", userId);
                    return user;
                } else {
                    logger.debug("found authorizable with id '{}' is not an user", authorizable.getID());
                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
View Full Code Here

        String userPath = "/home/users/a/admin";
        MockValue[] emailVal = new MockValue[] { new MockValue("admin@adobe.com") };

        ResourceResolver resolver = mock(ResourceResolver.class);
        Resource userRes = mock(Resource.class);
        Authorizable adminUser = mock(Authorizable.class);

        when(resolver.getResource(userPath)).thenReturn(userRes);
        when(userRes.adaptTo(Authorizable.class)).thenReturn(adminUser);

        when(adminUser.isGroup()).thenReturn(false);
        when(adminUser.hasProperty(PN_EMAIL)).thenReturn(true);
        when(adminUser.getProperty(PN_EMAIL)).thenReturn(emailVal);

        String[] emails = SendTemplatedEmailUtils.getEmailAddrsFromUserPath(resolver, userPath);

        assertEquals(1, emails.length);
        assertEquals("admin@adobe.com", emails[0]);
View Full Code Here

        // mock group and users
        String groupPath = "/home/users/g/group";
        List<Authorizable> groupMembers = new ArrayList<Authorizable>();

        Authorizable user1 = mock(Authorizable.class);
        Authorizable user2 = mock(Authorizable.class);

        when(user1.hasProperty(PN_EMAIL)).thenReturn(true);
        when(user1.getProperty(PN_EMAIL)).thenReturn(new MockValue[] { new MockValue("user1@adobe.com") });

        when(user2.hasProperty(PN_EMAIL)).thenReturn(true);
        when(user2.getProperty(PN_EMAIL)).thenReturn(new MockValue[] { new MockValue("user2@adobe.com") });

        groupMembers.add(user1);
        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);
View Full Code Here

TOP

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

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.