Search code examples
jbossjboss-portal

Accessing a list of users through JBoss in a non-admin role?


We would like to make a list of users available in a portlet similar to the admin version of the UsersPortlet, but for those that aren't admins. This list would be names only. Is there a way to do this through JBoss GA 4.2.2? We are currently developing on the Hypersonic DB, but I would hope there is a DB independent way to do this through JBoss.


Solution

  • We found the Identity Manager and its associated classes. Using the default configurations source code can be:

    import org.jboss.portal.identity.UserModule;
    import org.jboss.portal.identity.RoleModule;
    import org.jboss.portal.identity.MembershipModule;
    import org.jboss.portal.identity.UserProfileModule;
    
    [...]
    
    (UserModule)new InitialContext().lookup("java:portal/UserModule");
    RoleModule rm = (RoleModule)new InitialContext().lookup("java:portal/RoleModule");
    (MembershipModule)new InitialContext().lookup("java:portal/MembershipModule");
    (UserProfileModule)new InitialContext().lookup("java:portal/UserProfileModule");
    
    rm.findRoles()
    

    A critical gotcha that got us is that for the InitialContext to be properly populated this must occur in a transaction. That means if you are using RichFaces this can't take place in the underlying beans.