Search in sources :

Example 46 with RequestScope

use of com.yahoo.elide.core.RequestScope 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 47 with RequestScope

use of com.yahoo.elide.core.RequestScope 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 48 with RequestScope

use of com.yahoo.elide.core.RequestScope in project elide by yahoo.

the class PermissionExecutorTest method testReadFieldAwareFailureAllSpecificField.

@Test
public void testReadFieldAwareFailureAllSpecificField() {
    PersistentResource resource = newResource(SampleBean.class, false);
    RequestScope requestScope = resource.getRequestScope();
    assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, null, ReadPermission.class, "allVisible"));
    requestScope.getPermissionExecutor().executeCommitChecks();
}
Also used : PersistentResource(com.yahoo.elide.core.PersistentResource) ReadPermission(com.yahoo.elide.annotation.ReadPermission) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 49 with RequestScope

use of com.yahoo.elide.core.RequestScope in project elide by yahoo.

the class PermissionExecutorTest method testReadFailureFieldAwareOpenBean.

@Test
public void testReadFailureFieldAwareOpenBean() {
    PersistentResource resource = newResource(OpenBean.class, false);
    RequestScope requestScope = resource.getRequestScope();
    assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, null, ReadPermission.class, "openAll"));
    requestScope.getPermissionExecutor().executeCommitChecks();
}
Also used : PersistentResource(com.yahoo.elide.core.PersistentResource) ReadPermission(com.yahoo.elide.annotation.ReadPermission) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 50 with RequestScope

use of com.yahoo.elide.core.RequestScope in project elide by yahoo.

the class CollectionTerminalState method handlePost.

@Override
public Supplier<Pair<Integer, JsonNode>> handlePost(StateContext state) {
    RequestScope requestScope = state.getRequestScope();
    JsonApiMapper mapper = requestScope.getMapper();
    newObject = createObject(requestScope);
    parent.ifPresent(persistentResource -> persistentResource.addRelation(relationName.get(), newObject));
    return () -> {
        JsonApiDocument returnDoc = new JsonApiDocument();
        returnDoc.setData(new Data<>(newObject.toResource()));
        JsonNode responseBody = mapper.getObjectMapper().convertValue(returnDoc, JsonNode.class);
        return Pair.of(HttpStatus.SC_CREATED, responseBody);
    };
}
Also used : JsonApiDocument(com.yahoo.elide.jsonapi.models.JsonApiDocument) Data(com.yahoo.elide.jsonapi.models.Data) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonApiMapper(com.yahoo.elide.jsonapi.JsonApiMapper) RequestScope(com.yahoo.elide.core.RequestScope)

Aggregations

RequestScope (com.yahoo.elide.core.RequestScope)132 Test (org.junit.jupiter.api.Test)99 PersistentResource (com.yahoo.elide.core.PersistentResource)63 TestRequestScope (com.yahoo.elide.core.TestRequestScope)28 Include (com.yahoo.elide.annotation.Include)27 Entity (javax.persistence.Entity)27 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)26 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)23 ReadPermission (com.yahoo.elide.annotation.ReadPermission)22 EntityProjection (com.yahoo.elide.core.request.EntityProjection)22 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)22 Book (example.Book)19 UpdatePermission (com.yahoo.elide.annotation.UpdatePermission)17 JsonApiDocument (com.yahoo.elide.jsonapi.models.JsonApiDocument)15 HashSet (java.util.HashSet)15 Publisher (example.Publisher)14 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)12 Author (example.Author)10 Editor (example.Editor)10 Collection (java.util.Collection)10