Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
Stephan H
Using the permission system
8. November 2012 01:34
Antwort

Stephan H

Rang: New Member

Nachrichten: 15

Eintrittsdatum: 15. Februar 2012

Neue Beiträge

Hi all,

with the book "Liferay in Action" and the developer's guides I tried to write a test portlet that implements the permission system.

I extended the example in Service Builder (Foo) with a field for the groupId to store the Scope.

When creating an object, a resource, as in the the LiA example, is generated:
1resourceLocalService.addResources(newFoo.getCompanyId(), newFoo.getGroupId(), userId, Foo.class.getName(), foo.getPrimaryKey(), false, true, true);


The authorization defaults for resources are also available an referenced:
1resource.actions.configs=resource-actions/default.xml


 1<?xml version="1.0" encoding="UTF-8"?>
 2
 3<resource-action-mapping>
 4
 5  <portlet-resource>
 6    <portlet-name>test-permissions</portlet-name>
 7    <permissions>
 8      <supports>
 9        <action-key>ADD_FOO</action-key>
10        <action-key>VIEW</action-key>
11      </supports>
12      <site-member-defaults>
13        <action-key>VIEW</action-key>
14      </site-member-defaults>
15      <guest-defaults>
16        <action-key>VIEW</action-key>
17      </guest-defaults>
18
19      <guest-unsupported>
20        <action-key>ADD_FOO</action-key>
21      </guest-unsupported>
22    </permissions>
23  </portlet-resource>
24
25  <model-resource>
26    <model-name>
27      de.gwdg.test.permission.model.Foo
28    </model-name>
29    <portlet-ref>
30      <portlet-name>test-permissions</portlet-name>
31    </portlet-ref>
32    <permissions>
33      <supports>
34        <action-key>DELETE</action-key>
35        <action-key>PERMISSIONS</action-key>
36        <action-key>UPDATE</action-key>
37        <action-key>VIEW</action-key>
38      </supports>
39      <site-member-defaults>
40        <action-key>VIEW</action-key>
41      </site-member-defaults>
42      <guest-defaults>
43        <action-key>VIEW</action-key>
44      </guest-defaults>
45      <guest-unsupported>
46        <action-key>UPDATE</action-key>
47      </guest-unsupported>
48    </permissions>
49  </model-resource>
50
51</resource-action-mapping>


But the permission check for an entry does not work. I expect, that the owner, so the user who created the "Foo", also automatically gets all permissions on the entry. At least that is displayed in the "Permissions" for the entry. From the code example below, the buttons are only shown the administrator.

 1<%
 2ResultRow row = (ResultRow) request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
 3Foo myFoo = (Foo) row.getObject();
 4long groupId = themeDisplay.getLayout().getGroupId();
 5String name = Foo.class.getName();
 6String primKey = String.valueOf(myFoo.getPrimaryKey());
 7%>
 8<liferay-ui:icon-menu>
 9  <c:if test="<%= permissionChecker.hasPermission(groupId, name, primKey, ActionKeys.UPDATE) %>">
10    <portlet:actionURL name="editProduct" var="editURL">
11      <portlet:param name="resourcePrimKey" value="<%= primKey %>" />
12    </portlet:actionURL>
13
14    <liferay-ui:icon image="edit" message="Edit" url="<%= editURL.toString() %>" />
15  </c:if>
16
17 <c:if test="<%= permissionChecker.hasPermission(groupId, name, primKey, ActionKeys.PERMISSIONS) %>">
18    <liferay-security:permissionsURL
19        modelResource="<%= Foo.class.getName() %>"
20        modelResourceDescription="<%= String.valueOf(myFoo.getPrimaryKey()) %>"
21        resourcePrimKey="<%= primKey %>"
22        var="permissionsURL" />
23
24    <liferay-ui:icon image="permissions" url="<%= permissionsURL.toString() %>" />
25  </c:if>
26</liferay-ui:icon-menu>


What have I missed? Is something wrong with the permissionChecker call?

Stephan