How to get permission of current user in servlet? | Community
Skip to main content
bhoang
Level 4
July 10, 2018
Solved

How to get permission of current user in servlet?

  • July 10, 2018
  • 6 replies
  • 5723 views

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

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 BrijeshYadav

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 Users and Groups

/Brijesh Yadav

6 replies

BrijeshYadav
BrijeshYadavAccepted solution
Level 5
July 10, 2018

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 Users and Groups

/Brijesh Yadav

arunpatidar
Community Advisor
Community Advisor
July 10, 2018

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
bhoang
bhoangAuthor
Level 4
July 10, 2018

Thanks for your helps,

I will try it.

Thank you so much,

BienHV

bhoang
bhoangAuthor
Level 4
July 11, 2018

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!

arunpatidar
Community Advisor
Community Advisor
July 11, 2018

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
bhoang
bhoangAuthor
Level 4
July 30, 2018

Thank you for your help.