How to check the role of a user through APIHow to check the role of a user through APIhttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=38972002024-03-28T19:46:36Z2024-03-28T19:46:36ZRE: How to check the role of a user through APILee Jordanhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1185136062020-02-14T17:55:17Z2020-02-14T17:55:17ZJust commenting here because in trying to find a similar working situation in 2020 I'm being directed to threads from 2010. Liferay documentation is letting theme developers down badly.Lee Jordan2020-02-14T17:55:17ZRE: How to check the role of a user through APISherwin Sena Aborothttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=41135392009-10-08T17:24:05Z2009-10-08T17:24:05ZNot sure if this is any simpler than the previous post but this is what I used. <br /><br /> public boolean checkIfUserIsAdmin(RenderRequest req) {<br /> try {<br /> User user = UserLocalServiceUtil.getUserById(Long.parseLong(req.getRemoteUser()));<br /> List<Role> roles = user.getRoles();<br /> <br /> for ( int i=0;i<roles.size();i++ ) {<br /> if ( roles.get(i).getName().indexOf("Administrator") >= 0 ){<br /> return true;<br /> }<br /> }<br /> } catch(Exception err) {}<br /> return false;<br /> }Sherwin Sena Aborot2009-10-08T17:24:05ZRE: How to check the role of a user through APIAmos Fonghttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=40025102009-09-10T23:53:53Z2009-09-10T23:53:53Z<html><head></head><body>Hi Suresh,<br><br>I think this is the method you are looking for:<br><br><pre><code>List<role> userGroupRoles = RoleLocalServiceUtil.getUserGroupRoles(userId, groupId);</role></code></pre><br><br>It should find all community roles of the group that you specify. I found it used in AdvancedPermissionChecker.java</body></html>Amos Fong2009-09-10T23:53:53ZRE: How to check the role of a user through APIsuresh middehttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=38980692009-08-28T08:17:55Z2009-08-28T08:17:55ZHi ,<br /><br />It seems that we cannot use the RoleLocalServiceImpl methods for retrieving Community Roles .<br /><br />Instead, from my inspection, I found a way to do this.<br /><br />Retrieve a list of roles associated with the user id using the method<br /><br />UserGroupRoleLocalServiceUtil.getUserGroupRoles(userid) which returns you a list<userGroupRole> <br /><br />like <br /><br />List<UserGroupRoles> userGroupRoles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(selUser.getUserId());<br /><br /><br />for (UserGroupRole userGroupRole : userGroupRoles) {<br /> int roleType = userGroupRole.getRole().getType();<br /><br /> if (roleType == RoleConstants.TYPE_COMMUNITY) {<br /> communityRoles.add(userGroupRole);<br /> }<br />}<br /><br />if(communityRoles != null) {<br /> for(int j=0;j<communityRoles.size();j++){<br /> UserGroupRole comm = (UserGroupRole)communityRoles.get(j);<br /> // check for roleId that corresponds to the "Community Administrator"<br /> <br /> comm.getRoleId()<br /><br /> }<br />}<br /><br /><br /><br />If anyone can suggest me, a simpler one to achieve this, I will be happy<br /><br />Regards<br />Suresh Middesuresh midde2009-08-28T08:17:55ZRE: How to check the role of a user through APIAritz Galdoshttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=38979512009-08-28T08:03:27Z2009-08-28T08:03:27ZI am not sure but I think role assignemetc can bi done both direct o indirectly.<br /><br />I mean that a role can be assigned to a user personally, but it can be assigned throgh a user group, sommunity or so...<br /><br />Which in database level mean that:<br /><br />1case: relation is user -- user_roles -- roles<br /><br />2 case: user -- users_usergroups -- usergrouprole<br /><br /><br />But double check it table ralation because I may be wrong<br /><br />Hope it helpsAritz Galdos2009-08-28T08:03:27ZRE: How to check the role of a user through APIsuresh middehttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=38978062009-08-28T07:40:52Z2009-08-28T07:40:52ZHi ,<br /><br />I had a weird problem,when I have verified my database table users_roles there was no mapping between my userid which I have associated with the role of "Community Administrator".<br /><br />My userid has only mapping to the role ids of "Power User" and "User"<br /><br />But from my application, I have assigned my user as Community Administrator.I dont know what is the problem?<br /><br />Screenshot attachedsuresh midde2009-08-28T07:40:52ZRE: How to check the role of a user through APIAritz Galdoshttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=38972962009-08-28T06:50:01Z2009-08-28T06:50:01ZHi, <br /><br />Did you try with hasUserRole(long userId, long roleId) method in the same class? You will only need the userId and the role Id.<br /><br />On the other hand, did you double check via web, that this user actually has this role?<br /><br />good luckAritz Galdos2009-08-28T06:50:01ZHow to check the role of a user through APIsuresh middehttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=38971992009-08-28T06:37:55Z2009-08-28T06:37:55ZHi,<br /><br />I want to check whether the user has a role of "community administrator" using API.<br /><br />I could get a method from RoleLocalServiceImpl.java<br /><br />public boolean hasUserRole(<br /> long userId, long companyId, String name, boolean inherited)<br /><br />I have assigned a user as Community Administrator <br /><br />I have tried checking<br /><br /> RoleLocalServiceUtil.hasUserRole(userId, companyI