diff --git a/conf/core/authtoken.example.yaml b/conf/core/authtoken.example.yaml index 17c903a3a18b29b79720d4f9de8aade8ecfed2cc..d0628842f2b6a8c1037156b286f1eab094ce4499 100644 --- a/conf/core/authtoken.example.yaml +++ b/conf/core/authtoken.example.yaml @@ -1,3 +1,4 @@ +# TODO: Add documentation. - purpose: scripting:administration/diagnostics.py roles: - administration diff --git a/conf/core/server.conf b/conf/core/server.conf index 34d688b69ea5f00bc37348110ed85d57b715b7dd..ed08510ea7187f82b62bc5eba84cd586af1b5706 100644 --- a/conf/core/server.conf +++ b/conf/core/server.conf @@ -115,17 +115,17 @@ CERTIFICATES_KEY_STORE_PASSWORD= SESSION_TIMEOUT_MS=600000 # Time after which one-time tokens expire. -# This is only a default value. The actual timeout of each token can be -# configured otherwise. +# This is only a default value. The actual timeout of tokens can be +# configured otherwise, for example in authtoken.yml. # 7days ONE_TIME_TOKEN_EXPIRES_MS=604800000 -# Path to config file for one time tokens. +# Path to config file for one time tokens, for example authtoken.yml. AUTHTOKEN_CONFIG= # Timeout after which a consumed one-time token expires regardless of the # maximum of attempts that are allowed for that token. This is only a default -# value. The actual timeout of each token can be configured otherwise. +# value. The actual timeout of tokens can be configured otherwise. # 30 s ONE_TIME_TOKEN_ATTEMPTS_TIMEOUT_MS=30000 diff --git a/src/main/java/caosdb/server/CaosDBServer.java b/src/main/java/caosdb/server/CaosDBServer.java index bfca2f3c13520ec83a35c8f3bd8d88cdb6ae1f81..88beecfbc3d437ab75d121c60a8105c2bbe3107a 100644 --- a/src/main/java/caosdb/server/CaosDBServer.java +++ b/src/main/java/caosdb/server/CaosDBServer.java @@ -128,6 +128,60 @@ public class CaosDBServer extends Application { return getServerProperties().getProperty(key); } + /** + * This main method starts up a web application that will listen on a port defined in the config + * file. + * + * @param args One option temporarily (for testing) available: silent: If present: disable + * System.out-stream (stream to a NullPrintStream). This makes the response of the database + * amazingly faster. + * @throws IOException + * @throws FileNotFoundException + * @throws SecurityException + * @throws Exception If problems occur. + */ + public static void main(final String[] args) + throws SecurityException, FileNotFoundException, IOException { + try { + init(args); + initScheduler(); + initServerProperties(); + initTimeZone(); + initOneTimeTokens(); + initShiro(); + initBackend(); + initWebServer(); + initShutDownHook(); + } catch (Exception e1) { + logger.error("Could not start the server.", e1); + System.exit(1); + } + } + + private static void init(final String[] args) { + // Important change: + // Make silent the default option + START_GUI = false; + for (final String s : args) { + if (s.equals("silent")) { + START_GUI = false; + } else if (s.equals("gui")) { + START_GUI = true; + } else if (s.equals("nobackend")) { + START_BACKEND = false; + } else if (s.equals("insecure")) { + INSECURE = true; + } + } + INSECURE = INSECURE && isDebugMode(); // only allow insecure in debug mode + START_BACKEND = START_BACKEND || !isDebugMode(); // always start backend if not in debug mode + } + + private static void initScheduler() throws SchedulerException { + SCHEDULER = StdSchedulerFactory.getDefaultScheduler(); + SCHEDULER.start(); + } + public static void initServerProperties() throws IOException { SERVER_PROPERTIES = ServerProperties.initServerProperties(); } @@ -211,23 +265,15 @@ public class CaosDBServer extends Application { } } - private static void init(final String[] args) { - // Important change: - // Make silent the default option - START_GUI = false; - for (final String s : args) { - if (s.equals("silent")) { - START_GUI = false; - } else if (s.equals("gui")) { - START_GUI = true; - } else if (s.equals("nobackend")) { - START_BACKEND = false; - } else if (s.equals("insecure")) { - INSECURE = true; - } - } - INSECURE = INSECURE && isDebugMode(); // only allow insecure in debug mode - START_BACKEND = START_BACKEND || !isDebugMode(); // always start backend if // not in debug mode + public static void initOneTimeTokens() throws Exception { + OneTimeAuthenticationToken.initConfig(); + ConsumedInfoCleanupJob.scheduleDaily(); + } + + public static void initShiro() { + // init Shiro (user authentication/authorization and session management) + final Ini config = getShiroConfig(); + initShiro(config); } public static Ini getShiroConfig() { @@ -255,12 +301,6 @@ public class CaosDBServer extends Application { SecurityUtils.setSecurityManager(securityManager); } - public static void initShiro() { - // init Shiro (user authentication/authorization and session management) - final Ini config = getShiroConfig(); - initShiro(config); - } - public static void initBackend() throws Exception { if (START_BACKEND) { try (final Initialization init = Initialization.setUp()) { @@ -286,67 +326,6 @@ public class CaosDBServer extends Application { } } - public static void initGUI() throws InterruptedException { - if (START_GUI) { - final CaosDBTerminal caosDBTerminal = new CaosDBTerminal(); - caosDBTerminal.setName("CaosDBTerminal"); - caosDBTerminal.start(); - - addPreShutdownHook( - new Runnable() { - - @Override - public void run() { - caosDBTerminal.shutDown(); - SystemErrPanel.close(); - } - }); - // wait until the terminal is initialized. - Thread.sleep(1000); - - // add Benchmark - StatsPanel.addStat("TransactionBenchmark", TransactionBenchmark.getRootInstance()); - } else { - logger.info("NO GUI"); - System.setOut(new NullPrintStream()); - } - } - - public static void initOneTimeTokens() throws Exception { - OneTimeAuthenticationToken.initConfig(); - ConsumedInfoCleanupJob.scheduleDaily(); - } - - /** - * This main method starts up a web application that will listen on a port defined in the config - * file. - * - * @param args One option temporarily (for testing) available: silent: If present: disable - * System.out-stream (stream to a NullPrintStream). This makes the response of the database - * amazingly faster. - * @throws IOException - * @throws FileNotFoundException - * @throws SecurityException - * @throws Exception If problems occur. - */ - public static void main(final String[] args) - throws SecurityException, FileNotFoundException, IOException { - try { - init(args); - initScheduler(); - initServerProperties(); - initTimeZone(); - initOneTimeTokens(); - initShiro(); - initBackend(); - initWebServer(); - initShutDownHook(); - } catch (Exception e1) { - logger.error("Could not start the server.", e1); - System.exit(1); - } - } - private static void initWebServer() throws Exception { final int port_https = Integer.parseInt(getServerProperty(ServerProperties.KEY_SERVER_PORT_HTTPS)); @@ -372,9 +351,30 @@ public class CaosDBServer extends Application { } } - private static void initScheduler() throws SchedulerException { - SCHEDULER = StdSchedulerFactory.getDefaultScheduler(); - SCHEDULER.start(); + public static void initGUI() throws InterruptedException { + if (START_GUI) { + final CaosDBTerminal caosDBTerminal = new CaosDBTerminal(); + caosDBTerminal.setName("CaosDBTerminal"); + caosDBTerminal.start(); + + addPreShutdownHook( + new Runnable() { + + @Override + public void run() { + caosDBTerminal.shutDown(); + SystemErrPanel.close(); + } + }); + // wait until the terminal is initialized. + Thread.sleep(1000); + + // add Benchmark + StatsPanel.addStat("TransactionBenchmark", TransactionBenchmark.getRootInstance()); + } else { + logger.info("NO GUI"); + System.setOut(new NullPrintStream()); + } } private static void initDatatypes(final Access access) throws Exception {