mneethiraj commented on code in PR #1265:
URL: https://github.com/apache/ranger/pull/1265#discussion_r4130112242


##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerAccessRequestUtil.java:
##########
@@ -239,6 +240,28 @@ public static boolean getIsRequestPreprocessed(Map<String, 
Object> context) {
         return value != null && value;
     }
 
+    public static void setBatchEvalContext(Map<String, Object> context, 
RangerBatchEvalContext batchEvalContext) {
+        if (context != null && batchEvalContext != null) {
+            context.put(KEY_CONTEXT_BATCH_EVAL_CONTEXT, batchEvalContext);
+        }
+    }
+
+    public static RangerBatchEvalContext getBatchEvalContext(Map<String, 
Object> context) {
+        if (context == null) {
+            return null;
+        }
+
+        Object value = context.get(KEY_CONTEXT_BATCH_EVAL_CONTEXT);
+
+        return value instanceof RangerBatchEvalContext ? 
(RangerBatchEvalContext) value : null;
+    }
+
+    public static void removeBatchEvalContext(Map<String, Object> context, 
RangerBatchEvalContext batchEvalContext) {

Review Comment:
   Is `batchEvalContext` parameter necessary in `removeBatchEvalContext()`. I 
suggest removing it.



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerBatchEvalContext.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Not thread-safe. One instance per evaluation call; do not mutate a groups 
set during that call, because the hot key matches the same set instance.
+ */
+public class RangerBatchEvalContext {
+    private final Map<String, String> userNameMappings = new HashMap<>();
+    private final Map<IdentityKey, Set<String>> userGroupsMappings = new 
HashMap<>();
+    private final Map<IdentityKey, Set<String>> userRolesMappings = new 
HashMap<>();
+
+    private IdentityKey hotKey;
+    private String hotUser;
+    private Set<String> hotGroupsRef;
+
+    public boolean hasUserName(String user) {
+        return userNameMappings.containsKey(user);
+    }
+
+    public String getUserName(String user) {

Review Comment:
   `getUserName()` => `getMappedUserName()`



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerBatchEvalContext.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Not thread-safe. One instance per evaluation call; do not mutate a groups 
set during that call, because the hot key matches the same set instance.
+ */
+public class RangerBatchEvalContext {
+    private final Map<String, String> userNameMappings = new HashMap<>();
+    private final Map<IdentityKey, Set<String>> userGroupsMappings = new 
HashMap<>();
+    private final Map<IdentityKey, Set<String>> userRolesMappings = new 
HashMap<>();
+
+    private IdentityKey hotKey;
+    private String hotUser;
+    private Set<String> hotGroupsRef;
+
+    public boolean hasUserName(String user) {
+        return userNameMappings.containsKey(user);
+    }
+
+    public String getUserName(String user) {
+        return userNameMappings.get(user);
+    }
+
+    public void putUserName(String user, String normalizedUser) {

Review Comment:
   `putUserName()` => `setUserNameMapping()`



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerBatchEvalContext.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Not thread-safe. One instance per evaluation call; do not mutate a groups 
set during that call, because the hot key matches the same set instance.
+ */
+public class RangerBatchEvalContext {
+    private final Map<String, String> userNameMappings = new HashMap<>();
+    private final Map<IdentityKey, Set<String>> userGroupsMappings = new 
HashMap<>();
+    private final Map<IdentityKey, Set<String>> userRolesMappings = new 
HashMap<>();
+
+    private IdentityKey hotKey;
+    private String hotUser;
+    private Set<String> hotGroupsRef;
+
+    public boolean hasUserName(String user) {

Review Comment:
   `hasUserName()` => `hasMappingForUserName()`



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerBatchEvalContext.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Not thread-safe. One instance per evaluation call; do not mutate a groups 
set during that call, because the hot key matches the same set instance.
+ */
+public class RangerBatchEvalContext {
+    private final Map<String, String> userNameMappings = new HashMap<>();
+    private final Map<IdentityKey, Set<String>> userGroupsMappings = new 
HashMap<>();
+    private final Map<IdentityKey, Set<String>> userRolesMappings = new 
HashMap<>();
+
+    private IdentityKey hotKey;
+    private String hotUser;
+    private Set<String> hotGroupsRef;
+
+    public boolean hasUserName(String user) {
+        return userNameMappings.containsKey(user);
+    }
+
+    public String getUserName(String user) {
+        return userNameMappings.get(user);
+    }
+
+    public void putUserName(String user, String normalizedUser) {
+        userNameMappings.put(user, normalizedUser);
+    }
+
+    public boolean hasUserGroups(String user, Set<String> groups) {
+        return userGroupsMappings.containsKey(keyFor(user, groups));
+    }
+
+    public Set<String> getUserGroups(String user, Set<String> groups) {
+        return userGroupsMappings.get(keyFor(user, groups));
+    }
+
+    public void putUserGroups(String user, Set<String> groups, Set<String> 
normalizedGroups) {
+        userGroupsMappings.put(storedKey(user, groups), normalizedGroups);
+    }
+
+    public boolean hasUserRoles(String user, Set<String> groups) {

Review Comment:
   `hasUserRoles()` => `hasMappingForUserRoles()`



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerBatchEvalContext.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Not thread-safe. One instance per evaluation call; do not mutate a groups 
set during that call, because the hot key matches the same set instance.
+ */
+public class RangerBatchEvalContext {
+    private final Map<String, String> userNameMappings = new HashMap<>();
+    private final Map<IdentityKey, Set<String>> userGroupsMappings = new 
HashMap<>();
+    private final Map<IdentityKey, Set<String>> userRolesMappings = new 
HashMap<>();
+
+    private IdentityKey hotKey;
+    private String hotUser;
+    private Set<String> hotGroupsRef;
+
+    public boolean hasUserName(String user) {
+        return userNameMappings.containsKey(user);
+    }
+
+    public String getUserName(String user) {
+        return userNameMappings.get(user);
+    }
+
+    public void putUserName(String user, String normalizedUser) {
+        userNameMappings.put(user, normalizedUser);
+    }
+
+    public boolean hasUserGroups(String user, Set<String> groups) {

Review Comment:
   `hasUserGroups()` => `hasMappingForUserGroups()`



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerBatchEvalContext.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Not thread-safe. One instance per evaluation call; do not mutate a groups 
set during that call, because the hot key matches the same set instance.
+ */
+public class RangerBatchEvalContext {
+    private final Map<String, String> userNameMappings = new HashMap<>();
+    private final Map<IdentityKey, Set<String>> userGroupsMappings = new 
HashMap<>();
+    private final Map<IdentityKey, Set<String>> userRolesMappings = new 
HashMap<>();
+
+    private IdentityKey hotKey;
+    private String hotUser;
+    private Set<String> hotGroupsRef;
+
+    public boolean hasUserName(String user) {
+        return userNameMappings.containsKey(user);
+    }
+
+    public String getUserName(String user) {
+        return userNameMappings.get(user);
+    }
+
+    public void putUserName(String user, String normalizedUser) {
+        userNameMappings.put(user, normalizedUser);
+    }
+
+    public boolean hasUserGroups(String user, Set<String> groups) {
+        return userGroupsMappings.containsKey(keyFor(user, groups));
+    }
+
+    public Set<String> getUserGroups(String user, Set<String> groups) {
+        return userGroupsMappings.get(keyFor(user, groups));
+    }
+
+    public void putUserGroups(String user, Set<String> groups, Set<String> 
normalizedGroups) {

Review Comment:
   `putUserGroups()` => `setUserGroupsMapping()`



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerBatchEvalContext.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Not thread-safe. One instance per evaluation call; do not mutate a groups 
set during that call, because the hot key matches the same set instance.
+ */
+public class RangerBatchEvalContext {
+    private final Map<String, String> userNameMappings = new HashMap<>();
+    private final Map<IdentityKey, Set<String>> userGroupsMappings = new 
HashMap<>();
+    private final Map<IdentityKey, Set<String>> userRolesMappings = new 
HashMap<>();
+
+    private IdentityKey hotKey;
+    private String hotUser;
+    private Set<String> hotGroupsRef;
+
+    public boolean hasUserName(String user) {
+        return userNameMappings.containsKey(user);
+    }
+
+    public String getUserName(String user) {
+        return userNameMappings.get(user);
+    }
+
+    public void putUserName(String user, String normalizedUser) {
+        userNameMappings.put(user, normalizedUser);
+    }
+
+    public boolean hasUserGroups(String user, Set<String> groups) {
+        return userGroupsMappings.containsKey(keyFor(user, groups));
+    }
+
+    public Set<String> getUserGroups(String user, Set<String> groups) {

Review Comment:
   `getUserGroups()` => `getMappedUserGroups()`



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerBatchEvalContext.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Not thread-safe. One instance per evaluation call; do not mutate a groups 
set during that call, because the hot key matches the same set instance.
+ */
+public class RangerBatchEvalContext {
+    private final Map<String, String> userNameMappings = new HashMap<>();
+    private final Map<IdentityKey, Set<String>> userGroupsMappings = new 
HashMap<>();
+    private final Map<IdentityKey, Set<String>> userRolesMappings = new 
HashMap<>();
+
+    private IdentityKey hotKey;
+    private String hotUser;
+    private Set<String> hotGroupsRef;
+
+    public boolean hasUserName(String user) {
+        return userNameMappings.containsKey(user);
+    }
+
+    public String getUserName(String user) {
+        return userNameMappings.get(user);
+    }
+
+    public void putUserName(String user, String normalizedUser) {
+        userNameMappings.put(user, normalizedUser);
+    }
+
+    public boolean hasUserGroups(String user, Set<String> groups) {
+        return userGroupsMappings.containsKey(keyFor(user, groups));
+    }
+
+    public Set<String> getUserGroups(String user, Set<String> groups) {
+        return userGroupsMappings.get(keyFor(user, groups));
+    }
+
+    public void putUserGroups(String user, Set<String> groups, Set<String> 
normalizedGroups) {
+        userGroupsMappings.put(storedKey(user, groups), normalizedGroups);
+    }
+
+    public boolean hasUserRoles(String user, Set<String> groups) {
+        return userRolesMappings.containsKey(keyFor(user, groups));
+    }
+
+    public Set<String> getUserRoles(String user, Set<String> groups) {
+        return userRolesMappings.get(keyFor(user, groups));
+    }
+
+    public void putUserRoles(String user, Set<String> groups, Set<String> 
roles) {

Review Comment:
   `putUserRoles()` => `setUserRolesMapping()`



##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerBatchEvalContext.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.plugin.util;
+
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Not thread-safe. One instance per evaluation call; do not mutate a groups 
set during that call, because the hot key matches the same set instance.
+ */
+public class RangerBatchEvalContext {
+    private final Map<String, String> userNameMappings = new HashMap<>();
+    private final Map<IdentityKey, Set<String>> userGroupsMappings = new 
HashMap<>();
+    private final Map<IdentityKey, Set<String>> userRolesMappings = new 
HashMap<>();
+
+    private IdentityKey hotKey;
+    private String hotUser;
+    private Set<String> hotGroupsRef;
+
+    public boolean hasUserName(String user) {
+        return userNameMappings.containsKey(user);
+    }
+
+    public String getUserName(String user) {
+        return userNameMappings.get(user);
+    }
+
+    public void putUserName(String user, String normalizedUser) {
+        userNameMappings.put(user, normalizedUser);
+    }
+
+    public boolean hasUserGroups(String user, Set<String> groups) {
+        return userGroupsMappings.containsKey(keyFor(user, groups));
+    }
+
+    public Set<String> getUserGroups(String user, Set<String> groups) {
+        return userGroupsMappings.get(keyFor(user, groups));
+    }
+
+    public void putUserGroups(String user, Set<String> groups, Set<String> 
normalizedGroups) {
+        userGroupsMappings.put(storedKey(user, groups), normalizedGroups);
+    }
+
+    public boolean hasUserRoles(String user, Set<String> groups) {
+        return userRolesMappings.containsKey(keyFor(user, groups));
+    }
+
+    public Set<String> getUserRoles(String user, Set<String> groups) {

Review Comment:
   `getUserRoles()` => `getMappedUserRoles()`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to