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.model.GroupConstants;
20  import com.liferay.portal.security.auth.PrincipalException;
21  import com.liferay.portal.security.permission.PermissionChecker;
22  import com.liferay.portlet.softwarecatalog.model.SCLicense;
23  import com.liferay.portlet.softwarecatalog.service.SCLicenseLocalServiceUtil;
24  
25  /**
26   * <a href="SCLicensePermission.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Jorge Ferrer
29   * @author Brian Wing Shun Chan
30   */
31  public class SCLicensePermission {
32  
33      public static void check(
34              PermissionChecker permissionChecker, long productEntryId,
35              String actionId)
36          throws PortalException, SystemException {
37  
38          if (!contains(permissionChecker, productEntryId, actionId)) {
39              throw new PrincipalException();
40          }
41      }
42  
43      public static void check(
44              PermissionChecker permissionChecker, SCLicense license,
45              String actionId)
46          throws PortalException {
47  
48          if (!contains(permissionChecker, license, actionId)) {
49              throw new PrincipalException();
50          }
51      }
52  
53      public static boolean contains(
54              PermissionChecker permissionChecker, long licenseId,
55              String actionId)
56          throws PortalException, SystemException {
57  
58          SCLicense license = SCLicenseLocalServiceUtil.getLicense(licenseId);
59  
60          return contains(permissionChecker, license, actionId);
61      }
62  
63      public static boolean contains(
64          PermissionChecker permissionChecker, SCLicense license,
65          String actionId) {
66  
67          return permissionChecker.hasPermission(
68              GroupConstants.DEFAULT_PARENT_GROUP_ID, SCLicense.class.getName(),
69              license.getLicenseId(), actionId);
70      }
71  
72  }