Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Impersonate a User From a Backend Custom Service

Avatar

Level 3

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

Avatar

Correct answer by
Community Advisor

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

Avatar

Correct answer by
Community Advisor

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. 

Avatar

Level 3

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?

Avatar

Level 3

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