Liferay 7: override Resource Permissions
by Stanislav on Saturday Jul 22, 2017
In Liferay 6 when you needed to change default permission set for some resource, then Ext plugin could be used to override such definitions. The reason of Ext using was the point that all permission definitions were stored in portal-impl.jar and Ext was the only way to override it. Starting from Liferay 7 the portal is moving to OSGi architecture where the other rules take place. Since now each OSGi module (e.g. Calendar) has its permissions defined in its own module, and not in the core of the portal. That’s why a new approach should be applied and this post shows how to achieve this.
In OSGi concept, each bundle’s own classpath is of higher priority than the other fragment modules (the ones that supposed to extend the current one). That means that the configuration defined in a fragment module won’t override the target bundle. So how should we proceed then? What should be done to be able to change guest defaults, supported and unsupported permissions for site members and others on a resource? Such possibility appeared only since Liferay 7-GA4, where the following should be done (a Calendar took as an example):
- Create a new fragment module that will override Calendar default permissions. It’s bnd.bnd file should include:
- Put portlet-ext.properties into the root of the current module. Its content:
- Create a new file /resource-actions/default-ext.xml that will be a copy of Calendar permissions definition with the custom modification. It will look as usual:
<?xml version="1.0"?> <!DOCTYPE resource-action-mapping PUBLIC "-//Liferay//DTD Resource Action Mapping 6.2.0//EN" "http://www.liferay.com/dtd/liferay-resource-action-mapping_6_2_0.dtd"> <resource-action-mapping> <model-resource> <model-name>com.liferay.calendar</model-name> <portlet-ref> <portlet-name>com_liferay_calendar_web_portlet_CalendarPortlet</portlet-name> </portlet-ref> <root>true</root> <permissions> <supports> <action-key>ADD_RESOURCE</action-key> <action-key>PERMISSIONS</action-key> </supports> <site-member-defaults /> <!-- Guest default permission VIEW removed --> <guest-defaults /> <guest-unsupported> <action-key>ADD_RESOURCE</action-key> <action-key>PERMISSIONS</action-key> </guest-unsupported> </permissions> </model-resource> </resource-action-mapping>
- Build the module and deploy it to portal.
After deployment your custom permissions will be applied.
This approach will work only starting from Liferay 7-GA4, but it’s a good beginning that makes Liferay OSGi more flexible and customizable.