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.portal.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.staging.permission.StagingPermission;
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            public Boolean hasPermission(
033                    PermissionChecker permissionChecker, Group group, String className,
034                    long classPK, String portletId, String actionId) {
035    
036                    try {
037                            return doHasPermission(
038                                    permissionChecker, group, className, classPK, portletId,
039                                    actionId);
040                    }
041                    catch (Exception e) {
042                            _log.error(e, e);
043                    }
044    
045                    return null;
046            }
047    
048            public Boolean hasPermission(
049                    PermissionChecker permissionChecker, long groupId, String className,
050                    long classPK, String portletId, String actionId) {
051    
052                    try {
053                            Group group = GroupLocalServiceUtil.getGroup(groupId);
054    
055                            return doHasPermission(
056                                    permissionChecker, group, className, classPK, portletId,
057                                    actionId);
058                    }
059                    catch (Exception e) {
060                            _log.error(e, e);
061                    }
062    
063                    return null;
064            }
065    
066            protected Boolean doHasPermission(
067                            PermissionChecker permissionChecker, Group group, String className,
068                            long classPK, String portletId, String actionId)
069                    throws Exception {
070    
071                    if (!actionId.equals(ActionKeys.VIEW) &&
072                            !actionId.equals(ActionKeys.DELETE) && group.hasStagingGroup() &&
073                            group.isStagedPortlet(portletId)) {
074    
075                            return false;
076                    }
077                    else {
078                            return null;
079                    }
080            }
081    
082            private static Log _log = LogFactoryUtil.getLog(
083                    StagingPermissionImpl.class);
084    
085    }