Search in sources :

Example 1 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class VerifyFieldAccessFilterExpressionVisitor method getValueChecked.

private Observable<PersistentResource> getValueChecked(PersistentResource<?> resource, String fieldName, RequestScope requestScope) {
    EntityDictionary dictionary = resource.getDictionary();
    // checkFieldAwareReadPermissions
    requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, null, ReadPermission.class, fieldName);
    Object entity = resource.getObject();
    if (entity == null || resource.getDictionary().getRelationshipType(resource.getResourceType(), fieldName) == RelationshipType.NONE) {
        return Observable.empty();
    }
    Relationship relationship = Relationship.builder().name(fieldName).alias(fieldName).projection(EntityProjection.builder().type(dictionary.getParameterizedType(resource.getResourceType(), fieldName)).build()).build();
    // use no filter to allow the read directly from loaded resource
    return resource.getRelationChecked(relationship);
}
Also used : Relationship(com.yahoo.elide.core.request.Relationship) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 2 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class CanPaginateVisitorTest method testNotOperationExpression.

@Test
public void testNotOperationExpression() throws Exception {
    @Entity
    @Include(rootLevel = false)
    class Book {

        @Id
        private long id;

        @ReadPermission(expression = "NOT In Memory Check")
        private String title;
    }
    EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
    dictionary.bindEntity(Book.class);
    RequestScope scope = mock(RequestScope.class);
    assertFalse(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, new HashSet<>()));
}
Also used : Entity(javax.persistence.Entity) Include(com.yahoo.elide.annotation.Include) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class CanPaginateVisitorTest method testSparseFields.

@Test
public void testSparseFields() throws Exception {
    @Entity
    @Include(rootLevel = false)
    @ReadPermission(expression = "In Memory Check")
    class Book {

        @Id
        private long id;

        @ReadPermission(expression = "Filter Expression Check")
        private String title;

        @ReadPermission(expression = "Filter Expression Check")
        private Date publicationDate;

        private boolean outOfPrint;
    }
    EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
    dictionary.bindEntity(Book.class);
    RequestScope scope = mock(RequestScope.class);
    Set<String> sparseFields = new HashSet<>();
    assertFalse(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, sparseFields));
    sparseFields.add("title");
    sparseFields.add("publicationDate");
    assertTrue(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, sparseFields));
    sparseFields.add("outOfPrint");
    assertFalse(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, sparseFields));
}
Also used : Entity(javax.persistence.Entity) Include(com.yahoo.elide.annotation.Include) ReadPermission(com.yahoo.elide.annotation.ReadPermission) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class CanPaginateVisitorTest method testFieldFilterPermissions.

@Test
public void testFieldFilterPermissions() throws Exception {
    @Entity
    @Include(rootLevel = false)
    class Book {

        @Id
        private long id;

        @ReadPermission(expression = "Filter Expression Check")
        private String title;
    }
    EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
    dictionary.bindEntity(Book.class);
    RequestScope scope = mock(RequestScope.class);
    assertTrue(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, new HashSet<>()));
}
Also used : Entity(javax.persistence.Entity) Include(com.yahoo.elide.annotation.Include) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class CanPaginateVisitorTest method testFalseUserOROperationExpression.

@Test
public void testFalseUserOROperationExpression() throws Exception {
    @Entity
    @Include(rootLevel = false)
    class Book {

        @Id
        private long id;

        @ReadPermission(expression = "False User Check OR In Memory Check")
        private String title;
    }
    EntityDictionary dictionary = TestDictionary.getTestDictionary(checkMappings);
    dictionary.bindEntity(Book.class);
    RequestScope scope = mock(RequestScope.class);
    assertFalse(CanPaginateVisitor.canPaginate(ClassType.of(Book.class), dictionary, scope, new HashSet<>()));
}
Also used : Entity(javax.persistence.Entity) Include(com.yahoo.elide.annotation.Include) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RequestScope(com.yahoo.elide.core.RequestScope) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)87 Test (org.junit.jupiter.api.Test)31 RequestScope (com.yahoo.elide.core.RequestScope)27 Include (com.yahoo.elide.annotation.Include)17 Entity (javax.persistence.Entity)17 HashSet (java.util.HashSet)16 Type (com.yahoo.elide.core.type.Type)13 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)12 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)10 Map (java.util.Map)10 BeforeAll (org.junit.jupiter.api.BeforeAll)10 PersistentResource (com.yahoo.elide.core.PersistentResource)9 Set (java.util.Set)9 ReadPermission (com.yahoo.elide.annotation.ReadPermission)8 ClassType (com.yahoo.elide.core.type.ClassType)8 List (java.util.List)8 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)7 DataStore (com.yahoo.elide.core.datastore.DataStore)7 InvalidObjectIdentifierException (com.yahoo.elide.core.exceptions.InvalidObjectIdentifierException)7 Check (com.yahoo.elide.core.security.checks.Check)7