Search in sources :

Example 16 with User

use of org.structr.web.entity.User in project structr by structr.

the class SaveLocalStorageCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final Map<String, Object> nodeData = webSocketData.getNodeData();
    final String localStorageString = (String) nodeData.get("localStorageString");
    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    if (StringUtils.isNotBlank(localStorageString)) {
        try {
            final User me = (User) securityContext.getUser(false);
            me.setLocalStorage(localStorageString);
            TransactionCommand.registerNodeCallback(me, callback);
        } catch (Throwable t) {
            logger.warn("Error saving localstorage", t);
            // send exception
            getWebSocket().send(MessageBuilder.status().code(422).message(t.toString()).build(), true);
        }
    } else {
        // send exception
        getWebSocket().send(MessageBuilder.status().code(422).message("Cannot save localStorage").build(), true);
    }
}
Also used : User(org.structr.web.entity.User) SecurityContext(org.structr.common.SecurityContext)

Example 17 with User

use of org.structr.web.entity.User in project structr by structr.

the class StructrConsoleCommand method start.

@Override
public void start(final Environment env) throws IOException {
    env.addSignalListener(this);
    final String userName = env.getEnv().get("USER");
    if (userName != null) {
        final App app = StructrApp.getInstance();
        try (final Tx tx = app.tx()) {
            user = app.nodeQuery(User.class).andName(userName).getFirst();
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    } else {
        logger.warn("Cannot start Structr shell, no username set!");
        return;
    }
    // abort if no user was found
    if (user == null) {
        logger.warn("Cannot start Structr shell, user not found for name {}!", userName);
        return;
    }
    final String terminalType = env.getEnv().get("TERM");
    if (terminalType != null) {
        if (terminalType.startsWith("xterm") || terminalType.startsWith("vt100") || terminalType.startsWith("vt220")) {
            term = new XTermTerminalEmulator(in, out, this);
        } else {
            logger.warn("Unsupported terminal type {}, aborting.", terminalType);
        }
        logger.warn("No terminal type provided, aborting.", terminalType);
    }
    if (term != null) {
        term.start();
        term.print("Welcome to the ");
        term.setBold(true);
        term.print("Structr " + VersionHelper.getFullVersionInfo());
        term.setBold(false);
        term.print(" JavaScript console. Use <Shift>+<Tab> to switch modes.");
        term.println();
        // display first prompt
        displayPrompt();
    } else {
        final OutputStreamWritable writable = new OutputStreamWritable(out);
        if (command != null) {
            try {
                this.console.run(command, writable);
            } catch (FrameworkException fex) {
                writable.println(fex.getMessage());
            }
        } else {
            writable.println("No command specified, aborting.");
        }
        callback.onExit(1);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException)

Example 18 with User

use of org.structr.web.entity.User in project structr by structr.

the class FtpTest method createFTPUser.

protected User createFTPUser(final String username, final String password) throws FrameworkException {
    PropertyMap props = new PropertyMap();
    props.put(StructrApp.key(Principal.class, "name"), username);
    props.put(StructrApp.key(Principal.class, "password"), password);
    return (User) createTestNodes(User.class, 1, props).get(0);
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) User(org.structr.web.entity.User) Principal(org.structr.core.entity.Principal)

Example 19 with User

use of org.structr.web.entity.User in project structr by structr.

the class DeploymentTest method test22TemplateOwnershipAndGrants.

@Test
public void test22TemplateOwnershipAndGrants() {
    Principal user1 = null;
    Principal user2 = null;
    try (final Tx tx = app.tx()) {
        user1 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
        user2 = createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
        tx.success();
    } catch (FrameworkException ex) {
        fail("Unexpected exception.");
    }
    Assert.assertNotNull("User was not created, test cannot continue", user1);
    Assert.assertNotNull("User was not created, test cannot continue", user2);
    // setup
    try (final Tx tx = app.tx()) {
        // create first page
        final Page page1 = Page.createNewPage(securityContext, "test22_1");
        final Html html1 = createElement(page1, page1, "html");
        final Head head1 = createElement(page1, html1, "head");
        createElement(page1, head1, "title", "test22_1");
        final Body body1 = createElement(page1, html1, "body");
        final Div div1 = createElement(page1, body1, "div");
        createElement(page1, div1, "div", "test1");
        createElement(page1, div1, "div", "test1");
        final Div component = createComponent(div1);
        // create second page
        final Page page2 = Page.createNewPage(securityContext, "test22_2");
        final Html html2 = createElement(page2, page2, "html");
        final Head head2 = createElement(page2, html2, "head");
        createElement(page2, head2, "title", "test22_2");
        final Body body2 = createElement(page2, html2, "body");
        final Div div2 = createElement(page2, body2, "div");
        // re-use template from above
        final Div cloned = cloneComponent(component, div2);
        component.grant(Permission.read, user1);
        cloned.grant(Permission.read, user2);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception.");
    }
    // test
    doImportExportRoundtrip(true, true, new Function() {

        @Override
        public Object apply(Object t) {
            try (final Tx tx = app.tx()) {
                createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user1"));
                createTestNode(User.class, new NodeAttribute<>(AbstractNode.name, "user2"));
                tx.success();
            } catch (FrameworkException ex) {
                fail("Unexpected exception.");
            }
            return null;
        }
    });
}
Also used : NodeAttribute(org.structr.core.graph.NodeAttribute) Head(org.structr.web.entity.html.Head) User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Html(org.structr.web.entity.html.Html) Page(org.structr.web.entity.dom.Page) Div(org.structr.web.entity.html.Div) Function(java.util.function.Function) GraphObject(org.structr.core.GraphObject) Body(org.structr.web.entity.html.Body) Principal(org.structr.core.entity.Principal) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Example 20 with User

use of org.structr.web.entity.User in project structr by structr.

the class FilesystemTest method test03UserHomeDirectory.

@Test
public void test03UserHomeDirectory() {
    Settings.FilesystemEnabled.setValue(true);
    try (final Tx tx = app.tx()) {
        app.create(User.class, "tester");
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final User tester = app.nodeQuery(User.class).andName("tester").getFirst();
        tester.setEMail("tester@structr.com");
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final User tester = app.nodeQuery(User.class).andName("tester").getFirst();
        tester.setEMail("tester2@structr.com");
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final User tester = app.nodeQuery(User.class).andName("tester").getFirst();
        tester.setEMail("tester3@structr.com");
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final User tester = app.nodeQuery(User.class).andName("tester").getFirst();
        final List<Folder> dirs = app.nodeQuery(Folder.class).getAsList();
        final Set<String> names = new HashSet<>();
        // there should only be two directories: home, and the home directory of the user
        assertEquals("Too many directories exist after modifying a user", 2, dirs.size());
        for (final Folder folder : dirs) {
            names.add(folder.getName());
        }
        // check for "home" directory
        assertTrue("A directory named 'home' must exist", names.contains("home"));
        // check for user home directory (which has the user's UUID as its name)
        assertTrue("A directory named 'home' must exist", names.contains(tester.getUuid()));
        tx.success();
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Unexpected exception.");
    }
}
Also used : User(org.structr.web.entity.User) Tx(org.structr.core.graph.Tx) Folder(org.structr.web.entity.Folder) HashSet(java.util.HashSet) Test(org.junit.Test) StructrUiTest(org.structr.web.StructrUiTest)

Aggregations

User (org.structr.web.entity.User)32 Tx (org.structr.core.graph.Tx)27 FrameworkException (org.structr.common.error.FrameworkException)23 Test (org.junit.Test)21 StructrUiTest (org.structr.web.StructrUiTest)16 PropertyMap (org.structr.core.property.PropertyMap)14 Principal (org.structr.core.entity.Principal)10 App (org.structr.core.app.App)8 StructrApp (org.structr.core.app.StructrApp)8 NodeAttribute (org.structr.core.graph.NodeAttribute)7 SecurityContext (org.structr.common.SecurityContext)5 Folder (org.structr.web.entity.Folder)5 SchemaMethod (org.structr.core.entity.SchemaMethod)4 SchemaNode (org.structr.core.entity.SchemaNode)4 Page (org.structr.web.entity.dom.Page)4 GraphObject (org.structr.core.GraphObject)3 RenderContext (org.structr.web.common.RenderContext)3 File (org.structr.web.entity.File)3 Body (org.structr.web.entity.html.Body)3 Div (org.structr.web.entity.html.Div)3