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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Impersonate a User From a Backend Custom Service

gauravs23
Level 2
Level 2

We have a custom service which is supposed to send emails to the end users (user data is saved in AEM) whenever a file stored in DAM is modified or a new file is uploaded under a certain DAM location. So, we are using event handler for catching the add/edit event, however, the email should be sent to the end users ONLY if the user has access to that file as per their assigned permissions through groups. So, in our even handler we need to first impersonate the user and then get the session of the impersonated user in order to check if that user has permissions to the file or not.

 

We are looking for any ideas on how to impersonate a user using code in an AEM service.

1 Accepted Solution
SivaPrasadReddyS
Correct answer by
Level 7
Level 7

Hi @gauravs23 

Please check below thread and see if that works :

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/api-to-check-user-access-t...

 

Note: Also, please use latest APIs. 

View solution in original post

4 Replies
SivaPrasadReddyS
Correct answer by
Level 7
Level 7

Hi @gauravs23 

Please check below thread and see if that works :

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/api-to-check-user-access-t...

 

Note: Also, please use latest APIs. 

View solution in original post

gauravs23
Level 2
Level 2

Thanks SivaPrasad for pointing me to the right thread. The solution provided there works.

 

However, it works only with admin resource resolver but not with any service resource resolver as it gives an error "Impersonation not allowed" even though the service user being used has jcr:all rights on /home.

 

Do you know if we are forced to use admin resolver if we want to do impersonation?

gauravs23
Level 2
Level 2

Yes, that's what I thought too and was looking for another opinion on the same. Thanks for all the help SivaPrasad.