【问题标题】:How to give Organization Administration Permissions to a Role, for Users that don't belong to this Organization?如何为不属于该组织的用户授予角色的组织管理权限?
【发布时间】:2012-11-01 07:52:44
【问题描述】:

我正在使用 Liferay 6.1,我想更改各个组织的权限,使这些组织可由 UserX 管理strong> 与不属于该组织 OrgARoleX

特别是:

  • 我想让 OrgA 通过 RoleXControl Panel->Users and Organizations 形式查看和更新​​
  • UserX 可以添加新的组织和用户
  • UserX 属于 RoleX不属于 OrgA(所以我认为组织范围的角色不会有帮助)。

我想以编程方式


到目前为止我所做的尝试

  • 创建了 RoleX 并赋予它以下权限:

    • 访问控制面板->用户和组织(portlet 125)
    • 组织机构,范围 4(个人):

      ActionKeys.VIEW、ActionKeys.UPDATE、ActionKeys.ASSIGN_USER_ROLES、 ActionKeys.DELETE、ActionKeys.MANAGE_USERS

    • OrgA 的小组,范围 4:

      ActionKeys.ASSIGN_MEMBERS, ActionKeys.ASSIGN_USER_ROLES,
      ActionKeys.CONFIGURE_PORTLETS, ActionKeys.DELETE,
      ActionKeys.MANAGE_ANNOUNCEMENTS, ActionKeys.MANAGE_LAYOUTS,
      ActionKeys.UPDATE, ActionKeys.VIEW, ActionKeys.VIEW_MEMBERS
      

拥有 RoleX 的用户可以访问控制面板中的 Users and Organizations 表单,但他们只能看到自己的组织,而不能看到 OrgA。

如何授予查看和管理 OrgA 的权限?

谢谢

【问题讨论】:

    标签: java liferay user-permissions rbac


    【解决方案1】:

    最后我能够完成为 RoleX 修改 Resource Permissions 和修改 init users_admin portlet jsp 文件,两者都使用 Hook 插件。

    主要问题是 Liferay 没有使用 ResourcePermissions 来启用用户所属组织之外的组织管理。

    特别是在portal-trunk/portal-web/docroot/html/portlet/users_admin/init.jsp 中,只有几行代码仅适用于公司管理员角色

    else if (permissionChecker.isCompanyAdmin()) {
        filterManageableGroups = false;
        filterManageableOrganizations = false;
        filterManageableUserGroups = false;
    }
    

    所以我在 init.jsp 中添加了以下几行(您可以在钩子中使用 init-ext.jsp),以便也为 RoleX 启用它:

    if (MyUtils.isRoleX()) {
        filterManageableGroups = false;
        filterManageableOrganizations = false;
        filterManageableUserGroups = false;
    }
    

    这样,数据库查询不会过滤组织、用户和组。

    第二步是定义添加、更新、管理等权限。用户和组织以及访问控制面板中的 portlet。

    使用启动操作挂钩和ResourcePermisssionLocalService API 非常简单:

    private static final String[] ORGANIZATION_ENTRY_ACTION_IDS = new String[] {
                ActionKeys.VIEW, ActionKeys.UPDATE, ActionKeys.ASSIGN_USER_ROLES,
                ActionKeys.DELETE, ActionKeys.MANAGE_USERS };
    
        private static final String[] ORGANIZATION_CUSTOM_FIELDS_ENTRY_ACTION_IDS = new String[] {
                ActionKeys.VIEW, ActionKeys.UPDATE };
    
        public static final String[] ORGANIZATION_MODEL_ACTION_IDS = new String[] {
                ActionKeys.ASSIGN_MEMBERS, ActionKeys.ASSIGN_USER_ROLES,
                ActionKeys.DELETE, ActionKeys.MANAGE_ANNOUNCEMENTS,
                ActionKeys.UPDATE, ActionKeys.VIEW, ActionKeys.MANAGE_USERS,
                ActionKeys.MANAGE_SUBORGANIZATIONS };
    
        public static final String[] ORGANIZATION_GROUP_ENTRY_ACTION_IDS = new String[] {
                ActionKeys.ASSIGN_MEMBERS, ActionKeys.ASSIGN_USER_ROLES,
                ActionKeys.UPDATE, ActionKeys.VIEW, ActionKeys.VIEW_MEMBERS };
    
        private static final String[] PORTAL_ACTION_IDS = new String[] {
                ActionKeys.ADD_USER, ActionKeys.ADD_ORGANIZATION,
                ActionKeys.VIEW_CONTROL_PANEL };
    
        private static final String[] USERS_ORG_ADMIN_ACTION_IDS = new String[] { ActionKeys.ACCESS_IN_CONTROL_PANEL };
    

    ...省略...

            ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
                    Organization.class.getName(),
                    ResourceConstants.SCOPE_GROUP_TEMPLATE, "0", CiUtils
                            .getRoleX().getPrimaryKey(),
                    ORGANIZATION_MODEL_ACTION_IDS);
    
            // ORGANIZATION MODEL COMPANY PERMISSIONS
            ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
                    Organization.class.getName(), ResourceConstants.SCOPE_COMPANY,
                    Long.toString(companyId),
                    CiUtils.getRoleX().getPrimaryKey(),
                    ORGANIZATION_MODEL_ACTION_IDS);
    
            // PORTAL (portlet 90) PERMISSIONS
            ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
                    "90", ResourceConstants.SCOPE_COMPANY,
                    Long.toString(companyId),
                    CiUtils.getRoleX().getPrimaryKey(),
                    PORTAL_ACTION_IDS);
    
            // USER_ORG_ADMINS PORTLET (125) PERMISSIONS
            ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
                    "125", ResourceConstants.SCOPE_COMPANY,
                    Long.toString(companyId),
                    CiUtils.getRoleX().getPrimaryKey(),
                    USERS_ORG_ADMIN_ACTION_IDS);
    

    对于每个组织:

    ResourcePermissionLocalServiceUtil.setResourcePermissions(organization.getCompanyId(),
                                Organization.class.getName(),   ResourceConstants.SCOPE_INDIVIDUAL, Long                    .toString(organization.getPrimaryKey()),
                                    MyUtils.getRoleX().getPrimaryKey(),
                                    ORGANIZATION_ENTRY_ACTION_IDS);
            long groupId = organization.getGroupId();
    
            ResourcePermissionLocalServiceUtil.setResourcePermissions(
                        organization.getCompanyId(),Group.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,Long.toString(groupId),
                        MyUtils.getRoleX().getPrimaryKey(),
                        ORGANIZATION_GROUP_ENTRY_ACTION_IDS);
    

    希望这可以帮助其他人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      • 1970-01-01
      • 2021-09-23
      相关资源
      最近更新 更多