Search in sources :

Example 1 with PermissionToFilterExpressionVisitor

use of com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor 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);
}
Also used : CheckExpression(com.yahoo.elide.core.security.permissions.expressions.CheckExpression) BeforeEach(org.junit.jupiter.api.BeforeEach) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Arrays(java.util.Arrays) Path(com.yahoo.elide.core.Path) Role(com.yahoo.elide.core.security.checks.prefab.Role) User(com.yahoo.elide.core.security.User) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) Map(java.util.Map) PermissionExpressionVisitor(com.yahoo.elide.core.security.visitors.PermissionExpressionVisitor) NO_EVALUATION_EXPRESSION(com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor.NO_EVALUATION_EXPRESSION) RequestScope(com.yahoo.elide.core.RequestScope) OperationCheck(com.yahoo.elide.core.security.checks.OperationCheck) MethodSource(org.junit.jupiter.params.provider.MethodSource) PermissionToFilterExpressionVisitor(com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor) UUID(java.util.UUID) Arguments(org.junit.jupiter.params.provider.Arguments) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Expression(com.yahoo.elide.core.security.permissions.expressions.Expression) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) ExpressionResultCache(com.yahoo.elide.core.security.permissions.ExpressionResultCache) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AndFilterExpression(com.yahoo.elide.core.filter.expression.AndFilterExpression) Optional(java.util.Optional) TRUE_USER_CHECK_EXPRESSION(com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor.TRUE_USER_CHECK_EXPRESSION) PermissionExpressionNormalizationVisitor(com.yahoo.elide.core.security.visitors.PermissionExpressionNormalizationVisitor) TestDictionary(com.yahoo.elide.core.dictionary.TestDictionary) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) Author(example.Author) Function(java.util.function.Function) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) ElideSettings(com.yahoo.elide.ElideSettings) TestUser(com.yahoo.elide.core.security.TestUser) ChangeSpec(com.yahoo.elide.core.security.ChangeSpec) Check(com.yahoo.elide.core.security.checks.Check) Book(example.Book) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EntityPermissions(com.yahoo.elide.core.dictionary.EntityPermissions) Type(com.yahoo.elide.core.type.Type) Operator(com.yahoo.elide.core.filter.Operator) Collections(java.util.Collections) FALSE_USER_CHECK_EXPRESSION(com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor.FALSE_USER_CHECK_EXPRESSION) CheckExpression(com.yahoo.elide.core.security.permissions.expressions.CheckExpression) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) Expression(com.yahoo.elide.core.security.permissions.expressions.Expression) AndFilterExpression(com.yahoo.elide.core.filter.expression.AndFilterExpression) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) OperationCheck(com.yahoo.elide.core.security.checks.OperationCheck) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) Check(com.yahoo.elide.core.security.checks.Check) PermissionToFilterExpressionVisitor(com.yahoo.elide.core.security.visitors.PermissionToFilterExpressionVisitor) PermissionExpressionVisitor(com.yahoo.elide.core.security.visitors.PermissionExpressionVisitor) ParseTree(org.antlr.v4.runtime.tree.ParseTree) CheckExpression(com.yahoo.elide.core.security.permissions.expressions.CheckExpression)

Aggregations

ElideSettings (com.yahoo.elide.ElideSettings)1 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)1 Path (com.yahoo.elide.core.Path)1 RequestScope (com.yahoo.elide.core.RequestScope)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)1 EntityPermissions (com.yahoo.elide.core.dictionary.EntityPermissions)1 TestDictionary (com.yahoo.elide.core.dictionary.TestDictionary)1 Operator (com.yahoo.elide.core.filter.Operator)1 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)1 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)1 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)1 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)1 ChangeSpec (com.yahoo.elide.core.security.ChangeSpec)1 TestUser (com.yahoo.elide.core.security.TestUser)1 User (com.yahoo.elide.core.security.User)1 Check (com.yahoo.elide.core.security.checks.Check)1 FilterExpressionCheck (com.yahoo.elide.core.security.checks.FilterExpressionCheck)1 OperationCheck (com.yahoo.elide.core.security.checks.OperationCheck)1 Role (com.yahoo.elide.core.security.checks.prefab.Role)1