在 Liferay 7 中,如何将用户角色配置为不继承来宾权限?

In Liferay 7, How do I configure the User role to NOT inherit Guest permissions?

我正在 Liferay 7 上构建一个站点。默认情况下,所有经过身份验证的用户都继承来宾权限(匿名用户)。

权限部分甚至还有一个标签:

"Under the current configuration, all users automatically inherit permissions from the Guest role."

我为什么需要这个?

我想只为匿名用户显示 X 内容,当用户登录时,我想显示不同的内容。


我的匿名用户内容权限是这样配置的:

Why do I need this?

权限并不是显示不同内容的全部。如果访客不允许看到某些内容,但需要登录 - 没关系。这是经过身份验证的内容,您需要登录。

如果已验证用户没有查看某些内容的权限,但只是需要注销以查看它:那是什么样的权限?让我为您回答:这不是许可。它更像是有针对性的内容,虽然它可能被权限模仿,但这种模仿只不过是模仿。

实现这种要求的一种方法是通过结构化的 Web 内容(听起来好像您想显示不同的 Web 内容文章)。该模板可以访问完整的 API 并且可以检查当前用户是否已登录 - 并根据此事实显示不同的内容。

回答您的问题 - 您不能为每个特定资产配置 !默认情况下,经过身份验证的用户不能拥有比未经身份验证的用户更少的权限。正如@Victor 正确指出的那样,您可以使用 permissions.check.guest.enabled=false 更改 所有资产 的行为!

虽然我同意有人说这不是最好的方法,但是你可以这样做 - 只是为了解决手头的问题。

Set this to true if resources should assume that all users have the Guest role. Set this to false if resources will not assume that all users have the Guest role and, thus, do not automatically inherit permissions that belong to the Guest role.

Setting this property to false may require users to grant permissions to roles like Site Member and User.
Defaults:

    permissions.check.guest.enabled=true

如果您想像 xxxlocalserviceImpl 那样使用代码级别实现角色权限 class.You 可以使用以下代码来允许来宾用户的权限。

如果文档和媒体允许使用 rest webservice 在 Liferay 7 中来宾和注册用户,您可以使用此代码允许使用此代码上传和下载文档的权限。

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId,
                                DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL,
                                String.valueOf(dlFileEntry.getFileEntryId()), guestRole.getRoleId(),
                                new String[] { ActionKeys.VIEW });