dlmarion commented on code in PR #93:
URL: https://github.com/apache/accumulo-access/pull/93#discussion_r2670114861


##########
core/src/main/java/org/apache/accumulo/access/impl/AccessEvaluatorImpl.java:
##########
@@ -159,4 +166,59 @@ boolean evaluate(byte[] accessExpression) throws 
InvalidAccessExpressionExceptio
     };
     return ParserEvaluator.parseAccessExpression(accessExpression, atp, 
authToken -> true);
   }
+
+  private boolean canAccess(ParsedAccessExpression pae) {
+    switch (pae.getType()) {
+      case AND:
+        return canAccessParsedAnd(pae.getChildren());
+      case OR:
+        return canAccessParsedOr(pae.getChildren());
+      case AUTHORIZATION:
+        return canAccessParsedAuthorization(pae.getExpression());
+      case EMPTY:
+        return true;
+      default:
+        throw new IllegalArgumentException("Unhandled type: " + pae.getType());
+    }
+  }
+
+  private boolean canAccessParsedAnd(List<ParsedAccessExpression> children) {
+    requireNonNull(children, "null children list passed to method");
+    if (children.isEmpty() || children.size() < 2) {
+      throw new IllegalArgumentException(
+          "Malformed AND expression, children: " + children.size() + " -> " + 
children);
+    }
+    boolean result = true;
+    for (ParsedAccessExpression child : children) {
+      result &= canAccess(child);
+      if (result == false) {
+        return result;
+      }
+    }
+    return result;
+  }
+
+  private boolean canAccessParsedOr(List<ParsedAccessExpression> children) {
+    requireNonNull(children, "null children list passed to method");
+    if (children.isEmpty()) {
+      throw new IllegalArgumentException("Malformed OR expression, no 
children");
+    }
+    boolean result = false;
+    for (ParsedAccessExpression child : children) {
+      result |= canAccess(child);

Review Comment:
   Added in ee50096



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