use of org.structr.common.error.FrameworkException in project structr by structr.
the class ResourceAccessTest method test01ResourceAccessGET.
@Test
public void test01ResourceAccessGET() {
// clear resource access objects that are created by the dynamic schema
clearResourceAccess();
Folder testFolder = null;
ResourceAccess folderGrant = null;
try (final Tx tx = app.tx()) {
testFolder = createTestNodes(Folder.class, 1).get(0);
assertNotNull(testFolder);
// no resource access node at all => forbidden
RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(401).when().get("/folders");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
folderGrant = createResourceAccess("Folder", UiAuthenticator.FORBIDDEN);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
// resource access explicetly set to FORBIDDEN => forbidden
RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(401).when().get("/folders");
// allow GET for authenticated users => access without user/pass should be still forbidden
folderGrant.setProperties(folderGrant.getSecurityContext(), new PropertyMap(GraphObject.visibleToPublicUsers, true));
folderGrant.setFlag(UiAuthenticator.AUTH_USER_GET);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(401).when().get("/folders");
// allow GET for non-authenticated users => access without user/pass should be allowed
folderGrant.setFlag(UiAuthenticator.NON_AUTH_USER_GET);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(200).when().get("/folders");
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class ResourceAccessTest method test04ResourceAccessDELETE.
@Test
public void test04ResourceAccessDELETE() {
// clear resource access objects that are created by the dynamic schema
clearResourceAccess();
final String name = "testuser-01";
final String password = "testpassword-01";
Folder testFolder = null;
User testUser = null;
ResourceAccess folderGrant = null;
try (final Tx tx = app.tx()) {
testFolder = createTestNodes(Folder.class, 1).get(0);
assertNotNull(testFolder);
testUser = createTestNodes(User.class, 1).get(0);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
// no resource access node at all => forbidden
RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(401).when().delete("/folder/" + testFolder.getUuid());
folderGrant = createResourceAccess("Folder", UiAuthenticator.FORBIDDEN);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
// resource access explicitly set to FORBIDDEN => forbidden
RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(401).when().delete("/folder/" + testFolder.getUuid());
folderGrant.setFlag(UiAuthenticator.AUTH_USER_DELETE);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(401).when().delete("/folder/" + testFolder.getUuid());
folderGrant.setProperties(folderGrant.getSecurityContext(), new PropertyMap(GraphObject.visibleToPublicUsers, true));
folderGrant.setFlag(UiAuthenticator.NON_AUTH_USER_DELETE);
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").expect().statusCode(404).when().delete("/folder/" + testFolder.getUuid());
final PropertyMap changedProperties = new PropertyMap();
changedProperties.put(StructrApp.key(User.class, "name"), name);
changedProperties.put(StructrApp.key(User.class, "password"), password);
testUser.setProperties(testUser.getSecurityContext(), changedProperties);
// make user own folder
testFolder.setProperties(testFolder.getSecurityContext(), new PropertyMap(AbstractNode.owner, testUser));
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
// test user owns object now => 200
RestAssured.given().headers("X-User", name, "X-Password", password).contentType("application/json; charset=UTF-8").expect().statusCode(200).when().delete("/folder/" + testFolder.getUuid());
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
logger.error(fex.toString());
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class SchemaMethodsTest method test05InheritedSchemaMethodOnBuildinType.
@Test
public void test05InheritedSchemaMethodOnBuildinType() {
final String builtinTypeName = "File";
final String schemaMethodName = "testFileMethod";
User admin = null;
try (final Tx tx = app.tx()) {
admin = createAdminUser();
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
// Add schema method "testFileMethod" to built-in File class
SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
final PropertyMap testFileMethodProperties = new PropertyMap();
testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
testFileMethodProperties.put(SchemaMethod.source, "()");
testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post("/Image/" + schemaMethodName);
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class SchemaMethodsTest method test06InheritedSchemaMethodOnEntityOfBuiltinType.
@Test
public void test06InheritedSchemaMethodOnEntityOfBuiltinType() {
final String builtinTypeName = "File";
final String schemaMethodName = "testFileMethod";
User admin = null;
try (final Tx tx = app.tx()) {
admin = createAdminUser();
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
// Add schema method "testFileMethod" to built-in File class
SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
final PropertyMap testFileMethodProperties = new PropertyMap();
testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
testFileMethodProperties.put(SchemaMethod.source, "()");
testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
String id = createEntityAsAdmin("Image", "{'name': 'Test Image'}");
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post("/Image/" + id + "/" + schemaMethodName);
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.common.error.FrameworkException in project structr by structr.
the class SchemaMethodsTest method test01SchemaMethodOnBuiltinType.
@Test
public void test01SchemaMethodOnBuiltinType() {
final String builtinTypeName = "File";
final String schemaMethodName = "testFileMethod";
try (final Tx tx = app.tx()) {
// Add schema method "testFileMethod" to built-in File class
SchemaNode fileNodeDef = app.nodeQuery(SchemaNode.class).andName(builtinTypeName).getFirst();
final PropertyMap testFileMethodProperties = new PropertyMap();
testFileMethodProperties.put(SchemaMethod.name, schemaMethodName);
testFileMethodProperties.put(SchemaMethod.source, "()");
testFileMethodProperties.put(SchemaMethod.schemaNode, fileNodeDef);
SchemaMethod testFileMethod = app.create(SchemaMethod.class, testFileMethodProperties);
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
User admin = null;
try (final Tx tx = app.tx()) {
admin = createAdminUser();
tx.success();
} catch (Exception ex) {
logger.error("", ex);
}
try (final Tx tx = app.tx()) {
RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(201)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(400)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(404)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(422)).filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).headers("X-User", ADMIN_USERNAME, "X-Password", ADMIN_PASSWORD).body("{}").expect().statusCode(200).when().post(builtinTypeName + "/" + schemaMethodName);
tx.success();
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations