<?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 if a user has a role within current community/site (Liferay 6.</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=12032443" />
  <subtitle>How to check if a user has a role within current community/site (Liferay 6.</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=12032443</id>
  <updated>2026-04-04T06:31:43Z</updated>
  <dc:date>2026-04-04T06:31:43Z</dc:date>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118552131" />
    <author>
      <name>David H Nebinger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118552131</id>
    <updated>2020-02-20T04:31:39Z</updated>
    <published>2020-02-20T04:31:39Z</published>
    <summary type="html">It is pure java in the form I gave, but you can easily wrap that into a context contributor for direct freemarker access.&lt;br /&gt;&lt;br /&gt;I try to avoid doing things in FM scripts because it is all interpreted. Instead I prefer to build all of my logic in Java and then use a context contributor to inject it into the FM context. Then my FM scripts can use simple ${} syntax to inject the value, but the heavy lifting is still done in java.</summary>
    <dc:creator>David H Nebinger</dc:creator>
    <dc:date>2020-02-20T04:31:39Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118550935" />
    <author>
      <name>Lee Jordan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118550935</id>
    <updated>2020-02-19T14:56:25Z</updated>
    <published>2020-02-19T14:56:25Z</published>
    <summary type="html">Is that freemarker code?&lt;br /&gt;&lt;br /&gt;That&amp;#39;s really the end game for figuring out what the user is on a site by site basis. I will need to track how many site admins are still using IE for example to provide education to change behaviour. I can&amp;#39;t currently see how Liferay analytics tracks that (it should). But as for figuring out how to do it ... It&amp;#39;s a desert out there. There&amp;#39;s a few threads with snippets but no such documentation on how to use services in freemarker.&lt;br /&gt;&lt;br /&gt;I&amp;#39;m at this stage to be honest ...&lt;br /&gt;&amp;#34;output a sequence in freemarker&amp;#34; just so I can see what&amp;#39;s in there to condition on. The chances of success for anyone particularly someone new to Liferay is close to zero.&lt;br /&gt;&lt;br /&gt;I also only get two pages of results in Google and one result is this thread. The thing is if I can get something to work it opens the floodgates for other stuff, there&amp;#39;s just very little chance of being able to scrape enough information together for a freemarker developer here (not java)??&lt;br /&gt;&lt;br /&gt;I have the ?size of the array/sequence whatever data Liferay is giving. The size is zero.</summary>
    <dc:creator>Lee Jordan</dc:creator>
    <dc:date>2020-02-19T14:56:25Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118544406" />
    <author>
      <name>David H Nebinger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118544406</id>
    <updated>2020-02-19T02:29:49Z</updated>
    <published>2020-02-19T02:29:49Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Ah, so you can do this pretty easily &lt;img alt="emoticon" src="@theme_images_path@/emoticons/smile.gif"&gt;&lt;br&gt;&lt;br&gt;For example, only a site admin can enable staging. So how do you figure out if a user has permission to enable staging? You look at the GroupServiceImpl to see how the portal verifies that the user can enable staging.&lt;br&gt;&lt;br&gt;&lt;br&gt;In 7.2 for example, the permission check is:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;GroupPermissionUtil.check(
   getPermissionChecker(), groupLocalService.getGroup(groupId),
   ActionKeys.UPDATE);
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;So if this is good enough for the portal to determine that the user can modify the group to enable staging, I think it is safe to say that these same users would be admins (either real admins or site admins).&lt;br&gt;&lt;br&gt;Liferay doesn't track page views by users, that would be something you'd have to build out yourself. The same permission check can be used to see if you're a site admin though.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>David H Nebinger</dc:creator>
    <dc:date>2020-02-19T02:29:49Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118540663" />
    <author>
      <name>Lee Jordan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118540663</id>
    <updated>2020-02-19T01:39:50Z</updated>
    <published>2020-02-19T01:39:50Z</published>
    <summary type="html">So how would we detect if the logged in user was a member vs an admin. I have another use case for this to direct IE usage discouragement to admins using IE. And also would like to report monthly on our page views by admins only.</summary>
    <dc:creator>Lee Jordan</dc:creator>
    <dc:date>2020-02-19T01:39:50Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118540297" />
    <author>
      <name>David H Nebinger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118540297</id>
    <updated>2020-02-18T22:38:18Z</updated>
    <published>2020-02-18T22:38:18Z</published>
    <summary type="html">So this is why Liferay recommends testing for permissions, not roles.&lt;br /&gt;&lt;br /&gt;Roles themselves are just containers of permissions, and your actual complete set of permissions can come from many source including but not limited to direct role assignment.&lt;br /&gt;&lt;br /&gt;Your test will fail the first time someone decides they don&amp;#39;t want to manage 50k site member role assignments (or some other role) and instead want to create a group that has the role(s) and all users become member of the group.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;From Liferay&amp;#39;s perspective, everything works exactly the same, but your test is now going to fail. Why? Because Liferay does permission checks, not role checks, to determine if a user has access to something.</summary>
    <dc:creator>David H Nebinger</dc:creator>
    <dc:date>2020-02-18T22:38:18Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118539626" />
    <author>
      <name>Lee Jordan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118539626</id>
    <updated>2020-02-18T19:49:24Z</updated>
    <published>2020-02-18T19:49:24Z</published>
    <summary type="html">One use case is to display an information box at the bottom of a web content template that&amp;#39;s only visible to site admins. Giving information on how to use the template, links to resources like where to find images for the template etc etc. We also get hammered with people not knowing if they are a site member or not, so adding a simple icon to the dockbar would help them quit bugging us and help us figure out faster if that user is a site member or not.&lt;br /&gt;&lt;br /&gt;// WRITE USER ROLE TO CONSOLE&lt;br /&gt;    &amp;lt;#if user_site_roles?is_sequence&amp;gt;&lt;br /&gt;      console.log(&amp;#39;is sequence&amp;#39;);&lt;br /&gt;      &amp;lt;#list user_site_roles as role&amp;gt;&lt;br /&gt;        &amp;lt;#assign role_name = role.getName()&amp;gt;&lt;br /&gt;        ${role_name}&lt;br /&gt;      &amp;lt;/#list&amp;gt;&lt;br /&gt;    &amp;lt;/#if&amp;gt;&lt;br /&gt;&lt;br /&gt;Caused by: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:_==&amp;gt; role.getName</summary>
    <dc:creator>Lee Jordan</dc:creator>
    <dc:date>2020-02-18T19:49:24Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118539266" />
    <author>
      <name>Lee Jordan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118539266</id>
    <updated>2020-02-18T19:34:21Z</updated>
    <published>2020-02-18T19:34:21Z</published>
    <summary type="html">Sigh, that&amp;#39;s what I&amp;#39;m using in 7.2 and the service is now found. That documentation isn&amp;#39;t helpful though. Java Docs to a front end developer is total nonsense. FED life in Liferay is abysmal.&lt;br /&gt;&lt;br /&gt;I have this is in init_custom.ftl&lt;br /&gt;&lt;br /&gt;user_id and group_id are already defined from the init.ftl&lt;br /&gt;&lt;br /&gt;&amp;lt;#assign UserLocalRoleService = serviceLocator.findService(&amp;#34;com.liferay.portal.kernel.service.UserGroupRoleLocalService&amp;#34;) /&amp;gt;&lt;br /&gt;&amp;lt;#assign user_site_roles = UserLocalRoleService.getUserGroupRoles(user_id, group_id) /&amp;gt;&lt;br /&gt;&lt;br /&gt;and this in portal normal&lt;br /&gt;&lt;br /&gt;console.log(&amp;#39;${user_site_roles}&amp;#39;);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I&amp;#39;m stuck trying to even see what&amp;#39;s in there as it&amp;#39;s a sequence and won&amp;#39;t echo out to the console, the error now is ...Caused by: freemarker.core.NonStringException: For &amp;#34;${...}&amp;#34; content: Expected a string or something automatically convertible to string (number, date or boolean), but this has evaluated to a sequence (Collections$UnmodifiableRandomAccessList wrapped into f.t.DefaultListAdapter):_==&amp;gt; user_site_roles  [in template &amp;#34;mercury-theme_SERVLET_CONTEXT_/templates/portal_normal.ftl&amp;#34; at line 91, column 20]__----_FTL stack trace (&amp;#34;~&amp;#34; means nesting-related):_   - Failed at: ${user_site_roles}  [in template &amp;#34;mercury-theme_SERVLET_CONTEXT_/templates/portal_normal.ftl&amp;#34; at line 91, column 18]_---- [Sanitized]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All I need right now is something like &amp;#34;is_site_admin&amp;#34; &amp;#34;is_site_member&amp;#34; &amp;#34;is_site_guest&amp;#34;, that&amp;#39;s really what I&amp;#39;m trying to build in the theme.</summary>
    <dc:creator>Lee Jordan</dc:creator>
    <dc:date>2020-02-18T19:34:21Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118514645" />
    <author>
      <name>Christoph Rabel</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118514645</id>
    <updated>2020-02-14T20:48:27Z</updated>
    <published>2020-02-14T20:48:27Z</published>
    <summary type="html">It&amp;#39;s &amp;#34;com.liferay.portal.kernel.service.UserGroupRoleLocalService&amp;#34;&lt;br /&gt;&lt;a href="https://docs.liferay.com/ce/portal/7.2-latest/javadocs/portal-kernel/com/liferay/portal/kernel/service/UserGroupRoleLocalService.html"&gt;https://docs.liferay.com/ce/portal/7.2-latest/javadocs/portal-kernel/com/liferay/portal/kernel/service/UserGroupRoleLocalService.html&lt;/a&gt;</summary>
    <dc:creator>Christoph Rabel</dc:creator>
    <dc:date>2020-02-14T20:48:27Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118510916" />
    <author>
      <name>Lee Jordan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118510916</id>
    <updated>2020-02-14T17:47:08Z</updated>
    <published>2020-02-14T17:47:08Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Trying to detect user site roles also here in freemarker portal_normal theme file, which is an absolute nightmare. These things need to be much easier.&lt;br&gt;&lt;br&gt;Can't find service in 7.2&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==&amp;amp;gt; serviceLocator.findService("com.liferay.portal.service.UserGroupRoleLocalService")&lt;/code&gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Lee Jordan</dc:creator>
    <dc:date>2020-02-14T17:47:08Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=22601155" />
    <author>
      <name>Ricardo Piccoli</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=22601155</id>
    <updated>2013-03-13T18:15:14Z</updated>
    <published>2013-03-13T18:15:14Z</published>
    <summary type="html">I was able to do that using:&lt;br /&gt;&lt;br /&gt;UserGroupRoleLocalServiceUtil.hasUserGroupRole(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), &amp;#34;my-custom-role&amp;#34;, true);&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;UserGroupRoleLocalServiceUtil.hasUserGroupRole(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), RoleConstants.SITE_ADMINISTRATOR, true);&lt;br /&gt;&lt;br /&gt;This last &amp;#34;true&amp;#34;, is because I don&amp;#39;t add users but groups to sites.</summary>
    <dc:creator>Ricardo Piccoli</dc:creator>
    <dc:date>2013-03-13T18:15:14Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=22552049" />
    <author>
      <name>Ricardo Piccoli</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=22552049</id>
    <updated>2013-03-12T14:43:14Z</updated>
    <published>2013-03-12T14:43:14Z</published>
    <summary type="html">Any success?</summary>
    <dc:creator>Ricardo Piccoli</dc:creator>
    <dc:date>2013-03-12T14:43:14Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to check if a user has a role within current community/site (Lifera</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=12036746" />
    <author>
      <name>Jitendra Rajput</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=12036746</id>
    <updated>2012-01-10T05:20:59Z</updated>
    <published>2012-01-10T05:20:59Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Have you tried by passing false in second approach .?&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;RoleServiceUtil.hasUserRole(user.getUserId(), communityId, SITE_ADMIN_ROLE, false);&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;Similar kind of problem encountered in below thread ..look into it ..May help you.&lt;br&gt;&lt;br&gt;http://www.liferay.com/community/forums/-/message_boards/message/4002510&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Jitendra Rajput</dc:creator>
    <dc:date>2012-01-10T05:20:59Z</dc:date>
  </entry>
  <entry>
    <title>How to check if a user has a role within current community/site (Liferay 6.</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=12032442" />
    <author>
      <name>Morad Ahmad</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=12032442</id>
    <updated>2012-01-09T20:04:49Z</updated>
    <published>2012-01-09T20:04:49Z</published>
    <summary type="html">I defined a community role &amp;#34;SiteContentManager&amp;#34; which allows users to add specific content to a site, where they have this role. I need to check if the user has this role in a portlet. I tried different ways without success:&lt;br /&gt;&lt;br /&gt;1. 	List&amp;lt;Role&amp;gt; userGroupRoles = RoleServiceUtil.getUserGroupRoles(user.getUserId(), communityId);&lt;br /&gt;			if (userGroupRoles != null) {&lt;br /&gt;				for (Role role : userGroupRoles) {&lt;br /&gt;					System.out.println(role.getName());&lt;br /&gt;					if (role.getName().equals(SITE_ADMIN_ROLE))&lt;br /&gt;						return true;&lt;br /&gt;				}&lt;br /&gt;			}&lt;br /&gt;&lt;br /&gt;2. groupRoles = RoleLocalServiceUtil.getGroupRoles(communityId);&lt;br /&gt;			System.out.println(&amp;#34;group roles: &amp;#34;);&lt;br /&gt;			if (groupRoles != null) {...}&lt;br /&gt;&lt;br /&gt;3. RoleServiceUtil.hasUserRole(user.getUserId(), communityId, SITE_ADMIN_ROLE, true);&lt;br /&gt;&lt;br /&gt;???&lt;br /&gt;&lt;br /&gt;Thanks.</summary>
    <dc:creator>Morad Ahmad</dc:creator>
    <dc:date>2012-01-09T20:04:49Z</dc:date>
  </entry>
</feed>
