use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testBadInstance.
@Test
public void testBadInstance() {
@Entity
@Include(rootLevel = false)
@UpdatePermission(expression = "privatePermission")
class Model {
}
PersistentResource resource = newResource(new Model(), Model.class, true);
RequestScope requestScope = resource.getRequestScope();
assertThrows(IllegalArgumentException.class, () -> requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testReadFieldAwareSuccessFailureAnyField.
@Test
public void testReadFieldAwareSuccessFailureAnyField() {
PersistentResource resource = newResource(SampleBean.class, false);
RequestScope requestScope = resource.getRequestScope();
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().checkPermission(ReadPermission.class, resource));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testDeleteCheckExpressionForNewlyCreatedObject.
@Test
public void testDeleteCheckExpressionForNewlyCreatedObject() {
@Entity
@Include(rootLevel = false)
@DeletePermission(expression = "FailOp")
class Model {
}
PersistentResource resource = newResource(new Model(), Model.class, true);
RequestScope requestScope = resource.getRequestScope();
requestScope.getDictionary().bindEntity(Model.class);
assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(DeletePermission.class, resource));
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testReadFieldAwareFailureAllNoOverride.
@Test
public void testReadFieldAwareFailureAllNoOverride() {
PersistentResource resource = newResource(SampleBean.class, false);
RequestScope requestScope = resource.getRequestScope();
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().checkSpecificFieldPermissions(resource, null, ReadPermission.class, "defaultHidden"));
requestScope.getPermissionExecutor().executeCommitChecks();
}
use of com.yahoo.elide.core.PersistentResource in project elide by yahoo.
the class PermissionExecutorTest method testFailOperationCheckDeferred.
@Test
public void testFailOperationCheckDeferred() throws Exception {
@Entity
@Include(rootLevel = false)
@UpdatePermission(expression = "sampleOperation")
class Model implements SampleOperationModel {
@Override
public boolean test() {
return false;
}
}
PersistentResource resource = newResource(new Model(), Model.class, true);
RequestScope requestScope = resource.getRequestScope();
// Because the object is newly created, the check is DEFERRED.
assertEquals(ExpressionResult.DEFERRED, requestScope.getPermissionExecutor().checkPermission(UpdatePermission.class, resource));
assertThrows(ForbiddenAccessException.class, () -> requestScope.getPermissionExecutor().executeCommitChecks());
}
Aggregations