简体   繁体   中英

Set Site Permissions for a Role Programmatically Liferay 6.2

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

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});

I used CompanyThreadLocal to obtain the Company Id because I am using this in a hook not a portlet, where typically it would be accessed through the theme display. Here I am just adding access to Roles, but other class namespaces could be added. (eg. "com.liferay.portlet.dynamicdatalists.model.DDLRecordSet" )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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