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.wiki.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.wiki.model.WikiNode;
22  import com.liferay.portlet.wiki.service.WikiNodeLocalServiceUtil;
23  
24  /**
25   * <a href="WikiNodePermission.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class WikiNodePermission {
30  
31      public static void check(
32              PermissionChecker permissionChecker, long nodeId, String actionId)
33          throws PortalException, SystemException {
34  
35          if (!contains(permissionChecker, nodeId, actionId)) {
36              throw new PrincipalException();
37          }
38      }
39  
40      public static void check(
41              PermissionChecker permissionChecker, long groupId, String name,
42              String actionId)
43          throws PortalException, SystemException {
44  
45          if (!contains(permissionChecker, groupId, name, actionId)) {
46              throw new PrincipalException();
47          }
48      }
49  
50      public static void check(
51              PermissionChecker permissionChecker, WikiNode node, String actionId)
52          throws PortalException {
53  
54          if (!contains(permissionChecker, node, actionId)) {
55              throw new PrincipalException();
56          }
57      }
58  
59      public static boolean contains(
60              PermissionChecker permissionChecker, long nodeId, String actionId)
61          throws PortalException, SystemException {
62  
63          WikiNode node = WikiNodeLocalServiceUtil.getNode(nodeId);
64  
65          return contains(permissionChecker, node, actionId);
66      }
67  
68      public static boolean contains(
69              PermissionChecker permissionChecker, long groupId, String name,
70              String actionId)
71          throws PortalException, SystemException {
72  
73          WikiNode node = WikiNodeLocalServiceUtil.getNode(groupId, name);
74  
75          return contains(permissionChecker, node, actionId);
76      }
77  
78      public static boolean contains(
79          PermissionChecker permissionChecker, WikiNode node, String actionId) {
80  
81          if (permissionChecker.hasOwnerPermission(
82                  node.getCompanyId(), WikiNode.class.getName(), node.getNodeId(),
83                  node.getUserId(), actionId)) {
84  
85              return true;
86          }
87  
88          return permissionChecker.hasPermission(
89              node.getGroupId(), WikiNode.class.getName(), node.getNodeId(),
90              actionId);
91      }
92  
93  }