Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Yves LeGrand
Using a different user context in Liferay
February 29, 2012 3:42 AM
Answer

Yves LeGrand

Rank: Regular Member

Posts: 158

Join Date: November 18, 2009

Recent Posts

Hello Liferay.

Is it possible to use a different user in using the API?
For instance, we want to get all layouts within the navigation.
Some layouts won't have the VIEW Action enabled for the guest user so the guest user won't see these pages in the navigation, too.
But these layouts should be shown within the navigation maybe with a little lock icon.

So is it possible to change a users context to a certain kind of user, lets say a navigation user which owns the appropriate permissions?

Please let me know.

Thanks a lot in advance.

Best regards,
Yves
Yves LeGrand
RE: Using a different user context in Liferay
February 29, 2012 6:41 AM
Answer

Yves LeGrand

Rank: Regular Member

Posts: 158

Join Date: November 18, 2009

Recent Posts

I need to mention we want to use this context change within a service implementation.

Thanks,
Yves
Mika Koivisto
RE: Using a different user context in Liferay
March 1, 2012 2:01 PM
Answer

Mika Koivisto

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1498

Join Date: August 7, 2006

Recent Posts

Something like this could work:

 1String currentPrincipalName = PrincipalThreadLocal.getName();
 2
 3try {
 4    PrincipalThreadLocal.setName(fakeUserId);
 5
 6    // do something
 7}
 8finally {
 9    PrincipalThreadLocal.setName(currentPrincipalName);
10}