I am using Liferay 6.1 and I have written below code for defining permissions for custom roles
1
2
3 Role role = RoleLocalServiceUtil.fetchRole(companyId, RoleType.ORGANIZATION_MANAGER);
4 int scope = ResourceConstants.SCOPE_GROUP_TEMPLATE;
5 long roleId = role.getRoleId();
6 long companyId = role.getCompanyId();
7 String primKey = String.valueOf(companyId);
8 String name = "com.liferay.portlet.blogs";
9 String actionIds[] = new String[] {ActionKeys.ADD_ENTRY, ActionKeys.SUBSCRIBE};
10
11 try{
12 if (_PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
13 ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, name, scope, primKey, roleId, actionIds);
14 }
15 else {
16 PermissionLocalServiceUtil.setRolePermissions(roleId, companyId, name, scope, primKey, actionIds);
17 }
18 }catch(Exception e){
19 e.printStackTrace();
20 }
This code does not throw any exception and when I navigate to Control Panel ==> Role Admin section, it shows that check box selected for the required permissions. But in actual, the permissions are not assigned. When I click on SAVE from Control Panel, then the permissions are getting assigned and it reflects in the portlets.
What am I doing wrong here? Any help please?
Regards,
Nilesh