UnderStanding the Resource Permission


This article explains about the basic flow of the resources, how they are applied.

1. Create the Portlet with the Name as "TestPermission"

2. Create service.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd">
<service-builder package-path="com.service">

<author>Test</author>
<namespace>Test</namespace>

<entity name="Bus" local-service="true">
        <column name="id" type="long" primary="true"></column>
        <column name="registration" type="String"></column>
        <column name="wheels" type="String"></column>
    </entity>

</service-builder>



Build the services, automatically classes will be generated

3. Create "resource-action" folder in the Src folder

4. Create the default.xml in the "resource-action" folder with the following entries
<?xml version="1.0"?>
 <resource-action-mapping>
     <portlet-resource>
         <portlet-name>TestPermission</portlet-name>
         <permissions>
            <supports>              
                <action-key>VIEW</action-key>
                <action-key>ADD_BUS</action-key>
            </supports>
            <site-member-defaults/>
            <guest-defaults>
                <action-key>VIEW</action-key>
            </guest-defaults>
            <guest-unsupported>              
                <action-key>ADD_BUS</action-key>
            </guest-unsupported>
        </permissions>
    </portlet-resource>
   
    <model-resource>
    <model-name>com.service.model.Bus</model-name>
<portlet-ref>
<portlet-name>TestPermission</portlet-name>
</portlet-ref>
<supports>
<action-key>DELETE</action-key>
<action-key>PERMISSIONS</action-key>
<action-key>UPDATE</action-key>
<action-key>VIEW</action-key>
</supports>
<site-member-defaults>
<action-key>VIEW</action-key>
</site-member-defaults>
<guest-defaults>
<action-key>VIEW</action-key>
</guest-defaults>
<guest-unsupported>
<action-key>UPDATE</action-key>
</guest-unsupported>
</model-resource>
</resource-action-mapping>



Here "portlet resource" are related to the Portlet and "model resource" related to the each bus we are adding in the DB.

5. Create the "portlet.properties" file in the src and paste the following content
resource.actions.configs=resource-actions/default.xml

6. Deploy the portlet, After deployment we will see the entries in the "resourceaction" table


   Look into these classes , following methods are invoked during the deployment
   1. PortletHotDeployListener.java : doInvokeDeploy(-);
              ResourceActionsUtil.getPortletResourceActions
 ResourceActionLocalServiceUtil.checkResourceActions
 ResourceActionsUtil.getModelResourceActions
 ResourceActionLocalServiceUtil.checkResourceActions

 long resourceActionId = counterLocalService.increment(ResourceAction.class.getName());
resourceAction = resourceActionPersistence.create(resourceActionId);
resourceAction.setName(name);
resourceAction.setActionId(actionId);
resourceAction.setBitwiseValue(bitwiseValue);
resourceActionPersistence.update(resourceAction);



It uses the bitWiseValue to increment like this as lastBitwiseValue = lastBitwiseValue << 1;

7. Also we can see the "portlet resource" in the settings/configuration path.

8. We can check the permission from the following conditions in jsp/class.

ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
long groupId = themeDisplay.getScopeGroupId();

boolean view = permissionChecker.hasPermission(groupId, "com.service.model.Bus", 1l, ActionKeys.VIEW);
boolean update = permissionChecker.hasPermission(groupId, "com.service.model.Bus", 1l, ActionKeys.UPDATE);



Comments

  1. I struggled more during the period after my schooling. I had struggled a lot in taking a decision on choosing what course to study and which college. A lot of advice are got at that time, but don't know what to choose. Finally I decided to chose one college with a particular course. Then I got admission to that top college itself by the help of admission essay writing service.

    ReplyDelete

Post a Comment

Popular posts from this blog

Theme display in javascript

How to know which liferay version we are using

Viewing the SQL Query in liferay : debugging the SQL Query in Hibernate