1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.softwarecatalog.service.permission;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.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  }