1
22
23 package com.liferay.portlet.bookmarks.service.permission;
24
25 import com.liferay.portal.PortalException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.security.auth.PrincipalException;
28 import com.liferay.portal.security.permission.PermissionChecker;
29 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
30 import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
31
32
38 public class BookmarksEntryPermission {
39
40 public static void check(
41 PermissionChecker permissionChecker, long entryId,
42 String actionId)
43 throws PortalException, SystemException {
44
45 if (!contains(permissionChecker, entryId, actionId)) {
46 throw new PrincipalException();
47 }
48 }
49
50 public static void check(
51 PermissionChecker permissionChecker, BookmarksEntry entry,
52 String actionId)
53 throws PortalException {
54
55 if (!contains(permissionChecker, entry, actionId)) {
56 throw new PrincipalException();
57 }
58 }
59
60 public static boolean contains(
61 PermissionChecker permissionChecker, long entryId,
62 String actionId)
63 throws PortalException, SystemException {
64
65 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(entryId);
66
67 return contains(permissionChecker, entry, actionId);
68 }
69
70 public static boolean contains(
71 PermissionChecker permissionChecker, BookmarksEntry entry,
72 String actionId) {
73
74 if (permissionChecker.hasOwnerPermission(
75 entry.getCompanyId(), BookmarksEntry.class.getName(),
76 entry.getEntryId(), entry.getUserId(), actionId)) {
77
78 return true;
79 }
80
81 return permissionChecker.hasPermission(
82 entry.getGroupId(), BookmarksEntry.class.getName(),
83 entry.getEntryId(), actionId);
84 }
85
86 }