How to fetch Users of a group, through Java code. | Community
Skip to main content
October 16, 2015
Solved

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

  • October 16, 2015
  • 3 replies
  • 6204 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sam205505050

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();

3 replies

Level 8
October 16, 2015

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. 

Adobe Employee
October 16, 2015

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

Sam205505050Accepted solution
Level 6
October 16, 2015

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();