我一直致力于访问控制。所以,在我们的liferay portlet中,我如何获得用户的所有权限,我已经通过
获得了用户的角色FacesContext facesContext = FacesContext
.getCurrentInstance();
PortletRequest request = (PortletRequest) facesContext
.getExternalContext().getRequest();
User user = (User) request.getAttribute(WebKeys.USER);
List<Role> roles = new ArrayList<Role>();
roles.addAll(RoleLocalServiceUtil.getUserRoles(user.getUserId()));
roles.addAll(RoleLocalServiceUtil.getUserRelatedRoles(user.getUserId(), user.getGroupIds()));
但是如果给定的用户对portlet有视图/配置/ etc权限,我无法找到任何可以找到的东西。getResourceResourcePermissions
给了我权限但是通过ID,我怎样才能找到权限权限名称即view / config / update
liferay 6.2
答案 0 :(得分:1)
您可以在portlet中逐一检查用户是否具有该权限。
ThemeDisplay themeDisplay= (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
long groupId = themeDisplay.getScopeGroupId();
String name = (String)request.getAttribute(WebKeys.PORTLET_ID);
String primKey = portletDisplay.getResourcePK();
boolean view = permissionChecker.hasPermission(groupId, name, primKey, ActionKeys.VIEW);
boolean congiguration = permissionChecker.hasPermission(groupId, name, primKey, ActionKeys.CONFIGURATION);
boolean update = permissionChecker.hasPermission(groupId, name, primKey, ActionKeys.UPDATE);
答案 1 :(得分:0)
我认为您可以尝试使用此类PermissionFinderUtil。该类包含许多函数来获取Permission。