use of com.yahoo.elide.core.security.permissions.expressions.Expression in project elide by yahoo.
the class PermissionToFilterExpressionVisitorTest method filterExpressionForPermissions.
private FilterExpression filterExpressionForPermissions(String permission) {
Function<Check, Expression> checkFn = (check) -> new CheckExpression(check, null, requestScope, null, cache);
ParseTree expression = EntityPermissions.parseExpression(permission);
PermissionToFilterExpressionVisitor fev = new PermissionToFilterExpressionVisitor(dictionary, requestScope, null);
return expression.accept(new PermissionExpressionVisitor(dictionary, checkFn)).accept(NORMALIZATION_VISITOR).accept(fev);
}
use of com.yahoo.elide.core.security.permissions.expressions.Expression in project elide by yahoo.
the class PermissionExpressionBuilderTest method testSpecificFieldExpressionText.
@Test
public void testSpecificFieldExpressionText() {
@Entity
@Include(rootLevel = false)
@UpdatePermission(expression = "user has no access")
class Model {
@Id
private long id;
@UpdatePermission(expression = "user has all access OR user has no access")
private int foo;
}
dictionary.bindEntity(Model.class);
PersistentResource resource = newResource(new Model(), Model.class);
ChangeSpec changes = new ChangeSpec(resource, "foo", 1, 2);
Expression expression = builder.buildSpecificFieldExpressions(resource, UpdatePermission.class, "foo", changes);
assertEquals("UPDATE PERMISSION WAS INVOKED ON PersistentResource{type=model, id=0} WITH CHANGES ChangeSpec { " + "resource=PersistentResource{type=model, id=0}, field=foo, original=1, modified=2} " + "FOR EXPRESSION [FIELD(((user has all access " + "\u001B[34mWAS UNEVALUATED\u001B[m)) OR ((user has no access " + "\u001B[34mWAS UNEVALUATED\u001B[m)))]", expression.toString());
expression.evaluate(Expression.EvaluationMode.ALL_CHECKS);
assertEquals("UPDATE PERMISSION WAS INVOKED ON PersistentResource{type=model, id=0} WITH CHANGES ChangeSpec { " + "resource=PersistentResource{type=model, id=0}, field=foo, original=1, modified=2} " + "FOR EXPRESSION [FIELD(((user has all access " + "\u001B[32mPASSED\u001B[m)) OR ((user has no access " + "\u001B[34mWAS UNEVALUATED\u001B[m)))]", expression.toString());
}
use of com.yahoo.elide.core.security.permissions.expressions.Expression in project elide by yahoo.
the class PermissionExpressionNormalizationVisitor method visitNotExpression.
@Override
public Expression visitNotExpression(NotExpression notExpression) {
Expression inner = notExpression.getLogical();
if (inner instanceof AndExpression) {
AndExpression and = (AndExpression) inner;
Expression left = new NotExpression(and.getLeft()).accept(this);
Expression right = new NotExpression(and.getRight()).accept(this);
return new OrExpression(left, right);
}
if (inner instanceof OrExpression) {
OrExpression or = (OrExpression) inner;
Expression left = new NotExpression(or.getLeft()).accept(this);
Expression right = new NotExpression(or.getRight()).accept(this);
return new AndExpression(left, right);
}
if (inner instanceof NotExpression) {
NotExpression not = (NotExpression) inner;
return (not.getLogical()).accept(this);
}
return notExpression;
}
use of com.yahoo.elide.core.security.permissions.expressions.Expression in project elide by yahoo.
the class PermissionExpressionVisitorTest method testComplexExpression.
@Test
public void testComplexExpression() {
Expression expression = getExpressionForPermission(UpdatePermission.class);
assertEquals(ExpressionResult.PASS, expression.evaluate(Expression.EvaluationMode.ALL_CHECKS));
}
use of com.yahoo.elide.core.security.permissions.expressions.Expression in project elide by yahoo.
the class PermissionExpressionNormalizationVisitor method visitOrExpression.
@Override
public Expression visitOrExpression(OrExpression orExpression) {
Expression left = orExpression.getLeft();
Expression right = orExpression.getRight();
return new OrExpression(left.accept(this), right.accept(this));
}
Aggregations