Foren

How can I retrieve Inherited Roles?

Edgar G., geändert vor 12 Jahren.

How can I retrieve Inherited Roles?

New Member Beiträge: 23 Beitrittsdatum: 24.10.11 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: How can I retrieve Inherited Roles?

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
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., geändert vor 12 Jahren.

RE: How can I retrieve Inherited Roles?

New Member Beiträge: 23 Beitrittsdatum: 24.10.11 Neueste Beiträge
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., geändert vor 12 Jahren.

RE: How can I retrieve Inherited Roles?

New Member Beiträge: 23 Beitrittsdatum: 24.10.11 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: How can I retrieve Inherited Roles?

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
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.