title: Liferay - How to hide/show button by checking user permission
body: <p>I have a web application hosted on liferay portal. There are certain features like showing a save button for certain users only based on custom permissions defined in liferay.</p>
  
  <p>I have configured the permissions in xml file as below using the reference from 
  <a href="http://www.liferay.com/community/wiki/-/wiki/Main/Permissioning+in+Plugin+Environment#section-Permissioning+in+Plugin+Environment-DEFINING+PERMISSION+FOR+A+PORTLET+RESOURCE+IN+PLUGIN+ENVIRONMENT" rel="nofollow">http://www.liferay.com/community/wiki/-/wiki/Main/Permissioning+in+Plugin+Environment#section-Permissioning+in+Plugin+Environment-DEFINING+PERMISSION+FOR+A+PORTLET+RESOURCE+IN+PLUGIN+ENVIRONMENT</a></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;resource-action-mapping&gt;
      &lt;portlet-resource&gt;
          &lt;portlet-name&gt;TESTPortlet&lt;/portlet-name&gt;
                  &lt;permissions&gt;
          &lt;supports&gt;
              &lt;action-key&gt;SEARCH_BUTTON&lt;/action-key&gt;
              &lt;action-key&gt;SAVE_BUTTON&lt;/action-key&gt;
              &lt;action-key&gt;DELETE_BUTTON&lt;/action-key&gt;
          &lt;/supports&gt; 
           &lt;/permissions&gt;
      &lt;/portlet-resource&gt;
  &lt;/resource-action-mapping&gt;
  </code></pre>
  
  <p>I can see the above permissions in permissions tab in portal under my portlet. I have also assigned the SAVE_BUTTON permission to one of the user role say (TEST_ADMIN is my role).</p>
  
  <p>How do I check in my jsp or java, if the logged in user has SAVE_BUTTON permission.</p>
  
  <p>I tried access check with this below code.</p>
  
  <pre><code>&lt;c:if test="&lt;%= PortletPermissionUtil.contains(permissionChecker,plid.longValue(), "TESTPortlet_WAR_TESTPortlet5121","SAVE_BUTTON") %&gt;"&gt;
  </code></pre>
  
  <p>However, it always returns me true even though I pass SEARCH_BUTTON permisison in above check. The above check returns false only, if I pass a permission which does not exist in my configuration itself. I guess above check is to know if the permissions are available in portlet or not and is not at user access level.</p>
  
  <p>Also, if I use the below code from Liferay SVN repo, I always get the value as Yes.</p>
  
  <pre><code>%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  
  &lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %&gt;
  
  &lt;%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %&gt;
  &lt;%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %&gt;
  &lt;%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %&gt;
  
  &lt;portlet:defineObjects /&gt;
  
  &lt;liferay-theme:defineObjects /&gt;
  
  &lt;%
  long groupId = scopeGroupId;
  String name = portletDisplay.getRootPortletId();
  String primKey = portletDisplay.getResourcePK();
  String actionId = "ADD_SOMETHING";
  %&gt;
  
  Do you have the &lt;i&gt;&lt;liferay-ui:message key='&lt;%= "action." + actionId %&gt;' /&gt;&lt;/i&gt; permission for this portlet?
  
  &lt;strong&gt;
  
  &lt;c:choose&gt;
      &lt;c:when test="&lt;%= permissionChecker.hasPermission(groupId, name, primKey, actionId) %&gt;"&gt;
          Yes
      &lt;/c:when&gt;
      &lt;c:otherwise&gt;
          No
      &lt;/c:otherwise&gt;
  &lt;/c:choose&gt;
  
  &lt;/strong&gt;
  </code></pre>
  
  <p>Can anyone please help, how to check if logged in user has access to a particular permission, so that I can hide or show my buttons.</p>
  
  <p>Thanks in advance.</p>