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