Fórumok

set user role via code

thumbnail
Markus Krause, módosítva 10 év-val korábban

set user role via code

New Member Bejegyzések: 13 Csatlakozás dátuma: 2012.08.14. Legújabb bejegyzések
Dear all,

we have a liferay portal with some static content and several portlets which we allow access to using user roles. these roles are assign by group memberships synchronized from LDAP. This all works quite well.
Now I need an extension to this: based on some "java logic" I need to assign / modify the role of a guest user (not logged in) and change it to "special_guest".
How can I asign a role to a not-logged in user?
In particular I need to do this adding this information to the servletresponse/servletrequest as I want to set this via a servlet filter (which already is doing what I need).

thanks in advance for any hints or ideas to solve this!

regards,
Markus
thumbnail
Pankaj Kathiriya, módosítva 10 év-val korábban

RE: set user role via code

Liferay Master Bejegyzések: 722 Csatlakozás dátuma: 2010.08.05. Legújabb bejegyzések
In Liferay, database entry for Guest user is as default@liferay.com in user_ table.

This is Guest user with GUEST role.

Now, if you want to assign Guest user any other role then you can do it by UserLocalServiceUtil.addRoleUsers(roleId, new long[]{userId}).
Here userId is userId for default@liferay.com and roleId is of Role you want to assign to Guest User.

HTH,
Thanks,
Pankaj
thumbnail
Markus Krause, módosítva 10 év-val korábban

RE: set user role via code

New Member Bejegyzések: 13 Csatlakozás dátuma: 2012.08.14. Legújabb bejegyzések
Dear Pankaj,

thanks for your answer.
As far as I understand this would change the role for any guest user, right?

Actually what I want to do is set the role of a user depending on the subnet where his request is coming from.
Let me explain in more detail what I want to achieve: on our liferay based web site we want to display little information to guests (non authenticated users from any where out there), many information to users who did authenticate. In addition I need to show some internal information to users from our local LAN which are not authenticated (e.g. where to get an account etc.), I'll call them "campus guest".
So what I am seeking for is to set a users role from "guest" to "campus guest" depending on his remote address. I already figured out how to get this information on every request by using a servlet filter but I did not find a way to assign a role to a "user session without authentication". Can this be achieved using liferay anyway? Or is there even a better way to achieve this?

Thanks in advance for your help (or any others how will share their wisdom ;-) )

kind regards,
Markus