001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }