Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ are package private and are not part of the public API.
* [ExpressionType](modules/core/src/main/java/org/apache/accumulo/access/ParsedAccessExpression.java).
* [Authorizations](modules/core/src/main/java/org/apache/accumulo/access/Authorizations.java).

`AccessEvaluator`, `AccessExpression`, and `ParsedAccessExpression` will be
sealed interfaces or classes in future releases that support class sealing. So,
users should not create their own implementations of these. Their
implementations are expected to be provided by this library only.

## Getting Started

Add the library to your CLASSPATH. For Maven, use:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,20 @@ public void testCompareAntlrEvaluationAgainstAccessEvaluatorImpl() throws Except
assertNotEquals(0, test.getExpressions().length);
for (String expression : test.getExpressions()) {
switch (test.getExpectedResult()) {
case ACCESSIBLE -> {
case ACCESSIBLE:
assertTrue(evaluator.canAccess(expression), expression);
assertTrue(antlr.canAccess(expression), expression);
}
case INACCESSIBLE -> {
break;
case INACCESSIBLE:
assertFalse(evaluator.canAccess(expression), expression);
assertFalse(antlr.canAccess(expression), expression);
}
case ERROR -> {
break;
case ERROR:
assertThrows(InvalidAccessExpressionException.class,
() -> evaluator.canAccess(expression), expression);
assertThrows(InvalidAccessExpressionException.class,
() -> antlr.canAccess(expression), expression);
}
break;
Comment thread
ctubbsii marked this conversation as resolved.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package org.apache.accumulo.access;

import org.apache.accumulo.access.impl.AccessEvaluatorImpl;
import org.apache.accumulo.access.impl.MultiAccessEvaluatorImpl;

/**
* This class is used to decide if an entity with a given set of authorizations can access
* subsequent access expressions.
Expand Down Expand Up @@ -53,7 +50,7 @@
* @see <a href="https://github.com/apache/accumulo-access">Accumulo Access Documentation</a>
* @since 1.0.0
*/
public sealed interface AccessEvaluator permits AccessEvaluatorImpl, MultiAccessEvaluatorImpl {
public interface AccessEvaluator {
Comment thread
ctubbsii marked this conversation as resolved.

/**
* Evaluates an expression.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@
import java.io.Serializable;
import java.util.Objects;

import org.apache.accumulo.access.impl.AccessExpressionImpl;

/**
* An immutable wrapper for a validated access expression.
*
* @since 1.0.0
*/
public sealed abstract class AccessExpression implements Serializable
permits AccessExpressionImpl, ParsedAccessExpression {
public abstract class AccessExpression implements Serializable {

private static final long serialVersionUID = 1L;

Expand All @@ -53,8 +50,8 @@ protected AccessExpression() {}

@Override
public boolean equals(Object o) {
return this == o
|| (o instanceof AccessExpression a && Objects.equals(getExpression(), a.getExpression()));
return this == o || (o instanceof AccessExpression
&& Objects.equals(getExpression(), ((AccessExpression) o).getExpression()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import java.util.List;

import org.apache.accumulo.access.impl.ParsedAccessExpressionImpl;

/**
* Instances of this class are immutable and wrap a verified access expression and a parse tree for
* the access expression. To create an instance of this class call
Expand All @@ -30,8 +28,7 @@
*
* @since 1.0.0
*/
public sealed abstract class ParsedAccessExpression extends AccessExpression
permits ParsedAccessExpressionImpl {
public abstract class ParsedAccessExpression extends AccessExpression {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class AccessEvaluatorImpl implements AccessEvaluator {
.andThen(auth -> wrappedAuths.add(new CharsWrapper(auth.toCharArray()))));

this.authorizedPredicate =
auth -> auth instanceof CharsWrapper wrapped ? wrappedAuths.contains(wrapped)
auth -> auth instanceof CharsWrapper ? wrappedAuths.contains((CharsWrapper) auth)
: wrappedAuths.contains(new CharsWrapper(auth.toString().toCharArray()));
this.authorizationValidator = authorizationValidator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class AccessImpl implements Access {
private final AuthorizationValidator authValidator;

private void validateAuthArgument(CharSequence auth) {
if (auth.isEmpty()) {
if (auth.length() == 0) {
throw InvalidAuthorizationException.emptyString();
}
if (!authValidator.test(auth, ANY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public int hashCode() {

@Override
public boolean equals(Object o) {
return this == o || (o instanceof CharsWrapper obs && length() == obs.length() && Arrays
.equals(wrapped, offset, offset + len, obs.wrapped, obs.offset, obs.offset + obs.len));
return this == o || (o instanceof CharsWrapper && length() == ((CharsWrapper) o).length()
&& Arrays.equals(wrapped, offset, offset + len, ((CharsWrapper) o).wrapped,
((CharsWrapper) o).offset, ((CharsWrapper) o).offset + ((CharsWrapper) o).len));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,25 @@ private static void runTestCases(Access accumuloAccess, TestDataSet testSet,
}

switch (tests.getExpectedResult()) {
case ACCESSIBLE -> {
case ACCESSIBLE:
assertTrue(evaluator.canAccess(expression), expression);
assertTrue(evaluator.canAccess(accumuloAccess.newExpression(expression)), expression);
assertTrue(evaluator.canAccess(accumuloAccess.newParsedExpression(expression)),
expression);
assertTrue(
evaluator.canAccess(accumuloAccess.newParsedExpression(expression).getExpression()),
expression);
}
case INACCESSIBLE -> {
break;
case INACCESSIBLE:
assertFalse(evaluator.canAccess(expression), expression);
assertFalse(evaluator.canAccess(accumuloAccess.newExpression(expression)), expression);
assertFalse(evaluator.canAccess(accumuloAccess.newParsedExpression(expression)),
expression);
assertFalse(
evaluator.canAccess(accumuloAccess.newParsedExpression(expression).getExpression()),
expression);
}
case ERROR -> {
break;
case ERROR:
assertThrows(InvalidAccessExpressionException.class,
() -> evaluator.canAccess(expression), expression);
assertThrows(InvalidAccessExpressionException.class,
Expand All @@ -120,7 +120,7 @@ private static void runTestCases(Access accumuloAccess, TestDataSet testSet,
() -> accumuloAccess.newExpression(expression), expression);
assertThrows(InvalidAccessExpressionException.class,
() -> accumuloAccess.newParsedExpression(expression), expression);
}
break;
Comment thread
ctubbsii marked this conversation as resolved.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,17 @@ public static class NormalizedExpression implements Comparable<NormalizedExpress

// determines the sort order of different kinds of subexpressions.
private static int typeOrder(ExpressionType type) {
return switch (type) {
case AUTHORIZATION -> 1;
case OR -> 2;
case AND -> 3;
case EMPTY -> throw new IllegalArgumentException("Unexpected type " + type);
};
switch (type) {
case AUTHORIZATION:
return 1;
case OR:
return 2;
case AND:
return 3;
case EMPTY:
default:
throw new IllegalArgumentException("Unexpected type " + type);
}
}

@Override
Expand All @@ -111,7 +116,8 @@ public int compareTo(NormalizedExpression o) {

@Override
public boolean equals(Object o) {
return this == o || (o instanceof NormalizedExpression n && compareTo(n) == 0);
return this == o
|| (o instanceof NormalizedExpression && compareTo((NormalizedExpression) o) == 0);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ specific language governing permissions and limitations
under the License.
]]></accumulo.build.license.header>
<failsafe.failIfNoSpecifiedTests>false</failsafe.failIfNoSpecifiedTests>
<javaVersion>17</javaVersion>
<javaVersion>11</javaVersion>
<!-- prevent introduction of new compiler warnings -->
<maven.compiler.failOnWarning>true</maven.compiler.failOnWarning>
<maven.javadoc.failOnWarnings>true</maven.javadoc.failOnWarnings>
Expand Down