1

我正在使用 Liferay 6.1 CE、Tomcat、Vaadin 6.8.4
对我来说可能是一种非常不正确的方法,或者我可能错过了一些明显的东西。

我需要为我的用户控制 crud 功能 - 允许访问他们所属的组织以及其下的任何子组织。(我正在使用 Liferay 的organization_桌子)

在尝试简化权限管理时,我曾希望将用户分配给层次结构中的组织。然后可以根据分配给该组织和任何父组织的角色来确定默认权限。这对于常规角色似乎工作得相当好 - 但后来我尝试了自定义组织角色,但我无法按预期掌握细节。

  • 我可以在用户的​​控制面板定义中看到正确的数据。
    (Liferay 知道如何检索和显示自定义组织角色 :-)

  • 我可以看到后端表中填充的实际数据值usergrouprole

  • 我能够检测到默认超级管理员/所有者 (test@liferay) 的此角色
    。. . 但我无法检测到其他用户的角色:(

  • 我一直在使用RoleLocalServiceUtilGroupLocalServiceUtil但没有运气。

    我的直觉告诉我要放弃我的“纯粹”概念,转而使用熟悉的自定义查询,但我想先看看其他人是否有更好的建议。

    我目前不知道如何进入 Liferay 代码以找到相关部分,所以如果你有一些阅读材料,这可能是一个选择:)

    线索?

  • 4

    2 回答 2

    1

    这看起来很难看(因为确实如此),但我认为您需要致电:

    UserGroupRoleLocalServiceUtil.hasUserGroupRole(long userId, long groupId, long roleId);
    

    一般来说,XYZ 表有(如果不总是)一个 XYZLocalServiceUtil 和 XYZServiceUtil。

    于 2012-10-30T22:55:13.113 回答
    0

    本着分享的精神,这里有一些显示权限的示例代码。

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    User i_user =  themeDisplay.getUser();
    PortletDisplay portDisplay = themeDisplay.getPortletDisplay();
    String myRootname = portDisplay.getRootPortletId();
    String strOrgGroupRoles = "";
    
    //== 1. Display permission provided to user by Organisation(Group) Roles
    //== 2. User is assigned to the org.
    //== 3. Org is a member of the OrgRole.
    //== 4. OrgRole has permission defined from current selected portlet permissions (action-key)
    List<UserGroupRole> ugRoles = new ArrayList<UserGroupRole>();
    ugRoles.addAll(UserGroupRoleLocalServiceUtil.getUserGroupRoles(i_user.getUserId() ) );
    for (UserGroupRole ugRole : ugRoles){
    
        //== For each role this user has allocated, display the Rolename and the Organisation
        strOrgGroupRoles += "'" +ugRole.getRole().getName() + "'  (roleId="+ugRole.getRoleId()+")";
        strOrgGroupRoles += " for organization '"+OrganizationLocalServiceUtil.getOrganization(ugRole.getGroup().getClassPK()).getName();
        strOrgGroupRoles += "' (groupId=" +ugRole.getGroupId()+ ")\n";
    
        //== Permissions for the role is harder to find - linked to a resource
        //== Data shows the `actionId` equates to relative action number column 'bitwiseValue' in `resourceaction`.
        //== Snag is ResourcePermission needs a tie-breaker of the portlet name, not just the roleId
        //== Get this from ThemeDisplay getRootPortletId()
        //==
        //== I think Liferay 6.1.0 API may be broken here:  ResourceActionLocalServiceUtil.getResourceAction expects String, String . . .
        //==  . . . yet the `bitwiseValue` column is BIGINT(20) so nothing is returned.
        //== This causes us to attack it from a different angle
        List<ResourcePermission> resourcePerms = new ArrayList<ResourcePermission>();
        resourcePerms.addAll( ResourcePermissionLocalServiceUtil.getRoleResourcePermissions(ugRole.getRoleId()) );
        for (ResourcePermission resourcePerm : resourcePerms){
    
            //== For each of the ResourcePermissions of this role, get the actionId (equals Role Permissions aka action-key)
            //== The link is a relative number, not unique in this table so ensure it is for this portlet only
            if ( resourcePerm.getName().equals(myRootname)){ 
                List<ResourceAction> resourceActions = new ArrayList<ResourceAction>();
                resourceActions.addAll( ResourceActionLocalServiceUtil.getResourceActions(myRootname)  );
                for (ResourceAction resourceAction : resourceActions) {
    
                    //== For each listed action, ensure it is the relative action number we want (actionId) 
                    if (resourceAction.getBitwiseValue() == resourcePerm.getActionIds() ) {
                        strOrgGroupRoles += " +-- action= " + resourceAction.getActionId() + "\n";
                    }   
    
                }   //== End of actionIds for this portlet
    
            }   //== End if this portlet only
    
        }   //== End ResourcePermissions for this role
    
    }   //== End roles for this user                
    

    高温高压

    罗宾

    于 2012-11-01T22:08:27.990 回答