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.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  }