RE: How to get impersonated user details in serve resource method ?

Olaf Kock, modified 3 Years ago. New Member Post: 1 Join Date: 6/24/22 Recent Posts

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

thumbnail
Olaf Kock, modified 3 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts

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.