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.
I have configured the permissions in xml file as below using the reference from 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
<?xml version="1.0"?>
<resource-action-mapping>
<portlet-resource>
<portlet-name>TESTPortlet</portlet-name>
<permissions>
<supports>
<action-key>SEARCH_BUTTON</action-key>
<action-key>SAVE_BUTTON</action-key>
<action-key>DELETE_BUTTON</action-key>
</supports>
</permissions>
</portlet-resource>
</resource-action-mapping>
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).
How do I check in my jsp or java, if the logged in user has SAVE_BUTTON permission.
I tried access check with this below code.
<c:if test="<%= PortletPermissionUtil.contains(permissionChecker,plid.longValue(), "TESTPortlet_WAR_TESTPortlet5121","SAVE_BUTTON") %>">
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.
Also, if I use the below code from Liferay SVN repo, I always get the value as Yes.
%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<portlet:defineObjects />
<liferay-theme:defineObjects />
<%
long groupId = scopeGroupId;
String name = portletDisplay.getRootPortletId();
String primKey = portletDisplay.getResourcePK();
String actionId = "ADD_SOMETHING";
%>
Do you have the <i><liferay-ui:message key='<%= "action." + actionId %>' /></i> permission for this portlet?
<strong>
<c:choose>
<c:when test="<%= permissionChecker.hasPermission(groupId, name, primKey, actionId) %>">
Yes
</c:when>
<c:otherwise>
No
</c:otherwise>
</c:choose>
</strong>
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.
Thanks in advance.