Views
Replies
Total Likes
It's great that the response from this thread showcases solutions for how to programmatically check if a user belongs to the administrator's group, but however, you can manually check this in the UI as well.
1. visit: localhost:4502/useradmin
2. search for the group administrators
3. click on members; you should be able to see all the members here who are associated with the administrator's group.
Hi @akshaybhujbale,
Assuming you would like to do it programmatically you can use classes from org.apache.jackrabbit.api.security.user package. Mainly it will be UserManager, Authorizable, User and Group.
import org.apache.jackrabbit.api.security.user.*;
UserManager userManager = resourceResolver.adaptTo(UserManager.class); User user = (User) userManager.getAuthorizable("test-user"); user.isAdmin();
import org.apache.jackrabbit.api.security.user.*; UserManager userManager = resourceResolver.adaptTo(UserManager.class); User user = (User) userManager.getAuthorizable("test-user"); Group group = (Group) userManager.getAuthorizable("administrators"); group.isMember(user);second option for the same
import org.apache.jackrabbit.api.security.user.*; UserManager userManager = resourceResolver.adaptTo(UserManager.class); User user = (User) userManager.getAuthorizable("test"); Iterator<Group> groups = user.memberOf(); while (groups.hasNext()) { Group group = groups.next(); if (group.getID().equals("administrators")) { break; } }
In general memberOf will return all groups hierarchy so even if user is not directly assigned to administrators group but is member of other group that is added to administrators group you will get appropriate result.
To check user is admin
UserManager userManager = resourceResolver.adaptTo(UserManager.class); User user = (User) userManager.getAuthorizable("myuser"); user.isAdmin(); // returns true if myuser is admin
To check user is part of administrative group
Group group = (Group) userManager.getAuthorizable("administrators"); group.isMember(user);// true if the Authorizable to test is a direct or indirect member
Hi @HeenaMadan
Do you what is logic behind
user.isAdmin();
like what is check it check if the user is admin user or not.
Check User belongs to which Group -> Check Group Permission from User/Group Console to Identify.
Configure user and group (Older version of AEM)
It's great that the response from this thread showcases solutions for how to programmatically check if a user belongs to the administrator's group, but however, you can manually check this in the UI as well.
1. visit: localhost:4502/useradmin
2. search for the group administrators
3. click on members; you should be able to see all the members here who are associated with the administrator's group.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies