001
014
015 package com.liferay.portlet.asset.service.permission;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.security.auth.PrincipalException;
020 import com.liferay.portal.security.permission.PermissionChecker;
021 import com.liferay.portlet.asset.model.AssetVocabulary;
022 import com.liferay.portlet.asset.service.AssetVocabularyLocalServiceUtil;
023
024
028 public class AssetVocabularyPermission {
029
030 public static void check(
031 PermissionChecker permissionChecker, AssetVocabulary vocabulary,
032 String actionId)
033 throws PortalException {
034
035 if (!contains(permissionChecker, vocabulary, actionId)) {
036 throw new PrincipalException();
037 }
038 }
039
040 public static void check(
041 PermissionChecker permissionChecker, long vocabularyId,
042 String actionId)
043 throws PortalException, SystemException {
044
045 if (!contains(permissionChecker, vocabularyId, actionId)) {
046 throw new PrincipalException();
047 }
048 }
049
050 public static boolean contains(
051 PermissionChecker permissionChecker, AssetVocabulary vocabulary,
052 String actionId) {
053
054 if (permissionChecker.hasOwnerPermission(
055 vocabulary.getCompanyId(), AssetVocabulary.class.getName(),
056 vocabulary.getVocabularyId(), vocabulary.getUserId(),
057 actionId)) {
058
059 return true;
060 }
061
062 return permissionChecker.hasPermission(
063 vocabulary.getGroupId(), AssetVocabulary.class.getName(),
064 vocabulary.getVocabularyId(), actionId);
065 }
066
067 public static boolean contains(
068 PermissionChecker permissionChecker, long vocabularyId,
069 String actionId)
070 throws PortalException, SystemException {
071
072 AssetVocabulary vocabulary =
073 AssetVocabularyLocalServiceUtil.getVocabulary(vocabularyId);
074
075 return contains(permissionChecker, vocabulary, actionId);
076 }
077
078 }