001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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    /**
025     * @author Eduardo Lundgren
026     * @author JorgeFerrer
027     */
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    }