From ee0e18ab4101f6ae9513794ed52434af1e54bfb1 Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Tue, 18 May 2021 08:03:49 +0000
Subject: [PATCH] MAINT rename insecure to --no-tls and add to Makefile

---
 CHANGELOG.md                                  |  1 +
 Makefile                                      |  8 +++++---
 .../java/org/caosdb/server/CaosDBServer.java  | 19 +++++++++----------
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e560318..c9cee75e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
+* Server can be started without TLS even when not in debug mode.
 * Select queries would originally only select the returned properties by their
   names and would not check if a property is a subtype of a selected property. This
   has changed now and select queries will also return subtypes of selected
diff --git a/Makefile b/Makefile
index d73f140f..1304d9ef 100644
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,7 @@
 #
 
 CAOSDB_SERVER_VERSION ?= $(shell mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)
+CAOSDB_COMMAND_LINE_OPTIONS ?=
 SHELL:=/bin/bash
 JPDA_PORT ?= 9000
 JMX_PORT ?= 9090
@@ -41,13 +42,14 @@ run: compile
 	mvn exec:java@run
 
 run-debug: jar
-	java -Xrunjdwp:transport=dt_socket,address=0.0.0.0:$(JPDA_PORT),server=y,suspend=n -Dcaosdb.debug=true -jar target/caosdb-server.jar
+	java -Xrunjdwp:transport=dt_socket,address=0.0.0.0:$(JPDA_PORT),server=y,suspend=n -Dcaosdb.debug=true -jar target/caosdb-server.jar $(CAOSDB_COMMAND_LINE_OPTIONS)
+
 
 run-debug-single:
-	java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$(JMX_PORT) -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Xrunjdwp:transport=dt_socket,address=0.0.0.0:$(JPDA_PORT),server=y,suspend=n -Dcaosdb.debug=true -jar target/caosdb-server.jar
+	java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$(JMX_PORT) -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Xrunjdwp:transport=dt_socket,address=0.0.0.0:$(JPDA_PORT),server=y,suspend=n -Dcaosdb.debug=true -jar target/caosdb-server.jar $(CAOSDB_COMMAND_LINE_OPTIONS)
 
 run-single:
-	java -jar target/caosdb-server.jar
+	java -jar target/caosdb-server.jar $(CAOSDB_COMMAND_LINE_OPTIONS)
 
 formatting:
 	mvn fmt:format
diff --git a/src/main/java/org/caosdb/server/CaosDBServer.java b/src/main/java/org/caosdb/server/CaosDBServer.java
index 4a69f24d..74e70fc6 100644
--- a/src/main/java/org/caosdb/server/CaosDBServer.java
+++ b/src/main/java/org/caosdb/server/CaosDBServer.java
@@ -117,7 +117,7 @@ public class CaosDBServer extends Application {
   private static ArrayList<Runnable> postShutdownHooks = new ArrayList<Runnable>();
   private static ArrayList<Runnable> preShutdownHooks = new ArrayList<Runnable>();
   private static boolean START_BACKEND = true;
-  private static boolean INSECURE = false;
+  private static boolean NO_TLS = false;
   public static final String REQUEST_TIME_LOGGER = "REQUEST_TIME_LOGGER";
   public static final String REQUEST_ERRORS_LOGGER = "REQUEST_ERRORS_LOGGER";
   private static Scheduler SCHEDULER;
@@ -160,24 +160,23 @@ public class CaosDBServer extends Application {
    * Parse the command line arguments.
    *
    * <ul>
-   *   <li>"nobackend": flag to run caosdb without any backend (for testing purposes)
-   *   <li>"insecure": flag to start only a http server (no https server)
+   *   <li>"--no-backend": flag to run caosdb without any backend (for testing purposes)
+   *   <li>"--no-tls": flag to start only a http server (no https server)
    * </ul>
    *
-   * <p>Both flags are only available in the debug mode which is controlled by the `caosdb.debug`
-   * JVM Property.
+   * <p>The --no-backend flag is only available in the debug mode which is controlled by the
+   * `caosdb.debug` JVM Property.
    *
    * @param args
    */
   private static void parseArguments(final String[] args) {
     for (final String s : args) {
-      if (s.equals("nobackend")) {
+      if (s.equals("--no-backend")) {
         START_BACKEND = false;
-      } else if (s.equals("insecure")) {
-        INSECURE = true;
+      } else if (s.equals("--no-tls")) {
+        NO_TLS = true;
       }
     }
-    INSECURE = INSECURE && isDebugMode(); // only allow insecure in debug mode
     START_BACKEND = START_BACKEND || !isDebugMode(); // always start backend if not in debug mode
   }
 
@@ -347,7 +346,7 @@ public class CaosDBServer extends Application {
     final int maxTotalConnections =
         Integer.parseInt(getServerProperty(ServerProperties.KEY_MAX_CONNECTIONS));
 
-    if (INSECURE) {
+    if (NO_TLS) {
       runHTTPServer(port_http, initialConnections, maxTotalConnections);
     } else {
       runHTTPSServer(
-- 
GitLab