1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.enterpriseadmin.search;
16  
17  import com.liferay.portal.kernel.dao.search.RowChecker;
18  import com.liferay.portal.model.Role;
19  import com.liferay.portal.service.PermissionLocalServiceUtil;
20  import com.liferay.portal.service.ResourcePermissionLocalServiceUtil;
21  import com.liferay.portal.util.PropsValues;
22  
23  import javax.portlet.RenderResponse;
24  
25  /**
26   * <a href="ResourceActionRowChecker.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Jorge Ferrer
29   */
30  public class ResourceActionRowChecker extends RowChecker {
31  
32      public ResourceActionRowChecker(RenderResponse renderResponse) {
33          super(renderResponse);
34      }
35  
36      public boolean isChecked(Object obj) {
37          try {
38              return doIsChecked(obj);
39          }
40          catch (Exception e) {
41              return false;
42          }
43      }
44  
45      protected boolean doIsChecked(Object obj) throws Exception {
46          Object[] objArray = (Object[])obj;
47  
48          Role role = (Role)objArray[0];
49          String actionId = (String)objArray[1];
50          String resourceName = (String)objArray[2];
51          Integer scope = (Integer)objArray[4];
52  
53          if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
54              return
55                  ResourcePermissionLocalServiceUtil.hasScopeResourcePermission(
56                      role.getCompanyId(), resourceName, scope, role.getRoleId(),
57                      actionId);
58          }
59          else {
60              return PermissionLocalServiceUtil.hasRolePermission(
61                  role.getRoleId(), role.getCompanyId(), resourceName, scope,
62                  actionId);
63          }
64      }
65  
66  }