RE: Impersonating friendly URLs

Jan Tošovský, modified 5 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
I am trying to pass doAsUserId param to my friendly URL .../attachment/2749384?doAsUserId=xRdO8Wv72X5YHWlYGO, but it is apparently not passed upstream.
When my route is processed and enters the serveResource() method, the user retrieved from resourceRequest is not that impersonated user, but real one.
<route>
&nbsp;&nbsp; <pattern>/attachment/{attachmentId:[^/]+}</pattern>
&nbsp;&nbsp; <implicit-parameter name="p_p_lifecycle">2</implicit-parameter>
&nbsp;&nbsp; <implicit-parameter name="p_p_cacheability">cacheLevelPage</implicit-parameter>
&nbsp;&nbsp; <implicit-parameter name="mvcPath">/attachment.jsp</implicit-parameter>
</route>
This prevents to emulate some functionality from that specific user perspective.
Is there any workaround for this?
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Jan Tošovský:

I am trying to pass doAsUserId param to my friendly URL
I probably can't help you directly, but it might help to mention the exact Liferay version. And if there's a newer GA on your major version, try if it's an issue that was already fixed.
Jan Tošovský, modified 5 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
Hi Olaf, a good point. I checked this in old 6.2 version and it works as expected there. Now I am on 7.2 GA1. So this seems to be a regression. I'll test this on some core friendly URLs if it is really global issue or just a problem of my portlet.
Jan Tošovský, modified 5 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
I fixed it. Originally this was fix for another issue, but both turned out to be related.
My resourceAction should return PNG attachment, but the content was written directly to the page as characters. After further analysis I found this binary content is wrapped by senna container so I finally found the root cause.
My links look like this: <a href=" .../attachment/2749384?doAsUserId=xRdO8Wv72X5YHWlYGO">. However, they are internally processed by SennaJS, which, in my case, breaks the original functionality.
So with the help of https://stackoverflow.com/questions/41288039/how-can-i-disable-sennajs-spa-in-liferay-7 I changed the link to <a href=" .../attachment/2749384?doAsUserId=xRdO8Wv72X5YHWlYGO" data-senna-off="true">
It not only fixed that attachment issue, but also impersonating one.