<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>How to check the role of a user through API</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=3897200" />
  <subtitle>How to check the role of a user through API</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=3897200</id>
  <updated>2026-04-05T16:17:43Z</updated>
  <dc:date>2026-04-05T16:17:43Z</dc:date>
  <entry>
    <title>RE: How to check the role of a user through API</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118513606" />
    <author>
      <name>Lee Jordan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118513606</id>
    <updated>2020-02-14T17:55:17Z</updated>
    <published>2020-02-14T17:55:17Z</published>
    <summary type="html">Just commenting here because in trying to find a similar working situation in 2020 I&amp;#39;m being directed to threads from 2010. Liferay documentation is letting theme developers down badly.</summary>
    <dc:creator>Lee Jordan</dc:creator>
    <dc:date>2020-02-14T17:55:17Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check the role of a user through API</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4113539" />
    <author>
      <name>Sherwin Sena Aborot</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4113539</id>
    <updated>2009-10-08T17:24:05Z</updated>
    <published>2009-10-08T17:24:05Z</published>
    <summary type="html">Not sure if this is any simpler than the previous post but this is what I used. &lt;br /&gt;&lt;br /&gt;	 public boolean checkIfUserIsAdmin(RenderRequest req) {&lt;br /&gt;		 try {&lt;br /&gt;			 User user = UserLocalServiceUtil.getUserById(Long.parseLong(req.getRemoteUser()));&lt;br /&gt;			 List&amp;lt;Role&amp;gt; roles = user.getRoles();&lt;br /&gt;			 &lt;br /&gt;			 for ( int i=0;i&amp;lt;roles.size();i++ ) {&lt;br /&gt;				 if ( roles.get(i).getName().indexOf(&amp;#34;Administrator&amp;#34;) &amp;gt;= 0 ){&lt;br /&gt;					 return true;&lt;br /&gt;				 }&lt;br /&gt;			 }&lt;br /&gt;		 } catch(Exception err) {}&lt;br /&gt;		 return false;&lt;br /&gt;	 }</summary>
    <dc:creator>Sherwin Sena Aborot</dc:creator>
    <dc:date>2009-10-08T17:24:05Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check the role of a user through API</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4002510" />
    <author>
      <name>Amos Fong</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4002510</id>
    <updated>2009-09-10T23:53:53Z</updated>
    <published>2009-09-10T23:53:53Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi Suresh,&lt;br&gt;&lt;br&gt;I think this is the method you are looking for:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;List&amp;lt;role&amp;gt; userGroupRoles = RoleLocalServiceUtil.getUserGroupRoles(userId, groupId);&amp;lt;/role&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;It should find all community roles of the group that you specify. I found it used in AdvancedPermissionChecker.java&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Amos Fong</dc:creator>
    <dc:date>2009-09-10T23:53:53Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check the role of a user through API</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3898069" />
    <author>
      <name>suresh midde</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3898069</id>
    <updated>2009-08-28T08:17:55Z</updated>
    <published>2009-08-28T08:17:55Z</published>
    <summary type="html">Hi ,&lt;br /&gt;&lt;br /&gt;It seems that we cannot use the RoleLocalServiceImpl methods for retrieving Community Roles .&lt;br /&gt;&lt;br /&gt;Instead, from my inspection, I found a way to do this.&lt;br /&gt;&lt;br /&gt;Retrieve a list of roles associated with the user id using the method&lt;br /&gt;&lt;br /&gt;UserGroupRoleLocalServiceUtil.getUserGroupRoles(userid) which returns you a list&amp;lt;userGroupRole&amp;gt; &lt;br /&gt;&lt;br /&gt;like &lt;br /&gt;&lt;br /&gt;List&amp;lt;UserGroupRoles&amp;gt; userGroupRoles = UserGroupRoleLocalServiceUtil.getUserGroupRoles(selUser.getUserId());&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;for (UserGroupRole userGroupRole : userGroupRoles) {&lt;br /&gt;	int roleType = userGroupRole.getRole().getType();&lt;br /&gt;&lt;br /&gt;	if (roleType == RoleConstants.TYPE_COMMUNITY) {&lt;br /&gt;		communityRoles.add(userGroupRole);&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(communityRoles != null) {&lt;br /&gt;					for(int j=0;j&amp;lt;communityRoles.size();j++){&lt;br /&gt;						UserGroupRole comm = (UserGroupRole)communityRoles.get(j);&lt;br /&gt;                                                // check for roleId that corresponds to the &amp;#34;Community Administrator&amp;#34;&lt;br /&gt;                                            &lt;br /&gt;                                               comm.getRoleId()&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If anyone can suggest me, a simpler one to achieve this, I will be happy&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Suresh Midde</summary>
    <dc:creator>suresh midde</dc:creator>
    <dc:date>2009-08-28T08:17:55Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check the role of a user through API</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3897951" />
    <author>
      <name>Aritz Galdos</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3897951</id>
    <updated>2009-08-28T08:03:27Z</updated>
    <published>2009-08-28T08:03:27Z</published>
    <summary type="html">I am not sure but I think role assignemetc can bi done both direct o indirectly.&lt;br /&gt;&lt;br /&gt;I mean that a role can be assigned to a user personally, but it can be assigned throgh a user group, sommunity or so...&lt;br /&gt;&lt;br /&gt;Which in database level mean that:&lt;br /&gt;&lt;br /&gt;1case: relation is user -- user_roles -- roles&lt;br /&gt;&lt;br /&gt;2 case: user -- users_usergroups -- usergrouprole&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But double check it table ralation because I may be wrong&lt;br /&gt;&lt;br /&gt;Hope it helps</summary>
    <dc:creator>Aritz Galdos</dc:creator>
    <dc:date>2009-08-28T08:03:27Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check the role of a user through API</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3897806" />
    <author>
      <name>suresh midde</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3897806</id>
    <updated>2009-08-28T07:40:52Z</updated>
    <published>2009-08-28T07:40:52Z</published>
    <summary type="html">Hi ,&lt;br /&gt;&lt;br /&gt;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 &amp;#34;Community Administrator&amp;#34;.&lt;br /&gt;&lt;br /&gt;My userid has only mapping to the role ids of &amp;#34;Power User&amp;#34; and &amp;#34;User&amp;#34;&lt;br /&gt;&lt;br /&gt;But from my application, I have assigned my user as Community Administrator.I dont know what is the problem?&lt;br /&gt;&lt;br /&gt;Screenshot attached</summary>
    <dc:creator>suresh midde</dc:creator>
    <dc:date>2009-08-28T07:40:52Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check the role of a user through API</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3897296" />
    <author>
      <name>Aritz Galdos</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3897296</id>
    <updated>2009-08-28T06:50:01Z</updated>
    <published>2009-08-28T06:50:01Z</published>
    <summary type="html">Hi, &lt;br /&gt;&lt;br /&gt;Did you try with hasUserRole(long userId, long roleId)  method in the same class? You will only need the userId and the role Id.&lt;br /&gt;&lt;br /&gt;On the other hand, did you double check via web, that this user actually has this role?&lt;br /&gt;&lt;br /&gt;good luck</summary>
    <dc:creator>Aritz Galdos</dc:creator>
    <dc:date>2009-08-28T06:50:01Z</dc:date>
  </entry>
  <entry>
    <title>How to check the role of a user through API</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3897199" />
    <author>
      <name>suresh midde</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=3897199</id>
    <updated>2009-08-28T06:37:55Z</updated>
    <published>2009-08-28T06:37:55Z</published>
    <summary type="html">Hi,&lt;br /&gt;&lt;br /&gt;I want to check  whether the user has a role of &amp;#34;community administrator&amp;#34; using API.&lt;br /&gt;&lt;br /&gt;I could get a method from RoleLocalServiceImpl.java&lt;br /&gt;&lt;br /&gt;public boolean hasUserRole(&lt;br /&gt;			long userId, long companyId, String name, boolean inherited)&lt;br /&gt;&lt;br /&gt;I have assigned a user as Community Administrator &lt;br /&gt;&lt;br /&gt;I have tried checking&lt;br /&gt;&lt;br /&gt;   RoleLocalServiceUtil.hasUserRole(userId, companyId, &amp;#34;Community Administrator&amp;#34;, false);  which returned me false, which should be true.&lt;br /&gt;&lt;br /&gt;Also I tried &lt;br /&gt;&lt;br /&gt;RoleLocalServiceUtil.hasUserRole(userId, companyId, &amp;#34;Community Administrator&amp;#34;, true);  which also returned me false.&lt;br /&gt;&lt;br /&gt;I observed that this works fine for Regular roles.&lt;br /&gt;&lt;br /&gt;Can anyone look into this?&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Suresh Midde</summary>
    <dc:creator>suresh midde</dc:creator>
    <dc:date>2009-08-28T06:37:55Z</dc:date>
  </entry>
</feed>
