Search in sources :

Example 31 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class AggregationStorePermissionExecutorTest method filterTest.

@Test
public void filterTest() {
    @Entity
    @Include
    @Value
    @ReadPermission(expression = "user none or filter check")
    class Model1 {

        String filterDim;

        long metric;
    }
    com.yahoo.elide.core.RequestScope scope = bindAndgetRequestScope(Model1.class);
    PermissionExecutor executor = scope.getPermissionExecutor();
    FilterExpression expression = executor.getReadPermissionFilter(ClassType.of(Model1.class), new HashSet<>(Arrays.asList("filterDim", "metric"))).orElse(null);
    Assertions.assertNotNull(expression);
    Assertions.assertEquals("model1.filterDim NOTNULL []", expression.toString());
    @Entity
    @Include
    @Value
    @ReadPermission(expression = "user none and filter check")
    class Model2 {

        String filterDim;

        long metric;
    }
    scope = bindAndgetRequestScope(Model2.class);
    executor = scope.getPermissionExecutor();
    expression = executor.getReadPermissionFilter(ClassType.of(Model2.class), new HashSet<>(Arrays.asList("filterDim", "metric"))).orElse(null);
    Assertions.assertNull(expression);
    @Entity
    @Include
    @Value
    @ReadPermission(expression = "user all or filter check")
    class Model3 {

        String filterDim;

        long metric;
    }
    scope = bindAndgetRequestScope(Model3.class);
    executor = scope.getPermissionExecutor();
    expression = executor.getReadPermissionFilter(ClassType.of(Model3.class), new HashSet<>(Arrays.asList("filterDim", "metric"))).orElse(null);
    Assertions.assertNull(expression);
}
Also used : Entity(javax.persistence.Entity) AggregationStorePermissionExecutor(com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor) Include(com.yahoo.elide.annotation.Include) Value(lombok.Value) ReadPermission(com.yahoo.elide.annotation.ReadPermission) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 32 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class PermissionExecutorTest method testReadCheckExpressionForNewlyCreatedObject.

@Test
public void testReadCheckExpressionForNewlyCreatedObject() {
    @Entity
    @Include(rootLevel = false)
    @ReadPermission(expression = "FailOp")
    class Model {
    }
    PersistentResource resource = newResource(new Model(), Model.class, true);
    RequestScope requestScope = resource.getRequestScope();
    requestScope.getDictionary().bindEntity(Model.class);
    assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource));
    assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
Also used : Entity(javax.persistence.Entity) PersistentResource(com.yahoo.elide.core.PersistentResource) Include(com.yahoo.elide.annotation.Include) ReadPermission(com.yahoo.elide.annotation.ReadPermission) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 33 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class PermissionExecutorTest method testSuccessfulCommitChecks.

@Test
public void testSuccessfulCommitChecks() throws Exception {
    @Entity
    @Include(rootLevel = false)
    @UpdatePermission(expression = "sampleOperation")
    class Model implements SampleOperationModel {
    }
    PersistentResource resource = newResource(new Model(), Model.class, true);
    RequestScope requestScope = resource.getRequestScope();
    // Because the object is newly created, the check is DEFERRED.
    assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource, ALL_FIELDS));
    requestScope.getPermissionExecutor().executeCommitChecks();
}
Also used : Entity(javax.persistence.Entity) PersistentResource(com.yahoo.elide.core.PersistentResource) Include(com.yahoo.elide.annotation.Include) RequestScope(com.yahoo.elide.core.RequestScope) UpdatePermission(com.yahoo.elide.annotation.UpdatePermission) Test(org.junit.jupiter.api.Test)

Example 34 with Include

use of com.yahoo.elide.annotation.Include 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 PASSED)) " + "AND ((user has no access FAILED))]", expression.toString());
}
Also used : Entity(javax.persistence.Entity) PersistentResource(com.yahoo.elide.core.PersistentResource) Expression(com.yahoo.elide.core.security.permissions.expressions.Expression) Include(com.yahoo.elide.annotation.Include) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Test(org.junit.jupiter.api.Test)

Example 35 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class PermissionExecutorTest method testFailAllFieldAwareSuccessOperationFailCommit.

@Test
public void testFailAllFieldAwareSuccessOperationFailCommit() {
    @Entity
    @Include(rootLevel = false)
    @UpdatePermission(expression = "Prefab.Role.None")
    class Model {

        @Id
        public Long id;

        @UpdatePermission(expression = "Prefab.Role.All AND FailOp")
        public String field = "some data";
    }
    PersistentResource resource = newResource(new Model(), Model.class, true);
    RequestScope requestScope = resource.getRequestScope();
    assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource));
    assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
Also used : Entity(javax.persistence.Entity) PersistentResource(com.yahoo.elide.core.PersistentResource) Include(com.yahoo.elide.annotation.Include) RequestScope(com.yahoo.elide.core.RequestScope) UpdatePermission(com.yahoo.elide.annotation.UpdatePermission) Test(org.junit.jupiter.api.Test)

Aggregations

Include (com.yahoo.elide.annotation.Include)46 Test (org.junit.jupiter.api.Test)41 Entity (javax.persistence.Entity)37 RequestScope (com.yahoo.elide.core.RequestScope)26 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)19 HashSet (java.util.HashSet)17 PersistentResource (com.yahoo.elide.core.PersistentResource)16 UpdatePermission (com.yahoo.elide.annotation.UpdatePermission)12 ReadPermission (com.yahoo.elide.annotation.ReadPermission)11 Annotation (java.lang.annotation.Annotation)4 Date (java.util.Date)4 ApiVersion (com.yahoo.elide.annotation.ApiVersion)3 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)3 FromTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 Exclude (com.yahoo.elide.annotation.Exclude)2 AggregationStorePermissionExecutor (com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor)2 Expression (com.yahoo.elide.core.security.permissions.expressions.Expression)2 TableMeta (com.yahoo.elide.datastores.aggregation.annotation.TableMeta)2