Search in sources :

Example 11 with Include

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

the class PermissionExecutorTest method testSuccessfulOperationCheck.

@Test
public void testSuccessfulOperationCheck() throws Exception {
    @Entity
    @Include(rootLevel = false)
    @UpdatePermission(expression = "sampleOperation")
    class Model implements SampleOperationModel {
    }
    PersistentResource resource = newResource(new Model(), Model.class, false);
    RequestScope requestScope = resource.getRequestScope();
    assertEquals(ExpressionResult.PASS, 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 12 with Include

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

the class PermissionExecutorTest method testFailAllSpecificFieldAwareSuccessOperationFailCommit.

@Test
public void testFailAllSpecificFieldAwareSuccessOperationFailCommit() {
    @Entity
    @Include(rootLevel = false)
    @UpdatePermission(expression = "Prefab.Role.All")
    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().checkSpecificFieldPermissions(resource, null, UpdatePermission.class, "field"));
    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)

Example 13 with Include

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

the class PermissionExecutorTest method testFailOperationCheckAll.

@Test
public void testFailOperationCheckAll() throws Exception {
    @Entity
    @Include(rootLevel = false)
    @UpdatePermission(expression = "sampleOperation AND Prefab.Role.None")
    class Model implements SampleOperationModel {
    }
    PersistentResource resource = newResource(new Model(), Model.class, false);
    RequestScope requestScope = resource.getRequestScope();
    assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource));
}
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 14 with Include

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

the class EntityDictionaryTest method testGetFirstAnnotationConflict.

@Test
public void testGetFirstAnnotationConflict() {
    @Exclude
    @Include(rootLevel = false)
    class Foo {
    }
    Annotation first = getFirstAnnotation(ClassType.of(Foo.class), Arrays.asList(Exclude.class, Include.class));
    assertTrue(first instanceof Exclude);
}
Also used : Exclude(com.yahoo.elide.annotation.Exclude) Include(com.yahoo.elide.annotation.Include) Annotation(java.lang.annotation.Annotation) Test(org.junit.jupiter.api.Test)

Example 15 with Include

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

the class SwaggerBuilderTest method testIncludeParam.

@Test
public void testIncludeParam() throws Exception {
    List<Parameter> params = swagger.getPaths().get("/book").getGet().getParameters();
    Set<String> paramNames = params.stream().map((param) -> param.getName()).collect(Collectors.toSet());
    long includeParams = paramNames.stream().filter((name) -> name.startsWith("include")).count();
    assertEquals(1, includeParams);
    assertTrue(paramNames.contains("include"));
    QueryParameter includeParam = (QueryParameter) params.stream().filter((param) -> param.getName().equals("include")).findFirst().get();
    assertEquals("query", includeParam.getIn());
    List<String> includeValues = Arrays.asList("authors", "publisher");
    assertTrue(((StringProperty) includeParam.getItems()).getEnum().containsAll(includeValues));
    assertEquals("csv", includeParam.getCollectionFormat());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Resource(com.yahoo.elide.swagger.model.Resource) Arrays(java.util.Arrays) Data(com.yahoo.elide.swagger.property.Data) Swagger(io.swagger.models.Swagger) Tag(io.swagger.models.Tag) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Include(com.yahoo.elide.annotation.Include) StringProperty(io.swagger.models.properties.StringProperty) HashMap(java.util.HashMap) Publisher(example.models.Publisher) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) TestInstance(org.junit.jupiter.api.TestInstance) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Author(example.models.Author) BeforeAll(org.junit.jupiter.api.BeforeAll) Path(io.swagger.models.Path) Map(java.util.Map) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) Book(example.models.Book) RefProperty(io.swagger.models.properties.RefProperty) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Operation(io.swagger.models.Operation) Datum(com.yahoo.elide.swagger.property.Datum) Property(io.swagger.models.properties.Property) Id(javax.persistence.Id) Entity(javax.persistence.Entity) BodyParameter(io.swagger.models.parameters.BodyParameter) Set(java.util.Set) Parameter(io.swagger.models.parameters.Parameter) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Info(io.swagger.models.Info) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.junit.jupiter.api.Test) Response(io.swagger.models.Response) ObjectProperty(io.swagger.models.properties.ObjectProperty) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Relationship(com.yahoo.elide.swagger.property.Relationship) Optional(java.util.Optional) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) StringProperty(io.swagger.models.properties.StringProperty) 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