Share

How to create custom permission in Liferay

1. Create one portlet
2. Create new folder named as reource-actions under docroot/WEB-INF/src
    now create defualt.xml file under resource-actions folder
3. This xml file defines all the resources and their permissions.It is like as follows

	
		permissionsExample
		
			
				ADD_PRODUCT
				ADD_TO_PAGE
				CONFIGURATION
				VIEW
				ACCESS_IN_CONTROL_PANEL
			
			
				VIEW
			
			
				VIEW
			
			
				ADD_ENTRY
				CONFIGURATION
			
		
	

In the above xml we are defining new resource with the id of the portlet in portlet-name tag.
Supports tag : It includes default action items and new one i.e ADD_PRODUCT
action-key : It tells the name of the action
community-defaults : it is deprecated instead of this one site-member-defaults came newly
site-member-defaults : The action items which site members can perform default
guest-defaults : The action items which guest users can perform default
guest-unsupported : The action items which guest users won't perform even can't assign permission to guest by administrators
There are some more tags please go through the DTD

4. Telling to the server register this resource into the permission system by doing the following entry in portlet.properties(create under docroot/WEB-INF/src)


resource.actions.configs=resource-actions/default.xml

5. Associate OR dis-associate a particular role from performing this action. The owner of this resource usually does this operation under Permissions tab of the portlet.

By default permissions

After defining new permissions lets see permissions tab of portlet

If you observe above image a new permission added with the given name but it has the prefix action.XXX
So to get exact name make an entry in Language.properties with the key as action.New Action Key Name


action.ADD_PRODUCT=Add Product

6. Last step is check the permission where ever you want before providing access by using PermissionChecker or PortalPermissionUtil.