Expand my Community achievements bar.

SOLVED

How to get permission of current user in servlet?

Avatar

Level 4

Hi friends,

In my AEM, I created some user groups (ex: my-group-1, my-group-2, my-group-3, my-group-4, etc). So, I create some users (ex: my-user-1, my-user-2, my-user-3) and add the user into some groups. Example:

my-user-1 in groups: my-group-1 , my-group-2, my-group-3

my-user-2 in groups: my-group-2 , my-group-3

Now, I want to create a Servlet to get all group of the current user that have a permission. Example, when I login to AEM with my-user-1. I will get a result with (my-group-1 , my-group-2, my-group-3). If I login to AEM with my-user-2, I will get a result with (my-group-2 , my-group-3).

How to do that?

Please, help me with a simple servlet.

Thank you so much,

BienHV

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You can use UserManager API ( UserManager (Apache Jackrabbit 2.12.9 API) ) for working with user and groups
Here is example of servlet in which UserManager API has used .
Adobe Experience Manager Help | Using Jackrabbit UserManager APIs to create Adobe Experience Manager...

/Brijesh Yadav

View solution in original post

6 Replies

Avatar

Correct answer by
Community Advisor

You can use UserManager API ( UserManager (Apache Jackrabbit 2.12.9 API) ) for working with user and groups
Here is example of servlet in which UserManager API has used .
Adobe Experience Manager Help | Using Jackrabbit UserManager APIs to create Adobe Experience Manager...

/Brijesh Yadav

Avatar

Community Advisor

Hi,

You can check below Servlet which get Groups for current user

aem63app-repo/SimpleGetGroup.java at master · arunpatidar02/aem63app-repo · GitHub

Thanks

Arun



Arun Patidar

Avatar

Level 4

Thanks for your helps,

I will try it.

Thank you so much,

BienHV

Avatar

Level 4

Hi,

I was created a simple server let to get user groups. I can get userId, but I don't know how to get user groups. Could you help me how to do that?

 

Thank you so much!

Avatar

Community Advisor

Hi,

did you check the code which I shared?

you can easily get user group from user

Example :

User currentUser = request.getResourceResolver().adaptTo(User.class);

  Iterator<Group> currentUserGroups = currentUser.memberOf();

  while (currentUserGroups.hasNext()) {

  Group grp = (Group) currentUserGroups.next();

  groupName = grp.getID();

  hmap.put("groupName", groupName);

  }

Thanks
Arun



Arun Patidar