001    /**
002     * Copyright (c) 2000-present 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.portal.kernel.security.permission;
016    
017    import com.liferay.exportimport.kernel.staging.permission.StagingPermissionUtil;
018    import com.liferay.portal.kernel.model.Group;
019    import com.liferay.portal.kernel.service.GroupLocalServiceUtil;
020    
021    /**
022     * @author Preston Crary
023     */
024    public abstract class BaseResourcePermissionChecker
025            implements ResourcePermissionChecker {
026    
027            public static boolean contains(
028                    PermissionChecker permissionChecker, String name, long classPK,
029                    String actionId) {
030    
031                    Group group = GroupLocalServiceUtil.fetchGroup(classPK);
032    
033                    if ((group != null) && group.isStagingGroup()) {
034                            classPK = group.getLiveGroupId();
035                    }
036    
037                    return permissionChecker.hasPermission(
038                            classPK, name, classPK, actionId);
039            }
040    
041            public static boolean contains(
042                    PermissionChecker permissionChecker, String name, String portletId,
043                    long classPK, String actionId) {
044    
045                    Boolean hasPermission = StagingPermissionUtil.hasPermission(
046                            permissionChecker, classPK, name, classPK, portletId, actionId);
047    
048                    if (hasPermission != null) {
049                            return hasPermission.booleanValue();
050                    }
051    
052                    return contains(permissionChecker, name, classPK, actionId);
053            }
054    
055    }