Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Admin User/ Administrator Group

Avatar

Avatar
Validate 1
Level 2
ashwiniv5325199
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 2
ashwiniv5325199
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
ashwiniv5325199
Level 2

08-01-2019

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

Replies

Avatar

Avatar
Boost 1
Employee
amitgupta_adbe
Employee

Likes

2 likes

Total Posts

26 posts

Correct Reply

8 solutions
Top badges earned
Boost 1
Affirm 5
Affirm 3
Affirm 1
View profile

Avatar
Boost 1
Employee
amitgupta_adbe
Employee

Likes

2 likes

Total Posts

26 posts

Correct Reply

8 solutions
Top badges earned
Boost 1
Affirm 5
Affirm 3
Affirm 1
View profile
amitgupta_adbe
Employee

08-01-2019

Avatar

Avatar
Validate 1
Level 2
ashwiniv5325199
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 2
ashwiniv5325199
Level 2

Like

1 like

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
ashwiniv5325199
Level 2

08-01-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

Avatar

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile
Gaurav-Behl
MVP

08-01-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)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

08-01-2019

Avatar

Avatar
Validate 1
Level 10
edubey
Level 10

Likes

276 likes

Total Posts

1,502 posts

Correct Reply

392 solutions
Top badges earned
Validate 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Validate 1
Level 10
edubey
Level 10

Likes

276 likes

Total Posts

1,502 posts

Correct Reply

392 solutions
Top badges earned
Validate 1
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
edubey
Level 10

08-01-2019

Make sure to user current user session

Session userSession = slingRequest.getResourceResolver().adaptTo(Session.class);

final UserManager userManager = slingRequest.getResourceResolver().adaptTo(UserManager.class);

final User user = (User) userManager.getAuthorizable(userSession.getUserID());

Boolean isadmin = user.isAdmin()

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

08-01-2019

We have many AEM articles that show use of using a System user - ie - Scott's Digital Community: Querying Adobe Experience Manager 6.4 JCR data

That is your issue. You should be using a System user.