1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
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  /**
28   * <a href="BookmarksEntryPermission.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
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  }