Foros de discusión

How can I retrieve Inherited Roles?

Edgar G., modificado hace 12 años.

How can I retrieve Inherited Roles?

New Member Mensajes: 23 Fecha de incorporación: 24/10/11 Mensajes recientes
Hello,

I am currently using the following code to get the user roles

#set ($roles = $serviceLocator.findService("com.liferay.portal.service.RoleService").getUserRoles($user_id))


However, the list returned does not include inherited roles (which can be inherited by being a member of a user group).

The following only returns an empty list

 $serviceLocator.findService("com.liferay.portal.service.RoleService").getUserGroupRoles($user_id,$group_id)


Does anyone know how to get inherited roles? I'm using Liferay 6.0 SP2.

Thanks,
Edgar
thumbnail
Hitoshi Ozawa, modificado hace 12 años.

RE: How can I retrieve Inherited Roles?

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Instead of getting user roles, I just usually use hasUserRoles to check if the user has a role or not.

hasUserRoles(long userId, long companyId, String[] names, boolean inherited)

You'll need to get roles names, you'll be able to loop through the roles and test each one if the user has inherited it or not.
Edgar G., modificado hace 12 años.

RE: How can I retrieve Inherited Roles?

New Member Mensajes: 23 Fecha de incorporación: 24/10/11 Mensajes recientes
Thanks Hitoshi,

It seems like that is an easy way to check if a user has an inherited role.

Does setting the boolean "inherited" equal to true mean that you want to include all inherited roles?
Edgar G., modificado hace 12 años.

RE: How can I retrieve Inherited Roles?

New Member Mensajes: 23 Fecha de incorporación: 24/10/11 Mensajes recientes
If the role (String name) doesn't exist then an exception is thrown. Would you happen to know how to setup a try catch block within velocity?
thumbnail
David H Nebinger, modificado hace 12 años.

RE: How can I retrieve Inherited Roles?

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Most of the time when I'm working in Velocity I'll implement a facade layer in Java for the services I need to access. It's typically a lot easier to deal with things that way. Your facade can handle the try/catch stuff, conversions between lists/arrays, etc. Much easier (IMHO) than trying to deal w/ the issues in Velocity.