Search in sources :

Example 36 with Principal

use of org.structr.core.entity.Principal in project structr by structr.

the class StructrSessionDataStore method doStore.

@Override
public void doStore(final String id, final SessionData data, final long lastSaveTime) throws Exception {
    assertInitialized();
    try (final Tx tx = StructrApp.getInstance().tx()) {
        final Principal user = AuthHelper.getPrincipalForSessionId(id);
        // store sessions only for authenticated users
        if (user != null) {
            user.setSessionData(Base64.encode(SerializationUtils.serialize(data)));
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.info("Unable to store session data for session id " + id + ".", ex);
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Principal(org.structr.core.entity.Principal)

Example 37 with Principal

use of org.structr.core.entity.Principal in project structr by structr.

the class StructrSessionDataStore method load.

@Override
public SessionData load(final String id) throws Exception {
    assertInitialized();
    SessionData sessionData = null;
    try (final Tx tx = StructrApp.getInstance().tx()) {
        final Principal user = AuthHelper.getPrincipalForSessionId(id);
        // store sessions only for authenticated users
        if (user != null) {
            final String sessionDataString = user.getSessionData();
            if (sessionDataString != null) {
                sessionData = SerializationUtils.deserialize(Base64.decode(sessionDataString));
            }
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.info("Unable to load session data for session id " + id + ".", ex);
    }
    return sessionData;
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) SessionData(org.eclipse.jetty.server.session.SessionData) Principal(org.structr.core.entity.Principal)

Example 38 with Principal

use of org.structr.core.entity.Principal in project structr by structr.

the class AdvancedSearchTest method testSearchWithOwnerAndEnum.

@Test
public void testSearchWithOwnerAndEnum() {
    final Class testUserType = createTestUserType();
    try {
        final List<Principal> users = createTestNodes(testUserType, 3);
        final List<TestThree> testThrees = new LinkedList<>();
        final Random random = new Random();
        String uuid = null;
        int count = 0;
        try (final Tx tx = app.tx()) {
            for (final Principal user : users) {
                // create 20 entities for every user
                for (int i = 0; i < 20; i++) {
                    testThrees.add(app.create(TestThree.class, new NodeAttribute(AbstractNode.name, "test" + count++), new NodeAttribute(AbstractNode.owner, user), new NodeAttribute(TestThree.enumProperty, TestEnum.values()[random.nextInt(TestEnum.values().length)])));
                }
            }
            uuid = users.get(0).getUuid();
            tx.success();
        }
        // test with core API
        try (final Tx tx = app.tx()) {
            for (final Principal user : users) {
                for (final TestThree test : app.nodeQuery(TestThree.class).and(AbstractNode.owner, user).and(TestThree.enumProperty, TestEnum.Status1).getAsList()) {
                    assertEquals("Invalid enum query result", TestEnum.Status1, test.getProperty(TestThree.enumProperty));
                }
            }
            tx.success();
        }
        // test via REST
        RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(500)).expect().statusCode(200).when().get(concat("/test_threes?sort=createdDate&owner=" + uuid + "&enumProperty=" + TestEnum.Status1));
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        fail("Unexpected exception");
    }
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Random(java.util.Random) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestThree(org.structr.rest.entity.TestThree) Principal(org.structr.core.entity.Principal) LinkedList(java.util.LinkedList) Test(org.junit.Test) IndexingTest(org.structr.rest.common.IndexingTest)

Example 39 with Principal

use of org.structr.core.entity.Principal in project structr by structr.

the class PagingAndSortingTest method testRelationshipResourcePagingOnCollectionResource.

@Test
public void testRelationshipResourcePagingOnCollectionResource() {
    final Class testUserType = createTestUserType();
    final PropertyKey<String> passwordKey = StructrApp.key(testUserType, "password");
    Principal tester = null;
    try (final Tx tx = app.tx()) {
        tester = app.create(testUserType, new Name("tester"), new NodeAttribute<>(passwordKey, "test"));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final App app = StructrApp.getInstance(SecurityContext.getInstance(tester, AccessMode.Backend));
    try (final Tx tx = app.tx()) {
        app.create(TestOne.class, "TestOne1");
        app.create(TestOne.class, "TestOne2");
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).expect().statusCode(200).body("result_count", equalTo(4)).body("page_size", equalTo(2)).body("page_count", equalTo(2)).body("result", hasSize(2)).body("result[0].type", equalTo("PrincipalOwnsNode")).body("result[1].type", equalTo("Security")).when().get("/TestOne/in?pageSize=2");
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Principal(org.structr.core.entity.Principal) Name(org.structr.core.graph.attribute.Name) Test(org.junit.Test) StructrRestTest(org.structr.rest.common.StructrRestTest)

Example 40 with Principal

use of org.structr.core.entity.Principal in project structr by structr.

the class PagingAndSortingTest method testRelationshipResourcePagingOnEntityResource.

@Test
public void testRelationshipResourcePagingOnEntityResource() {
    final Class testUserType = createTestUserType();
    final PropertyKey<String> passwordKey = StructrApp.key(testUserType, "password");
    Principal tester = null;
    try (final Tx tx = app.tx()) {
        tester = app.create(testUserType, new Name("tester"), new NodeAttribute<>(passwordKey, "test"));
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    final App app = StructrApp.getInstance(SecurityContext.getInstance(tester, AccessMode.Backend));
    try (final Tx tx = app.tx()) {
        app.create(TestOne.class, "TestOne1");
        app.create(TestOne.class, "TestOne2");
        tx.success();
    } catch (FrameworkException fex) {
        fex.printStackTrace();
    }
    RestAssured.given().contentType("application/json; charset=UTF-8").filter(ResponseLoggingFilter.logResponseIfStatusCodeIs(200)).expect().statusCode(200).body("result_count", equalTo(4)).body("page_size", equalTo(2)).body("page_count", equalTo(2)).body("result", hasSize(2)).body("result[0].type", equalTo("PrincipalOwnsNode")).body("result[1].type", equalTo("Security")).when().get("/TestUser/" + tester.getUuid() + "/out?pageSize=2");
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Principal(org.structr.core.entity.Principal) Name(org.structr.core.graph.attribute.Name) Test(org.junit.Test) StructrRestTest(org.structr.rest.common.StructrRestTest)

Aggregations

Principal (org.structr.core.entity.Principal)112 FrameworkException (org.structr.common.error.FrameworkException)68 Tx (org.structr.core.graph.Tx)65 Test (org.junit.Test)41 App (org.structr.core.app.App)31 StructrApp (org.structr.core.app.StructrApp)31 TestOne (org.structr.core.entity.TestOne)16 Group (org.structr.core.entity.Group)14 NodeAttribute (org.structr.core.graph.NodeAttribute)13 PropertyMap (org.structr.core.property.PropertyMap)13 SecurityContext (org.structr.common.SecurityContext)10 LinkedList (java.util.LinkedList)9 Result (org.structr.core.Result)8 User (org.structr.web.entity.User)8 AbstractNode (org.structr.core.entity.AbstractNode)7 SuperUser (org.structr.core.entity.SuperUser)7 StructrUiTest (org.structr.web.StructrUiTest)7 Page (org.structr.web.entity.dom.Page)7 IOException (java.io.IOException)6 List (java.util.List)6