工作中遇到需要从 jsp 页面获取登录最高权限及相应 site 里某个页面具体的权限,以下是具体代码:
1. 获取登录状态下最高权限
首先 jsp 头引入
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-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" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<%@ page import="com.liferay.portal.theme.ThemeDisplay" %>
<%@ page import="com.liferay.portal.kernel.util.WebKeys" %>
<portlet:defineObjects />
<liferay-theme:defineObjects />
2. 获取登录状态,返回一个布尔值
ThemeDisplay portletThemeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
boolean signedIn = portletThemeDisplay.isSignedIn();
3. 获取某个指定 site 指定的权限,比如 preferences 的权限
PortletPreferences prefs = renderRequest.getPreferences();
long myGroupId = scopeGroupId;
String myName = portletDisplay.getRootPortletId();
String myPrimKey = portletDisplay.getResourcePK();
String actionId = "PREFERENCES";
boolean showOperateColumn = permissionChecker.hasPermission(myGroupId, myName, myPrimKey, actionId);
Appendix:这里面某些对象是 liferay 自带的,会自动识别!