1
14
15 package com.liferay.portlet.bookmarks.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.ActionKeys;
21 import com.liferay.portal.security.permission.PermissionChecker;
22 import com.liferay.portal.util.PropsValues;
23 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
24 import com.liferay.portlet.bookmarks.model.BookmarksFolder;
25 import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
26
27
32 public class BookmarksEntryPermission {
33
34 public static void check(
35 PermissionChecker permissionChecker, BookmarksEntry entry,
36 String actionId)
37 throws PortalException, SystemException {
38
39 if (!contains(permissionChecker, entry, actionId)) {
40 throw new PrincipalException();
41 }
42 }
43
44 public static void check(
45 PermissionChecker permissionChecker, long entryId,
46 String actionId)
47 throws PortalException, SystemException {
48
49 if (!contains(permissionChecker, entryId, actionId)) {
50 throw new PrincipalException();
51 }
52 }
53
54 public static boolean contains(
55 PermissionChecker permissionChecker, BookmarksEntry entry,
56 String actionId)
57 throws PortalException, SystemException {
58
59 BookmarksFolder folder = entry.getFolder();
60
61 if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {
62 if (!BookmarksFolderPermission.contains(
63 permissionChecker, folder, ActionKeys.VIEW)) {
64
65 return false;
66 }
67 }
68
69 if (permissionChecker.hasOwnerPermission(
70 entry.getCompanyId(), BookmarksEntry.class.getName(),
71 entry.getEntryId(), entry.getUserId(), actionId)) {
72
73 return true;
74 }
75
76 return permissionChecker.hasPermission(
77 entry.getGroupId(), BookmarksEntry.class.getName(),
78 entry.getEntryId(), actionId);
79 }
80
81 public static boolean contains(
82 PermissionChecker permissionChecker, long entryId,
83 String actionId)
84 throws PortalException, SystemException {
85
86 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(entryId);
87
88 return contains(permissionChecker, entry, actionId);
89 }
90
91 }