留言板

Set Site Permissions for a Role Programmatically Liferay 6.2

Amanda Pirner,修改在10 年前。

Set Site Permissions for a Role Programmatically Liferay 6.2

New Member 帖子: 5 加入日期: 14-2-7 最近的帖子
I am creating a startup hook script for liferay to add and preconfigure Roles for Liferay 6.2 behind the scenes.
Specifically I am looking to add the type of permissions that can be accessed through Control Panel > Roles > Actions> Define Permissions.

Currently I am able to add Liferay Roles, but have so far been unsuccessful in finding the correct way to add custom permissions to the Roles programmatically. I see there was a way to do this in prior Liferay versions, but do not see it here.

https://www.liferay.com/community/forums/-/message_boards/message/2965424
https://www.liferay.com/web/guest/community/forums/-/message_boards/message/124558

So far I have investigated RolePermissionUtil, RoleLocalServiceUtil, among other available services.

Let me know if this is available through the service to be added to a startup hook or if this can only be done in the UI.


It appears that the API has changed since these posts.

Thank you in advance for your help
Amanda Pirner,修改在10 年前。

RE: Set Site Permissions for a Role Programmatically Liferay 6.2

New Member 帖子: 5 加入日期: 14-2-7 最近的帖子
Currently I am looking into LR source code to see how this is done through portal-web/docroot/html/portlet/roles_admin/* jsp files and related classes.
Amanda Pirner,修改在10 年前。

RE: Set Site Permissions for a Role Programmatically Liferay 6.2 (答复)

New Member 帖子: 5 加入日期: 14-2-7 最近的帖子
Figured it out using ResourcePermissionLocalServiceUtil.setResourcePermissions and RoleLocalServiceUtil.

Eg.

RoleLocalServiceUtil.fetchRole(CompanyThreadLocal.getCompanyId(), "Role Name");
ResourcePermissionLocalServiceUtil.setResourcePermissions(CompanyThreadLocal.getCompanyId(), Role.class.getName(), ResourceConstants.SCOPE_GROUP_TEMPLATE, String.valueOf(role.getRoleId()), role.getRoleId(), new String[] {ActionKeys.VIEW, ActionKeys.UPDATE, ActionKeys.DELETE});