use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testReadFieldAwareEntireOpenBean.
@Test
public void testReadFieldAwareEntireOpenBean() {
OpenBean openBean = new OpenBean();
openBean.id = 1L;
PersistentResource resource = newResource(openBean, OpenBean.class, false);
RequestScope requestScope = resource.getRequestScope();
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource));
assertEquals(ExpressionResult.PASS, requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, null, ReadPermission.class, "open"));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.PersistentResource 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.PersistentResource 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.PersistentResource 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.PersistentResource 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();
}
Aggregations