Search in sources :

Example 1 with AndExpression

use of com.yahoo.elide.core.security.permissions.expressions.AndExpression 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;
}
Also used : AndExpression(com.yahoo.elide.core.security.permissions.expressions.AndExpression) CheckExpression(com.yahoo.elide.core.security.permissions.expressions.CheckExpression) Expression(com.yahoo.elide.core.security.permissions.expressions.Expression) OrExpression(com.yahoo.elide.core.security.permissions.expressions.OrExpression) AndExpression(com.yahoo.elide.core.security.permissions.expressions.AndExpression) NotExpression(com.yahoo.elide.core.security.permissions.expressions.NotExpression) NotExpression(com.yahoo.elide.core.security.permissions.expressions.NotExpression) OrExpression(com.yahoo.elide.core.security.permissions.expressions.OrExpression)

Example 2 with AndExpression

use of com.yahoo.elide.core.security.permissions.expressions.AndExpression in project elide by yahoo.

the class PermissionExpressionNormalizationVisitor method visitAndExpression.

@Override
public Expression visitAndExpression(AndExpression andExpression) {
    Expression left = andExpression.getLeft();
    Expression right = andExpression.getRight();
    return new AndExpression(left.accept(this), right.accept(this));
}
Also used : AndExpression(com.yahoo.elide.core.security.permissions.expressions.AndExpression) CheckExpression(com.yahoo.elide.core.security.permissions.expressions.CheckExpression) Expression(com.yahoo.elide.core.security.permissions.expressions.Expression) OrExpression(com.yahoo.elide.core.security.permissions.expressions.OrExpression) AndExpression(com.yahoo.elide.core.security.permissions.expressions.AndExpression) NotExpression(com.yahoo.elide.core.security.permissions.expressions.NotExpression)

Example 3 with AndExpression

use of com.yahoo.elide.core.security.permissions.expressions.AndExpression in project elide by yahoo.

the class PermissionExpressionVisitor method visitAND.

@Override
public Expression visitAND(ExpressionParser.ANDContext ctx) {
    Expression left = visit(ctx.left);
    Expression right = visit(ctx.right);
    return new AndExpression(left, right);
}
Also used : AndExpression(com.yahoo.elide.core.security.permissions.expressions.AndExpression) Expression(com.yahoo.elide.core.security.permissions.expressions.Expression) OrExpression(com.yahoo.elide.core.security.permissions.expressions.OrExpression) AndExpression(com.yahoo.elide.core.security.permissions.expressions.AndExpression) NotExpression(com.yahoo.elide.core.security.permissions.expressions.NotExpression)

Example 4 with AndExpression

use of com.yahoo.elide.core.security.permissions.expressions.AndExpression in project elide by yahoo.

the class PermissionExpressionBuilder method buildUserCheckEntityAndAnyFieldExpression.

/**
 * Build an expression that strictly evaluates UserCheck's and ignores other checks for an entity.
 * expression = (entityRule AND (field1Rule OR field2Rule ... OR fieldNRule))
 * <p>
 * NOTE: This method returns _NO_ commit checks.
 *
 * @param resourceClass   Resource class
 * @param annotationClass Annotation class
 * @param scope    Request scope
 * @param <A>             type parameter
 * @return User check expression to evaluate
 */
public <A extends Annotation> Expression buildUserCheckEntityAndAnyFieldExpression(final Type<?> resourceClass, final Class<A> annotationClass, Set<String> requestedFields, final RequestScope scope) {
    final Function<Check, Expression> leafBuilderFn = (check) -> new CheckExpression(check, null, scope, null, cache);
    ParseTree classPermissions = entityDictionary.getPermissionsForClass(resourceClass, annotationClass);
    Expression entityExpression = normalizedExpressionFromParseTree(classPermissions, leafBuilderFn);
    Expression anyFieldExpression = buildAnyFieldOnlyExpression(new PermissionCondition(annotationClass, resourceClass), leafBuilderFn, requestedFields);
    if (entityExpression == null) {
        return anyFieldExpression;
    }
    return new AndExpression(entityExpression, anyFieldExpression);
}
Also used : CheckExpression(com.yahoo.elide.core.security.permissions.expressions.CheckExpression) PermissionExpressionNormalizationVisitor(com.yahoo.elide.core.security.visitors.PermissionExpressionNormalizationVisitor) OrExpression(com.yahoo.elide.core.security.permissions.expressions.OrExpression) Function(java.util.function.Function) FAILURE(com.yahoo.elide.core.security.permissions.expressions.Expression.Results.FAILURE) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) SpecificFieldExpression(com.yahoo.elide.core.security.permissions.expressions.SpecificFieldExpression) PersistentResource(com.yahoo.elide.core.PersistentResource) PermissionExpressionVisitor(com.yahoo.elide.core.security.visitors.PermissionExpressionVisitor) ParseTree(org.antlr.v4.runtime.tree.ParseTree) NO_EVALUATION_EXPRESSION(com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor.NO_EVALUATION_EXPRESSION) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) RequestScope(com.yahoo.elide.core.RequestScope) ChangeSpec(com.yahoo.elide.core.security.ChangeSpec) Check(com.yahoo.elide.core.security.checks.Check) PermissionToFilterExpressionVisitor(com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor) AndExpression(com.yahoo.elide.core.security.permissions.expressions.AndExpression) AnyFieldExpression(com.yahoo.elide.core.security.permissions.expressions.AnyFieldExpression) Set(java.util.Set) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Expression(com.yahoo.elide.core.security.permissions.expressions.Expression) List(java.util.List) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Type(com.yahoo.elide.core.type.Type) Annotation(java.lang.annotation.Annotation) FALSE_USER_CHECK_EXPRESSION(com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor.FALSE_USER_CHECK_EXPRESSION) TRUE_USER_CHECK_EXPRESSION(com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor.TRUE_USER_CHECK_EXPRESSION) AndExpression(com.yahoo.elide.core.security.permissions.expressions.AndExpression) CheckExpression(com.yahoo.elide.core.security.permissions.expressions.CheckExpression) OrExpression(com.yahoo.elide.core.security.permissions.expressions.OrExpression) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) SpecificFieldExpression(com.yahoo.elide.core.security.permissions.expressions.SpecificFieldExpression) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) AndExpression(com.yahoo.elide.core.security.permissions.expressions.AndExpression) AnyFieldExpression(com.yahoo.elide.core.security.permissions.expressions.AnyFieldExpression) Expression(com.yahoo.elide.core.security.permissions.expressions.Expression) Check(com.yahoo.elide.core.security.checks.Check) ParseTree(org.antlr.v4.runtime.tree.ParseTree) CheckExpression(com.yahoo.elide.core.security.permissions.expressions.CheckExpression)

Aggregations

AndExpression (com.yahoo.elide.core.security.permissions.expressions.AndExpression)4 Expression (com.yahoo.elide.core.security.permissions.expressions.Expression)4 OrExpression (com.yahoo.elide.core.security.permissions.expressions.OrExpression)4 CheckExpression (com.yahoo.elide.core.security.permissions.expressions.CheckExpression)3 NotExpression (com.yahoo.elide.core.security.permissions.expressions.NotExpression)3 ReadPermission (com.yahoo.elide.annotation.ReadPermission)1 PersistentResource (com.yahoo.elide.core.PersistentResource)1 RequestScope (com.yahoo.elide.core.RequestScope)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)1 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)1 ChangeSpec (com.yahoo.elide.core.security.ChangeSpec)1 Check (com.yahoo.elide.core.security.checks.Check)1 AnyFieldExpression (com.yahoo.elide.core.security.permissions.expressions.AnyFieldExpression)1 FAILURE (com.yahoo.elide.core.security.permissions.expressions.Expression.Results.FAILURE)1 SpecificFieldExpression (com.yahoo.elide.core.security.permissions.expressions.SpecificFieldExpression)1 PermissionExpressionNormalizationVisitor (com.yahoo.elide.core.security.visitors.PermissionExpressionNormalizationVisitor)1 PermissionExpressionVisitor (com.yahoo.elide.core.security.visitors.PermissionExpressionVisitor)1 PermissionToFilterExpressionVisitor (com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor)1 FALSE_USER_CHECK_EXPRESSION (com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor.FALSE_USER_CHECK_EXPRESSION)1