001    /**
002     * Copyright (c) 2000-2010 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.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    }