001
014
015 package com.liferay.portlet.bookmarks.service.permission;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.security.auth.PrincipalException;
020 import com.liferay.portal.security.permission.ActionKeys;
021 import com.liferay.portal.security.permission.PermissionChecker;
022 import com.liferay.portal.util.PropsValues;
023 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
024 import com.liferay.portlet.bookmarks.model.BookmarksFolder;
025 import com.liferay.portlet.bookmarks.model.BookmarksFolderConstants;
026 import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
027
028
031 public class BookmarksEntryPermission {
032
033 public static void check(
034 PermissionChecker permissionChecker, BookmarksEntry entry,
035 String actionId)
036 throws PortalException, SystemException {
037
038 if (!contains(permissionChecker, entry, actionId)) {
039 throw new PrincipalException();
040 }
041 }
042
043 public static void check(
044 PermissionChecker permissionChecker, long entryId, String actionId)
045 throws PortalException, SystemException {
046
047 if (!contains(permissionChecker, entryId, actionId)) {
048 throw new PrincipalException();
049 }
050 }
051
052 public static boolean contains(
053 PermissionChecker permissionChecker, BookmarksEntry entry,
054 String actionId)
055 throws PortalException, SystemException {
056
057 if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {
058 if (entry.getFolderId() !=
059 BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
060
061 BookmarksFolder folder = entry.getFolder();
062
063 if (!BookmarksFolderPermission.contains(
064 permissionChecker, folder, ActionKeys.ACCESS) &&
065 !BookmarksFolderPermission.contains(
066 permissionChecker, folder, ActionKeys.VIEW)) {
067
068 return false;
069 }
070 }
071 }
072
073 if (permissionChecker.hasOwnerPermission(
074 entry.getCompanyId(), BookmarksEntry.class.getName(),
075 entry.getEntryId(), entry.getUserId(), actionId)) {
076
077 return true;
078 }
079
080 return permissionChecker.hasPermission(
081 entry.getGroupId(), BookmarksEntry.class.getName(),
082 entry.getEntryId(), actionId);
083 }
084
085 public static boolean contains(
086 PermissionChecker permissionChecker, long entryId, String actionId)
087 throws PortalException, SystemException {
088
089 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(entryId);
090
091 return contains(permissionChecker, entry, actionId);
092 }
093
094 }