jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cech. Ulrich" <Ulrich.C...@aeb.de>
Subject AW: getting users
Date Wed, 30 Jun 2010 10:40:52 GMT
Hi,

here are the methods to retrieve a created user:

 
   public User getUser(Session session, String userId)
            throws RepositoryException {
        UserManager um = getUserManager(session);
        Authorizable auth = um.getAuthorizable(userId);
        if (auth instanceof User) {
            return (User) um.getAuthorizable(userId);
        } else {
            throw new RepositoryException("The userid '" + userId
                    + "' is no valid repository user.");
        }
    }    

    private UserManager getUserManager(Session session)
            throws RepositoryException {
        if (session instanceof JackrabbitSession) {
            return ((JackrabbitSession) session).getUserManager();
        } else {
            throw new RepositoryException(
                    "This JCR implementation does not have a UserManager.");
        }
    }

   public List<String> getAllRegisteredUsers(Session session)
            throws RepositoryException {
        List<String> list = new ArrayList<String>();
        int type = UserManager.SEARCH_TYPE_USER; // or group or user
        Iterator<Authorizable> auths =
                getUserManager(session).findAuthorizables("rep:principalName",
                        null, type);
        while (auths.hasNext()) {
            Authorizable authorizable = (Authorizable) auths.next();
            list.add(authorizable.getID());
        }
        return list;
    }

Bye,
Ulrich



Mime
View raw message