Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Girish kumar
How impersonation works in Liferay.
October 23, 2013 4:49 AM
Answer

Girish kumar

Rank: Junior Member

Posts: 27

Join Date: June 16, 2013

Recent Posts

Hi All,

When i navigate to the user and admin->when i click on the impersonate use then it navigate to the differenet tab and then it will create the doAsuserId varibable which does all these things.

I wanted to know how this variable gets created which class does it.

Thanks in advance
Krzysztof Gołębiowski
RE: How impersonation works in Liferay.
October 23, 2013 6:31 AM
Answer

Krzysztof Gołębiowski

Rank: Liferay Master

Posts: 508

Join Date: June 25, 2011

Recent Posts

Impersonation url is being generated by liferay-security:doAsURL. More specifically it is encrypted companyId (as key) and userId (as value), encoded as Base64. Line 80 of com.liferay.taglib.security.DoAsURLTag:


String encDoAsUserId = Encryptor.encrypt(
company.getKeyObj(), String.valueOf(doAsUserId));

doAsURL = HttpUtil.addParameter(doAsURL, "doAsUserId", encDoAsUserId);
Girish kumar
RE: How impersonation works in Liferay.
October 24, 2013 2:33 AM
Answer

Girish kumar

Rank: Junior Member

Posts: 27

Join Date: June 16, 2013

Recent Posts

Hi Krzysztof / All,

Thanks for this awesome explaination.

Another thing i want to know when we impersonate any user then when we perform any operation then the URL has the doAsUserId appended which means the user is in impersonated state,

Use case 1)
I have created custom portlet with the link added which is pointing to the another site public page in the portal.
a) If user is impersonated then i click on the link in the custom portlet the user does not remain in the impersonation state.

How to retain this impersation in liferay by adding the doAsUserId appened in the custom links also.

Thanks in Advance
Krzysztof Gołębiowski
RE: How impersonation works in Liferay.
October 24, 2013 7:27 AM
Answer

Krzysztof Gołębiowski

Rank: Liferay Master

Posts: 508

Join Date: June 25, 2011

Recent Posts

Hmm, I think as long as you use URL's generated by Liferay (actionUrls / renderUrls), then doAsUserId is preserved. In other cases I think you have to process it on your own.
Girish kumar
RE: How impersonation works in Liferay.
October 25, 2013 2:05 AM
Answer

Girish kumar

Rank: Junior Member

Posts: 27

Join Date: June 16, 2013

Recent Posts

Hi Krzysztof,

Thanks for sharing knowledge.
venka reddy
RE: How impersonation works in Liferay.
October 25, 2013 11:56 AM
Answer

venka reddy

Rank: Regular Member

Posts: 231

Join Date: March 23, 2011

Recent Posts

Hi Girish,

You can use below method to append impersonate parameter

PortalUtil. addPreservedParameters(themedisplay,url)

Suppose if your looks before using this method as

Before url = https://www.liferay.com/community/forums?p_p_id=19&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view

After this it looks as

Before url = https://www.liferay.com/community/forums?p_p_id=19&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&doAsUserId=.......


Hopes this helps you .

Let me know if anything required .
Girish kumar
RE: How impersonation works in Liferay.
October 28, 2013 11:46 PM
Answer

Girish kumar

Rank: Junior Member

Posts: 27

Join Date: June 16, 2013

Recent Posts

Hi Venka,

Thanks for info,

Here is the use case.
I have the custom portlets added and has the links to some of the public pages of the other site.
While at the run time when the user impersonates how to add the &doAsUserId= paramter.

Hope the use case is understood.

Thanks in Advance
Armando Sandoval
RE: How impersonation works in Liferay.
January 20, 2015 12:51 PM
Answer

Armando Sandoval

Rank: New Member

Posts: 1

Join Date: June 18, 2014

Recent Posts

Is there a way to add the preserved parameters from within the vm templates?