1
14
15 package com.liferay.portlet.tags.service.permission;
16
17 import com.liferay.portal.PortalException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.security.auth.PrincipalException;
20 import com.liferay.portal.security.permission.PermissionChecker;
21 import com.liferay.portlet.tags.model.TagsEntry;
22 import com.liferay.portlet.tags.model.TagsEntryConstants;
23 import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
24
25
30 public class TagsEntryPermission {
31
32 public static void check(
33 PermissionChecker permissionChecker, long groupId, long entryId,
34 String actionId)
35 throws PortalException, SystemException {
36
37 if (!contains(permissionChecker, groupId, entryId, actionId)) {
38 throw new PrincipalException();
39 }
40 }
41
42 public static void check(
43 PermissionChecker permissionChecker, long entryId, String actionId)
44 throws PortalException, SystemException {
45
46 if (!contains(permissionChecker, entryId, actionId)) {
47 throw new PrincipalException();
48 }
49 }
50
51 public static void check(
52 PermissionChecker permissionChecker, TagsEntry entry,
53 String actionId)
54 throws PortalException {
55
56 if (!contains(permissionChecker, entry, actionId)) {
57 throw new PrincipalException();
58 }
59 }
60
61 public static boolean contains(
62 PermissionChecker permissionChecker, long groupId, long entryId,
63 String actionId)
64 throws PortalException, SystemException {
65
66 if (entryId == TagsEntryConstants.DEFAULT_PARENT_ENTRY_ID) {
67 return TagsPermission.contains(
68 permissionChecker, groupId, actionId);
69 }
70 else {
71 return contains(permissionChecker, entryId, actionId);
72 }
73 }
74
75 public static boolean contains(
76 PermissionChecker permissionChecker, long entryId,
77 String actionId)
78 throws PortalException, SystemException {
79
80 TagsEntry entry = TagsEntryLocalServiceUtil.getEntry(entryId);
81
82 return contains(permissionChecker, entry, actionId);
83 }
84
85 public static boolean contains(
86 PermissionChecker permissionChecker, TagsEntry entry, String actionId) {
87
88 if (permissionChecker.hasOwnerPermission(
89 entry.getCompanyId(), TagsEntry.class.getName(),
90 entry.getEntryId(), entry.getUserId(), actionId)) {
91
92 return true;
93 }
94
95 return permissionChecker.hasPermission(
96 entry.getGroupId(), TagsEntry.class.getName(), entry.getEntryId(),
97 actionId);
98 }
99
100 }