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.asset.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.asset.model.AssetTag;
22  import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
23  
24  /**
25   * <a href="AssetTagPermission.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Eduardo Lundgren
28   */
29  public class AssetTagPermission {
30  
31      public static void check(
32              PermissionChecker permissionChecker, AssetTag tag, String actionId)
33          throws PortalException {
34  
35          if (!contains(permissionChecker, tag, actionId)) {
36              throw new PrincipalException();
37          }
38      }
39  
40      public static void check(
41              PermissionChecker permissionChecker, long tagId, String actionId)
42          throws PortalException, SystemException {
43  
44          if (!contains(permissionChecker, tagId, actionId)) {
45              throw new PrincipalException();
46          }
47      }
48  
49      public static boolean contains(
50          PermissionChecker permissionChecker, AssetTag tag, String actionId) {
51  
52          if (permissionChecker.hasOwnerPermission(
53                  tag.getCompanyId(), AssetTag.class.getName(), tag.getTagId(),
54                  tag.getUserId(), actionId)) {
55  
56              return true;
57          }
58  
59          return permissionChecker.hasPermission(
60              tag.getGroupId(), AssetTag.class.getName(), tag.getTagId(),
61              actionId);
62      }
63  
64      public static boolean contains(
65              PermissionChecker permissionChecker, long tagId, String actionId)
66          throws PortalException, SystemException {
67  
68          AssetTag tag = AssetTagLocalServiceUtil.getTag(tagId);
69  
70          return contains(permissionChecker, tag, actionId);
71      }
72  
73  }