Search in sources :

Example 66 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class AccessControlTest method test09PrivilegeEscalation.

@Test
public void test09PrivilegeEscalation() {
    // remove auto-generated resource access objects
    clearResourceAccess();
    try {
        final Class principalType = StructrApp.getConfiguration().getNodeEntityClass("Principal");
        Principal nonAdmin = (Principal) createTestNode(principalType);
        final PropertyKey<Boolean> isAdminKey = StructrApp.key(principalType, "isAdmin");
        final SecurityContext userContext = SecurityContext.getInstance(nonAdmin, AccessMode.Frontend);
        nonAdmin.setSecurityContext(userContext);
        App userApp = StructrApp.getInstance(userContext);
        try (final Tx tx = userApp.tx()) {
            assertFalse(nonAdmin.isAdmin());
            nonAdmin.setProperty(isAdminKey, true);
            fail("Privilege escalation using setProperty()-method! Non-admin may not set an admin flag!");
            tx.success();
        } catch (FrameworkException ex) {
            assertFalse("Privilege escalation using setProperty()-method! Non-admin may not set an admin flag!", nonAdmin.isAdmin());
        }
        try (final Tx tx = userApp.tx()) {
            assertFalse(nonAdmin.isAdmin());
            PropertyMap props = new PropertyMap();
            props.put(isAdminKey, true);
            nonAdmin.setProperties(userContext, props);
            fail("Privilege escalation using setProperties()-method! Non-admin may not set an admin flag!");
            tx.success();
        } catch (FrameworkException ex) {
            assertFalse("Privilege escalation using setProperties()-method! Non-admin may not set an admin flag!", nonAdmin.isAdmin());
        }
    } catch (FrameworkException ex) {
        fail("Unexpected Exception");
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Principal(org.structr.core.entity.Principal) Test(org.junit.Test)

Example 67 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class BasicTest method test02CreateTwoNodesWithSameUuidInSameTx.

@Test
public void test02CreateTwoNodesWithSameUuidInSameTx() {
    try {
        final PropertyMap props = new PropertyMap();
        TestOne node = null;
        final String uuid = StringUtils.replace(UUID.randomUUID().toString(), "-", "");
        props.put(GraphObject.id, uuid);
        try (final Tx tx = app.tx()) {
            node = app.create(TestOne.class, props);
            assertTrue(node != null);
            assertTrue(node instanceof TestOne);
            assertEquals(node.getUuid(), uuid);
            node = app.create(TestOne.class, props);
            tx.success();
            fail("Validation failed!");
        }
    } catch (FrameworkException ex) {
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) Test(org.junit.Test)

Example 68 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class BasicTest method test01DeleteNode.

/**
 * Test successful deletion of a node.
 *
 * The node shouldn't be found afterwards.
 * Creation and deletion are executed in two different transactions.
 */
@Test
public void test01DeleteNode() {
    try {
        final PropertyMap props = new PropertyMap();
        final String type = "GenericNode";
        final String name = "GenericNode-name";
        NodeInterface node = null;
        String uuid = null;
        props.put(AbstractNode.type, type);
        props.put(AbstractNode.name, name);
        try (final Tx tx = app.tx()) {
            node = app.create(GenericNode.class, props);
            tx.success();
        }
        assertTrue(node != null);
        try (final Tx tx = app.tx()) {
            uuid = node.getUuid();
        }
        try (final Tx tx = app.tx()) {
            app.delete(node);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            Result result = app.nodeQuery().uuid(uuid).getResult();
            assertEquals("Node should have been deleted", 0, result.size());
        } catch (FrameworkException fe) {
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) GenericNode(org.structr.core.entity.GenericNode) NodeInterface(org.structr.core.graph.NodeInterface) Result(org.structr.core.Result) Test(org.junit.Test)

Example 69 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class BasicTest method test02CreateNodeWithExistingUuid.

@Test
public void test02CreateNodeWithExistingUuid() {
    try {
        final PropertyMap props = new PropertyMap();
        TestOne node = null;
        final String uuid = StringUtils.replace(UUID.randomUUID().toString(), "-", "");
        props.put(GraphObject.id, uuid);
        try (final Tx tx = app.tx()) {
            node = app.create(TestOne.class, props);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            assertTrue(node != null);
            assertTrue(node instanceof TestOne);
            assertEquals(node.getUuid(), uuid);
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) Test(org.junit.Test)

Example 70 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class BasicTest method test00SimpleCreateOperation.

@Test
public void test00SimpleCreateOperation() {
    try (final Tx tx = app.tx()) {
        final PropertyMap properties = new PropertyMap();
        properties.put(TestSix.name, "name");
        // test null value for a 1:1 related property
        properties.put(TestSix.oneToOneTestThree, null);
        app.create(TestSix.class, properties);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
    try (final Tx tx = app.tx()) {
        final TestSix test = app.nodeQuery(TestSix.class).getFirst();
        assertNotNull("Invalid simple object creation result", test);
        assertEquals("Invalid simple object creation result", "name", test.getProperty(AbstractNode.name));
        assertEquals("Invalid simple object creation result", null, test.getProperty(TestSix.oneToOneTestThree));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Aggregations

PropertyMap (org.structr.core.property.PropertyMap)233 FrameworkException (org.structr.common.error.FrameworkException)100 Tx (org.structr.core.graph.Tx)93 Test (org.junit.Test)60 App (org.structr.core.app.App)34 StructrApp (org.structr.core.app.StructrApp)34 PropertyKey (org.structr.core.property.PropertyKey)34 LinkedList (java.util.LinkedList)28 NodeInterface (org.structr.core.graph.NodeInterface)25 SchemaProperty (org.structr.core.entity.SchemaProperty)23 SecurityContext (org.structr.common.SecurityContext)22 StructrUiTest (org.structr.web.StructrUiTest)21 GraphObject (org.structr.core.GraphObject)20 Result (org.structr.core.Result)19 File (org.structr.web.entity.File)19 DOMNode (org.structr.web.entity.dom.DOMNode)19 TestOne (org.structr.core.entity.TestOne)17 AbstractNode (org.structr.core.entity.AbstractNode)16 Folder (org.structr.web.entity.Folder)15 Page (org.structr.web.entity.dom.Page)15