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.AssetTag;
022    import com.liferay.portlet.asset.service.AssetTagLocalServiceUtil;
023    
024    /**
025     * @author Eduardo Lundgren
026     */
027    public class AssetTagPermission {
028    
029            public static void check(
030                            PermissionChecker permissionChecker, AssetTag tag, String actionId)
031                    throws PortalException {
032    
033                    if (!contains(permissionChecker, tag, actionId)) {
034                            throw new PrincipalException();
035                    }
036            }
037    
038            public static void check(
039                            PermissionChecker permissionChecker, long tagId, String actionId)
040                    throws PortalException, SystemException {
041    
042                    if (!contains(permissionChecker, tagId, actionId)) {
043                            throw new PrincipalException();
044                    }
045            }
046    
047            public static boolean contains(
048                    PermissionChecker permissionChecker, AssetTag tag, String actionId) {
049    
050                    if (permissionChecker.hasOwnerPermission(
051                                    tag.getCompanyId(), AssetTag.class.getName(), tag.getTagId(),
052                                    tag.getUserId(), actionId)) {
053    
054                            return true;
055                    }
056    
057                    return permissionChecker.hasPermission(
058                            tag.getGroupId(), AssetTag.class.getName(), tag.getTagId(),
059                            actionId);
060            }
061    
062            public static boolean contains(
063                            PermissionChecker permissionChecker, long tagId, String actionId)
064                    throws PortalException, SystemException {
065    
066                    AssetTag tag = AssetTagLocalServiceUtil.getTag(tagId);
067    
068                    return contains(permissionChecker, tag, actionId);
069            }
070    
071    }