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());
}
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));
}
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();
}
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();
}
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);
};
}
Aggregations