简体   繁体   English

如何按名称为 liferay 用户拥有的每个角色获取权限

[英]How to get permissions by name for each role a liferay user has

I've been working on access control.So,In our liferay portlets,how can I get all permissions of a user,I've achieved getting roles of a user by我一直在研究访问控制。所以,在我们的 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()));

But I cant find any thing by which I can find if the given user has view/configuration/etc permissions with respect to the portlets.但是,如果给定的用户对 portlet 具有查看/配置/等权限,我无法找到任何可以找到的信息。 getResourceResourcePermissions gives me the permission but by ids,How can I find permissions with permission name ie view/config/update getResourceResourcePermissions给了我权限,但通过 ids,我如何找到具有权限名称的权限,即查看/配置/更新

liferay 6.2

You can check if user has that permission one by one in the portlet.您可以在 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);

I think you can try to use this class PermissionFinderUtil.我认为你可以尝试使用这个类 PermissionFinderUtil。 This class contains a lot of functions to get Permission.这个类包含了很多获取权限的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM