RE: Impersonation in REST API Application

Axel LEFEVRE, modified 5 Years ago. Junior Member Posts: 25 Join Date: 2/18/20 Recent Posts
Hi,

I want to get the username of the user connected to Liferay as well as the username usurped in my backend REST API Liferay application.

I saw this information is only accessible via the ThemeDisplay object, but I cannot get the content of this object in the method of my API, it is always null.

Is there another way to access this data? Currently I am using PortalUtil.getUser(httpServletRequest), but it still gives me the same username with or without usurpation.

Thanks for your help
Sarath Chandra, modified 5 Years ago. New Member Posts: 9 Join Date: 10/28/19 Recent Posts
Can you please elaborate, or put some code snippets? It's too hard to understand from what you said. 
thumbnail
Christoph Rabel, modified 5 Years ago. Liferay Legend Posts: 1555 Join Date: 9/24/09 Recent Posts
Do you attach the &doAsUserId=<ID> to the rest request? If it is there, it should work. You can get the real user id with this call:
long actingUserId = AuditRequestThreadLocal.getAuditThreadLocal().getRealUserId();
To make this more convenient, I have also created a feature request, but currently you are stuck with adding doAsUserId to each rest request.
https://issues.liferay.com/browse/LPS-100098