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.portlet.rolesadmin.search;
016    
017    import com.liferay.portal.kernel.dao.search.RowChecker;
018    import com.liferay.portal.model.Role;
019    import com.liferay.portal.service.PermissionLocalServiceUtil;
020    import com.liferay.portal.service.ResourceBlockLocalServiceUtil;
021    import com.liferay.portal.service.ResourcePermissionLocalServiceUtil;
022    import com.liferay.portal.service.ResourceTypePermissionLocalServiceUtil;
023    import com.liferay.portal.util.PropsValues;
024    
025    import javax.portlet.RenderResponse;
026    
027    /**
028     * @author Jorge Ferrer
029     * @author Connor McKay
030     */
031    public class ResourceActionRowChecker extends RowChecker {
032    
033            public ResourceActionRowChecker(RenderResponse renderResponse) {
034                    super(renderResponse);
035            }
036    
037            @Override
038            public boolean isChecked(Object obj) {
039                    try {
040                            return doIsChecked(obj);
041                    }
042                    catch (Exception e) {
043                            return false;
044                    }
045            }
046    
047            protected boolean doIsChecked(Object obj) throws Exception {
048                    Object[] objArray = (Object[])obj;
049    
050                    Role role = (Role)objArray[0];
051                    String actionId = (String)objArray[1];
052                    String resourceName = (String)objArray[2];
053                    Integer scope = (Integer)objArray[4];
054    
055                    if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
056                            if (ResourceBlockLocalServiceUtil.isSupported(resourceName)) {
057                                    return ResourceTypePermissionLocalServiceUtil.
058                                            hasEitherScopePermission(
059                                                    role.getCompanyId(), resourceName, role.getRoleId(),
060                                                    actionId);
061                            }
062    
063                            return
064                                    ResourcePermissionLocalServiceUtil.hasScopeResourcePermission(
065                                            role.getCompanyId(), resourceName, scope, role.getRoleId(),
066                                            actionId);
067                    }
068                    else {
069                            return PermissionLocalServiceUtil.hasRolePermission(
070                                    role.getRoleId(), role.getCompanyId(), resourceName, scope,
071                                    actionId);
072                    }
073            }
074    
075    }