keith-turner commented on code in PR #96:
URL: https://github.com/apache/accumulo-access/pull/96#discussion_r2677814737
##########
core/src/main/java/org/apache/accumulo/access/impl/AccessEvaluatorImpl.java:
##########
@@ -30,42 +29,56 @@
import org.apache.accumulo.access.AccessEvaluator;
import org.apache.accumulo.access.AccessExpression;
+import org.apache.accumulo.access.AuthorizationValidator;
import org.apache.accumulo.access.Authorizations;
import org.apache.accumulo.access.InvalidAccessExpressionException;
+import org.apache.accumulo.access.InvalidAuthorizationException;
public final class AccessEvaluatorImpl implements AccessEvaluator {
- private final Predicate<BytesWrapper> authorizedPredicate;
+ private final Predicate<CharSequence> authorizedPredicate;
+ // TODO set
+ private final AuthorizationValidator authorizationValidator;
/**
* Create an AccessEvaluatorImpl using an Authorizer object
*/
- public AccessEvaluatorImpl(Authorizer authorizationChecker) {
- this.authorizedPredicate = auth ->
authorizationChecker.isAuthorized(unescape(auth));
+ public AccessEvaluatorImpl(Authorizer authorizationChecker,
+ AuthorizationValidator authorizationValidator) {
+ this.authorizedPredicate = auth ->
authorizationChecker.isAuthorized(auth.toString());
+ this.authorizationValidator = authorizationValidator;
}
/**
* Create an AccessEvaluatorImpl using a collection of authorizations
*/
- public AccessEvaluatorImpl(Authorizations authorizations) {
+ public AccessEvaluatorImpl(Authorizations authorizations,
+ AuthorizationValidator authorizationValidator) {
var authsSet = authorizations.asSet();
- final Set<BytesWrapper> authBytes = new HashSet<>(authsSet.size());
+ final Set<CharsWrapper> wrappedAuths = new HashSet<>(authsSet.size());
for (String authorization : authsSet) {
- var auth = authorization.getBytes(UTF_8);
- if (auth.length == 0) {
+ if (authorization.isEmpty()) {
throw new IllegalArgumentException("Empty authorization");
}
- authBytes.add(new BytesWrapper(AccessEvaluatorImpl.escape(auth, false)));
+
+ wrappedAuths.add(new CharsWrapper(authorization.toCharArray()));
}
- authorizedPredicate = authBytes::contains;
+ this.authorizedPredicate = auth -> {
+ if (auth instanceof CharsWrapper) {
+ return wrappedAuths.contains(auth);
+ } else {
+ return wrappedAuths.contains(new
CharsWrapper(auth.toString().toCharArray()));
+ }
+ };
+ this.authorizationValidator = authorizationValidator;
}
- public static String unescape(BytesWrapper auth) {
+ public static CharSequence unescape(CharSequence auth) {
Review Comment:
Can not see a way to avoid the two passes. First pass figures out if an
allocation/copy is needed and what size to allocate.
--
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]