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: How to get impersonated user details in serve resource method ?
I am trying to get impersonated user details inside a resource command class, where request comes from a react portlet. Below is my code, but it's not working as expected. I am using Liferay 7.2 version
ThemeDisplay themeDisplay = (ThemeDisplay)resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
String email = "";
if(themeDisplay.isImpersonated()){
_log.debug("HimsCansWebResourceCommand User impersonated ");
email=themeDisplay.getUser().getEmailAddress();
String userId=themeDisplay.getDoAsUserId();
}else{
_log.debug("HimsCansWebResourceCommand User not impersonated ");
email=themeDisplay.getRealUser().getEmailAddress();
}
It's working in view.jsp or inside a render method, but not in a serve resource method where request comes from a react portlet
How do you build the URL? Make sure it contains a doAsUserId (or similar) parameter: If that parameter isn't there, there's no need to check server-side code. It simply would be a URL that's not impersonating anyone.