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.portlet.exportimport.staging.permission;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portal.model.Group;
022    import com.liferay.portal.security.permission.ActionKeys;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    import com.liferay.portal.service.GroupLocalServiceUtil;
025    
026    /**
027     * @author Jorge Ferrer
028     */
029    @DoPrivileged
030    public class StagingPermissionImpl implements StagingPermission {
031    
032            @Override
033            public Boolean hasPermission(
034                    PermissionChecker permissionChecker, Group group, String className,
035                    long classPK, String portletId, String actionId) {
036    
037                    try {
038                            return doHasPermission(
039                                    permissionChecker, group, className, classPK, portletId,
040                                    actionId);
041                    }
042                    catch (Exception e) {
043                            _log.error(e, e);
044                    }
045    
046                    return null;
047            }
048    
049            @Override
050            public Boolean hasPermission(
051                    PermissionChecker permissionChecker, long groupId, String className,
052                    long classPK, String portletId, String actionId) {
053    
054                    try {
055                            Group group = GroupLocalServiceUtil.getGroup(groupId);
056    
057                            return doHasPermission(
058                                    permissionChecker, group, className, classPK, portletId,
059                                    actionId);
060                    }
061                    catch (Exception e) {
062                            _log.error(e, e);
063                    }
064    
065                    return null;
066            }
067    
068            protected Boolean doHasPermission(
069                            PermissionChecker permissionChecker, Group group, String className,
070                            long classPK, String portletId, String actionId)
071                    throws Exception {
072    
073                    if (!actionId.equals(ActionKeys.ACCESS_IN_CONTROL_PANEL) &&
074                            !actionId.equals(ActionKeys.ADD_TO_PAGE) &&
075                            !actionId.equals(ActionKeys.CONFIGURATION) &&
076                            !actionId.equals(ActionKeys.CUSTOMIZE) &&
077                            !actionId.equals(ActionKeys.DELETE) &&
078                            !actionId.equals(ActionKeys.VIEW) &&
079                            group.hasLocalOrRemoteStagingGroup() &&
080                            (Validator.isNull(portletId) || group.isStagedPortlet(portletId))) {
081    
082                            return false;
083                    }
084                    else {
085                            return null;
086                    }
087            }
088    
089            private static final Log _log = LogFactoryUtil.getLog(
090                    StagingPermissionImpl.class);
091    
092    }