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