Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

How to fetch Users of a group, through Java code.

Avatar

Former Community Member

Hi All,

I have created a group in userAdmin and it has some users attached to it.

And in my java class I want to get the list of users attached to the group, but somehow I am not able to find any API or some way to find it out.

Finding the Group to which a user is attached I know, but dont know how to find out the list of users in a group in my java code.

Any suggestion on this will be really appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 6

Pls follow this tutorial : http://helpx.adobe.com/experience-manager/using/developing-aem-osgi-bundles-jackrabbit.html

If you want to see the group associated with user then see below - 

User currentUser = resourceResolver.adaptTo(User.class); 
Iterator<Group> currentUserGroups = currentUser.memberOf();

View solution in original post

3 Replies

Avatar

Level 8

If you the have the org.apache.jackrabbit.api.security.user.Authorizable for the group (and you are sure it's a group) you can cast to org.apache.jackrabbit.api.security.user.Group, and then call Group.getMembers. If you aren't sure it's a group you can call Authorizable.isGroup before you do the cast. 

Avatar

Level 2

Pushp Dang wrote...

And in my java class I want to get the list of users attached to the group, but somehow I am not able to find any API or some way to find it out.

Finding the Group to which a user is attached I know, but dont know how to find out the list of users in a group in my java code.

Any suggestion on this will be really appreciated.

 

If you have the group, you can use group.getMembers()   See: http://wiki.apache.org/jackrabbit/UserManagement fetch members from a group section

Zyg

Avatar

Correct answer by
Level 6

Pls follow this tutorial : http://helpx.adobe.com/experience-manager/using/developing-aem-osgi-bundles-jackrabbit.html

If you want to see the group associated with user then see below - 

User currentUser = resourceResolver.adaptTo(User.class); 
Iterator<Group> currentUserGroups = currentUser.memberOf();