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