use of com.yahoo.elide.core.security.permissions.expressions.Expression in project elide by yahoo.
the class AbstractPermissionExecutor method executeCommitChecks.
/**
* Execute commmit checks.
*/
@Override
public void executeCommitChecks() {
commitCheckQueue.forEach((expr) -> {
Expression expression = expr.getExpression();
ExpressionResult result = expression.evaluate(Expression.EvaluationMode.ALL_CHECKS);
if (result == FAIL) {
ForbiddenAccessException e = new ForbiddenAccessException(expr.getAnnotationClass(), expression, Expression.EvaluationMode.ALL_CHECKS);
if (log.isTraceEnabled()) {
log.trace("{}", e.getLoggedMessage());
}
throw e;
}
});
commitCheckQueue.clear();
}
use of com.yahoo.elide.core.security.permissions.expressions.Expression in project elide by yahoo.
the class PermissionExpressionBuilderTest method testAnyFieldExpressionText.
@Test
public void testAnyFieldExpressionText() {
@Entity
@Include(rootLevel = false)
@ReadPermission(expression = "user has all access AND user has no access")
class Model {
}
dictionary.bindEntity(Model.class);
PersistentResource resource = newResource(new Model(), Model.class);
Expression expression = builder.buildAnyFieldExpressions(resource, ReadPermission.class, null, null);
assertEquals("READ PERMISSION WAS INVOKED ON PersistentResource{type=model, id=null} " + "FOR EXPRESSION [((user has all access \u001B[34mWAS UNEVALUATED\u001B[m)) " + "AND ((user has no access \u001B[34mWAS UNEVALUATED\u001B[m))]", expression.toString());
expression.evaluate(Expression.EvaluationMode.ALL_CHECKS);
assertEquals("READ PERMISSION WAS INVOKED ON PersistentResource{type=model, id=null} " + "FOR EXPRESSION [((user has all access [32mPASSED[m)) " + "AND ((user has no access [31mFAILED[m))]", expression.toString());
}
use of com.yahoo.elide.core.security.permissions.expressions.Expression in project elide by yahoo.
the class PermissionExpressionNormalizationVisitorTest method normalforms.
@Test
public void normalforms() {
ParseTree tree;
Expression normalizedExpression;
tree = EntityPermissions.parseExpression("not ((parentInitCheck and passingOp) or shouldCache)");
normalizedExpression = tree.accept(permissionExpressionVisitor).accept(normalizationVisitor);
Assertions.assertEquals("((NOT ((parentInitCheck \u001B[34mWAS UNEVALUATED\u001B[m))) OR " + "(NOT ((passingOp \u001B[34mWAS UNEVALUATED\u001B[m)))) AND " + "(NOT ((shouldCache \u001B[34mWAS UNEVALUATED\u001B[m)))", normalizedExpression.toString());
tree = EntityPermissions.parseExpression("not (parentInitCheck and (passingOp or shouldCache))");
normalizedExpression = tree.accept(permissionExpressionVisitor).accept(normalizationVisitor);
Assertions.assertEquals("(NOT ((parentInitCheck \u001B[34mWAS UNEVALUATED\u001B[m))) OR " + "((NOT ((passingOp \u001B[34mWAS UNEVALUATED\u001B[m))) AND " + "(NOT ((shouldCache \u001B[34mWAS UNEVALUATED\u001B[m))))", normalizedExpression.toString());
tree = EntityPermissions.parseExpression("not parentInitCheck and not passingOp");
normalizedExpression = tree.accept(permissionExpressionVisitor).accept(normalizationVisitor);
Assertions.assertEquals("(NOT ((parentInitCheck \u001B[34mWAS UNEVALUATED\u001B[m))) AND " + "(NOT ((passingOp \u001B[34mWAS UNEVALUATED\u001B[m)))", normalizedExpression.toString());
}
use of com.yahoo.elide.core.security.permissions.expressions.Expression in project elide by yahoo.
the class PermissionExpressionNormalizationVisitorTest method andExpressionTest.
@Test
public void andExpressionTest() {
ParseTree tree;
Expression normalizedExpression;
tree = EntityPermissions.parseExpression("not (sampleCommit and sampleOperation)");
normalizedExpression = tree.accept(permissionExpressionVisitor).accept(normalizationVisitor);
Assertions.assertEquals("(NOT ((sampleCommit \u001B[34mWAS UNEVALUATED\u001B[m))) OR " + "(NOT ((sampleOperation \u001B[34mWAS UNEVALUATED\u001B[m)))", normalizedExpression.toString());
tree = EntityPermissions.parseExpression("not (Prefab.Role.All and sampleCommit and initCheck)");
normalizedExpression = tree.accept(permissionExpressionVisitor).accept(normalizationVisitor);
Assertions.assertEquals("((NOT ((Prefab.Role.All \u001B[34mWAS UNEVALUATED\u001B[m))) OR " + "(NOT ((sampleCommit \u001B[34mWAS UNEVALUATED\u001B[m)))) OR " + "(NOT ((initCheck \u001B[34mWAS UNEVALUATED\u001B[m)))", normalizedExpression.toString());
tree = EntityPermissions.parseExpression("not (parentInitCheck and passingOp) and (FailOp and shouldCache)");
normalizedExpression = tree.accept(permissionExpressionVisitor).accept(normalizationVisitor);
Assertions.assertEquals("((NOT ((parentInitCheck \u001B[34mWAS UNEVALUATED\u001B[m))) OR (NOT ((passingOp \u001B[34mWAS UNEVALUATED\u001B[m)))) AND " + "(((FailOp \u001B[34mWAS UNEVALUATED\u001B[m)) AND ((shouldCache \u001B[34mWAS UNEVALUATED\u001B[m)))", normalizedExpression.toString());
tree = EntityPermissions.parseExpression("not (parentInitCheck and passingOp) and not (FailOp and shouldCache)");
normalizedExpression = tree.accept(permissionExpressionVisitor).accept(normalizationVisitor);
Assertions.assertEquals("((NOT ((parentInitCheck \u001B[34mWAS UNEVALUATED\u001B[m))) OR (NOT ((passingOp \u001B[34mWAS UNEVALUATED\u001B[m)))) AND " + "((NOT ((FailOp \u001B[34mWAS UNEVALUATED\u001B[m))) OR (NOT ((shouldCache \u001B[34mWAS UNEVALUATED\u001B[m))))", normalizedExpression.toString());
tree = EntityPermissions.parseExpression("not (not (parentInitCheck and passingOp) and not (FailOp and shouldCache))");
normalizedExpression = tree.accept(permissionExpressionVisitor).accept(normalizationVisitor);
Assertions.assertEquals("(((parentInitCheck \u001B[34mWAS UNEVALUATED\u001B[m)) AND ((passingOp \u001B[34mWAS UNEVALUATED\u001B[m))) OR " + "(((FailOp \u001B[34mWAS UNEVALUATED\u001B[m)) AND ((shouldCache \u001B[34mWAS UNEVALUATED\u001B[m)))", normalizedExpression.toString());
}
Aggregations