Repository: ranger
Updated Branches:
  refs/heads/master 9ed210470 -> 91a437a29


RANGER-1993:Improvement on permission module for listing modules

Signed-off-by: Mehul Parikh <me...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/91a437a2
Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/91a437a2
Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/91a437a2

Branch: refs/heads/master
Commit: 91a437a29cd58902dc49b422e0421e36c7a07039
Parents: 9ed2104
Author: fatimaawez <fatimakhan4...@gmail.com>
Authored: Tue Feb 27 14:57:15 2018 +0530
Committer: Mehul Parikh <me...@apache.org>
Committed: Thu Mar 1 10:14:58 2018 +0530

----------------------------------------------------------------------
 .../plugin/store/AbstractPredicateUtil.java     | 22 +++++++++++++-------
 .../ranger/service/XModuleDefServiceBase.java   | 14 +++++++++----
 2 files changed, 24 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/91a437a2/agents-common/src/main/java/org/apache/ranger/plugin/store/AbstractPredicateUtil.java
----------------------------------------------------------------------
diff --git 
a/agents-common/src/main/java/org/apache/ranger/plugin/store/AbstractPredicateUtil.java
 
b/agents-common/src/main/java/org/apache/ranger/plugin/store/AbstractPredicateUtil.java
index a139443..1e3f145 100644
--- 
a/agents-common/src/main/java/org/apache/ranger/plugin/store/AbstractPredicateUtil.java
+++ 
b/agents-common/src/main/java/org/apache/ranger/plugin/store/AbstractPredicateUtil.java
@@ -462,10 +462,13 @@ public class AbstractPredicateUtil {
                                                List<RangerPolicyItem> 
policyItems = (List<RangerPolicyItem>)policyItemsObj;
 
                                                for(RangerPolicyItem policyItem 
: policyItems) {
-                                                       
if(policyItem.getUsers().contains(userName)) {
-                                                               ret = true;
-
-                                                               break;
+                                                        if(! 
policyItem.getUsers().isEmpty()) {
+                                                                for(String 
user : policyItem.getUsers()) {
+                                                                        
if(StringUtils.containsIgnoreCase(user, userName)) {
+                                                                               
 ret = true;
+                                                                               
 break;
+                                                                        }
+                                                                }
                                                        }
                                                }
                                                if (ret) {
@@ -517,10 +520,13 @@ public class AbstractPredicateUtil {
                                                List<RangerPolicyItem> 
policyItems = (List<RangerPolicyItem>)policyItemsObj;
 
                                                for(RangerPolicyItem policyItem 
: policyItems) {
-                                                       
if(policyItem.getGroups().contains(groupName)) {
-                                                               ret = true;
-
-                                                               break;
+                                                        if(! 
policyItem.getGroups().isEmpty()) {
+                                                                for(String 
group : policyItem.getGroups()) {
+                                                                        
if(StringUtils.containsIgnoreCase(group, groupName)) {
+                                                                               
 ret = true;
+                                                                               
 break;
+                                                                        }
+                                                                }
                                                        }
                                                }
                                                if (ret) {

http://git-wip-us.apache.org/repos/asf/ranger/blob/91a437a2/security-admin/src/main/java/org/apache/ranger/service/XModuleDefServiceBase.java
----------------------------------------------------------------------
diff --git 
a/security-admin/src/main/java/org/apache/ranger/service/XModuleDefServiceBase.java
 
b/security-admin/src/main/java/org/apache/ranger/service/XModuleDefServiceBase.java
index 57cc694..adf4358 100644
--- 
a/security-admin/src/main/java/org/apache/ranger/service/XModuleDefServiceBase.java
+++ 
b/security-admin/src/main/java/org/apache/ranger/service/XModuleDefServiceBase.java
@@ -26,7 +26,8 @@ import org.apache.ranger.common.SearchCriteria;
 import org.apache.ranger.entity.XXModuleDef;
 import org.apache.ranger.view.VXModuleDef;
 import org.apache.ranger.view.VXModuleDefList;
-
+import java.util.Map;
+import java.util.HashMap;
 public abstract class XModuleDefServiceBase<T extends XXModuleDef, V extends 
VXModuleDef>
                extends AbstractBaseResourceService<T, V> {
 
@@ -58,16 +59,21 @@ public abstract class XModuleDefServiceBase<T extends 
XXModuleDef, V extends VXM
        public VXModuleDefList searchModuleDef(SearchCriteria searchCriteria) {
                VXModuleDefList returnList = new VXModuleDefList();
                List<VXModuleDef> vXModuleDefList = new 
ArrayList<VXModuleDef>();
-
+                searchCriteria.setMaxRows(Integer.MAX_VALUE);
                List<T> resultList = searchResources(searchCriteria,
                                searchFields, sortFields, returnList);
+                Map<Long, T> matchModule = new HashMap<Long,T>();
+                for (T moduleDef : resultList) {
+                        matchModule.put(moduleDef.getId(),  moduleDef);
+                }
 
+                List <T> moduleDefList=new ArrayList<T>(matchModule.values());
                // Iterate over the result list and create the return list
-               for (T gjXModuleDef : resultList) {
+                for (T gjXModuleDef : moduleDefList) {
                        VXModuleDef vXModuleDef = 
populateViewBean(gjXModuleDef);
                        vXModuleDefList.add(vXModuleDef);
                }
-
+                returnList.setTotalCount(vXModuleDefList.size());
                returnList.setvXModuleDef(vXModuleDefList);
                return returnList;
        }

Reply via email to