Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Impersonation in REST API Application
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
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
Can you please elaborate, or put some code snippets? It's too hard to understand from what you said.
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
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
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™