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.enterpriseadmin.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.ResourcePermissionLocalServiceUtil;
021    import com.liferay.portal.util.PropsValues;
022    
023    import javax.portlet.RenderResponse;
024    
025    /**
026     * @author Jorge Ferrer
027     */
028    public class ResourceActionRowChecker extends RowChecker {
029    
030            public ResourceActionRowChecker(RenderResponse renderResponse) {
031                    super(renderResponse);
032            }
033    
034            public boolean isChecked(Object obj) {
035                    try {
036                            return doIsChecked(obj);
037                    }
038                    catch (Exception e) {
039                            return false;
040                    }
041            }
042    
043            protected boolean doIsChecked(Object obj) throws Exception {
044                    Object[] objArray = (Object[])obj;
045    
046                    Role role = (Role)objArray[0];
047                    String actionId = (String)objArray[1];
048                    String resourceName = (String)objArray[2];
049                    Integer scope = (Integer)objArray[4];
050    
051                    if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
052                            return
053                                    ResourcePermissionLocalServiceUtil.hasScopeResourcePermission(
054                                            role.getCompanyId(), resourceName, scope, role.getRoleId(),
055                                            actionId);
056                    }
057                    else {
058                            return PermissionLocalServiceUtil.hasRolePermission(
059                                    role.getRoleId(), role.getCompanyId(), resourceName, scope,
060                                    actionId);
061                    }
062            }
063    
064    }