Copilot commented on code in PR #743:
URL: https://github.com/apache/ranger/pull/743#discussion_r2551177799


##########
agents-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerInlinePolicyEvaluator.java:
##########
@@ -0,0 +1,307 @@
+/*
+ * 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.policyevaluator;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.ranger.authz.api.RangerAuthzException;
+import org.apache.ranger.plugin.model.RangerInlinePolicy;
+import org.apache.ranger.plugin.model.RangerPolicy;
+import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
+import org.apache.ranger.plugin.model.RangerPrincipal;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
+import org.apache.ranger.plugin.policyengine.RangerAccessRequestWrapper;
+import org.apache.ranger.plugin.policyengine.RangerAccessResult;
+import org.apache.ranger.plugin.policyengine.RangerPolicyEngine;
+import 
org.apache.ranger.plugin.policyresourcematcher.RangerDefaultPolicyResourceMatcher;
+import 
org.apache.ranger.plugin.policyresourcematcher.RangerPolicyResourceMatcher;
+import org.apache.ranger.plugin.util.RangerAccessRequestUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class RangerInlinePolicyEvaluator {
+    private static final Logger LOG = 
LoggerFactory.getLogger(RangerInlinePolicyEvaluator.class);
+
+    private static final String PRINCIPAL_G_PUBLIC = 
RangerPrincipal.PREFIX_GROUP + RangerPolicyEngine.GROUP_PUBLIC;
+
+    private final RangerInlinePolicy   policy;
+    private final RangerPolicyEngine   policyEngine;
+    private final List<GrantEvaluator> grants;
+
+    public RangerInlinePolicyEvaluator(RangerInlinePolicy policy, 
RangerPolicyEngine policyEngine) {
+        this.policy       = policy;
+        this.policyEngine = policyEngine;
+        this.grants       = toGrantEvaluators(policy);
+
+        LOG.debug("RangerInlinePolicyEvaluator(policy={})", policy);
+    }
+
+    @Override
+    public String toString() {
+        return toString(new StringBuilder()).toString();
+    }
+
+    public void evaluate(RangerAccessRequest request, RangerAccessResult 
result) {
+        LOG.debug("==> RangerInlinePolicyEvaluator.evaluate({}, {}, {})", 
policy, request, result);
+
+        if (request != null && result != null) {
+            boolean isAllowed = result.getIsAccessDetermined() && 
result.getIsAllowed();
+            boolean evalInlinePolicy;
+
+            if (policy.getMode() == null || policy.getMode() == 
RangerInlinePolicy.Mode.INLINE) {
+                evalInlinePolicy = true; // request must be allowed by the 
inline policy
+            } else if (policy.getMode() == 
RangerInlinePolicy.Mode.RANGER_AND_INLINE) {
+                evalInlinePolicy = isAllowed; // if not allowed by Ranger 
policies, no need to evaluate inline policy
+            } else { // RANGER_OR_ONLINE

Review Comment:
   Corrected spelling of 'RANGER_OR_ONLINE' to 'RANGER_OR_INLINE' in the 
comment.
   ```suggestion
               } else { // RANGER_OR_INLINE
   ```



-- 
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