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);
}
}
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);
}
}
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);
}
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;
}
});
}
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.");
}
}
Aggregations