Skip to main content
New Participant
January 8, 2019

Admin User/ Administrator Group

  • January 8, 2019
  • 6 replies
  • 10519 views

Hi All,

            How to authenticate whether the logged user is admin or belong to administrator group or not in a servlet?

Thanks & Regards,

Ashwini V

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

6 replies

arunpatidar
New Participant
January 8, 2019
amitgupta_adbe
Employee
January 8, 2019
New Participant
January 8, 2019

Thanks for the response

How to use the session and authenicate the current user is admin or whether the user belong to administrator group?

Because using the below code , it is giving NULL POINTER exception

ResourceResolver resourceResolver = resourceFactory.getAdministrativeResourceResolver(null);   

Session session = resourceResolver.adaptTo(Session.class);

UserManager currentUser = resourceResolver.adaptTo(UserManager.class);

Please suggest some other code to resolve this issue

Thanks & Regards,

Ashwini

Gaurav-Behl
New Participant
January 8, 2019

Admin session is not recommended in 6.x. Use service users to get the session and thereby current user's properties. You can get groups within Authorizable. You may have to modify the code based on AEM version that you use.

something like

Session session = resourceResolver.adaptTo(Session.class);

UserManager userManager = resourceResolver.adaptTo(UserManager.class);

Authorizable auth = userManager.getAuthorizable(session.getUserID());

Iterator<Group> groups = auth.memberOf();

or

      

  //Create a UserManager instance from the session object

  UserManager userManager = ((JackrabbitSession) session).getUserManager();

users= userManager.findAuthorizables("jcr:primaryType", "rep:User");

Refer:

Adobe CQ/Adobe AEM: How to Use Sessions and Resource Resolver through Service Authentication In AEM6

Service Users in AEM

Apache Sling :: Managing users and groups (jackrabbit.usermanager)