diff --git a/config/sample-databases/DefaultConfiguration/cloudbeaver.conf b/config/sample-databases/DefaultConfiguration/cloudbeaver.conf index 20f0e29bd1..daa718284c 100644 --- a/config/sample-databases/DefaultConfiguration/cloudbeaver.conf +++ b/config/sample-databases/DefaultConfiguration/cloudbeaver.conf @@ -6,6 +6,8 @@ contentRoot: "web", driversLocation: "drivers", + sslConfigurationPath:"${CLOUDBEAVER_SSL_CONF_PATH:workspace/.data/ssl-config.xml}", + rootURI: "/", serviceURI: "/api/", diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java index 90b1b50d0f..41498ed0fa 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java @@ -108,6 +108,7 @@ public static CBApplication getInstance() { protected int serverPort = CBConstants.DEFAULT_SERVER_PORT; private String serverHost = null; private String serverName = null; + private String sslConfigurationPath = null; private String contentRoot = CBConstants.DEFAULT_CONTENT_ROOT; private String rootURI = CBConstants.DEFAULT_ROOT_URI; private String servicesURI = CBConstants.DEFAULT_SERVICES_URI; @@ -554,6 +555,7 @@ protected void parseConfiguration(Map configProps) throws DBExce } serverName = JSONUtils.getString(serverConfig, CBConstants.PARAM_SERVER_NAME, serverName); + sslConfigurationPath = JSONUtils.getString(serverConfig, CBConstants.PARAM_SSL_CONFIGURATION_PATH, sslConfigurationPath); contentRoot = WebAppUtils.getRelativePath( JSONUtils.getString(serverConfig, CBConstants.PARAM_CONTENT_ROOT, contentRoot), homeFolder); rootURI = readRootUri(serverConfig); @@ -1223,4 +1225,13 @@ public String getContainerId() { } return containerId; } + + @Nullable + public Path getSslConfigurationPath() { + if (sslConfigurationPath == null) { + return null; + } + var sslConfiguration = Path.of(sslConfigurationPath); + return sslConfiguration.isAbsolute() ? sslConfiguration : getHomeDirectory().resolve(sslConfiguration); + } } diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBConstants.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBConstants.java index 3364ae53df..bce709d1f6 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBConstants.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBConstants.java @@ -28,6 +28,7 @@ public class CBConstants { public static final String PARAM_SERVER_PORT = "serverPort"; public static final String PARAM_SERVER_HOST = "serverHost"; public static final String PARAM_SERVER_NAME = "serverName"; + public static final String PARAM_SSL_CONFIGURATION_PATH = "sslConfigurationPath"; public static final String PARAM_CONTENT_ROOT = "contentRoot"; public static final String PARAM_SERVER_URL = "serverURL"; public static final String PARAM_ROOT_URI = "rootURI"; diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jetty/CBJettyServer.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jetty/CBJettyServer.java index c3c7f1a257..9b68eff485 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jetty/CBJettyServer.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/jetty/CBJettyServer.java @@ -33,7 +33,9 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletMapping; +import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; +import org.eclipse.jetty.xml.XmlConfiguration; import org.jkiss.code.NotNull; import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.Log; @@ -71,11 +73,25 @@ public void runServer() { JettyServer server; int serverPort = application.getServerPort(); String serverHost = application.getServerHost(); - if (CommonUtils.isEmpty(serverHost)) { - server = new JettyServer(serverPort); + Path sslPath = application.getSslConfigurationPath(); + + boolean sslConfigurationExists = sslPath != null && Files.exists(sslPath); + if (sslConfigurationExists) { + server = new JettyServer(); + XmlConfiguration sslConfiguration = new XmlConfiguration(new PathResource(sslPath)); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + // method sslConfiguration.configure() does not see the context class of the Loader, + // so we have to configure it manually, then return the old classLoader. + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + sslConfiguration.configure(server); + Thread.currentThread().setContextClassLoader(classLoader); } else { - server = new JettyServer( - InetSocketAddress.createUnresolved(serverHost, serverPort)); + if (CommonUtils.isEmpty(serverHost)) { + server = new JettyServer(serverPort); + } else { + server = new JettyServer( + InetSocketAddress.createUnresolved(serverHost, serverPort)); + } } { @@ -112,8 +128,6 @@ public void runServer() { server.setHandler(servletContextHandler); - var serverConnector = new ServerConnector(server); - server.addConnector(serverConnector); JettyWebSocketServletContainerInitializer.configure(servletContextHandler, (context, wsContainer) -> { wsContainer.setIdleTimeout(Duration.ofMinutes(5)); @@ -205,11 +219,14 @@ public int getRefreshCookieAge() { servletContextHandler.setSessionHandler(sessionHandler); } - private static class JettyServer extends Server { + public static class JettyServer extends Server { public JettyServer(int serverPort) { super(serverPort); } + public JettyServer() { + super(); + } public JettyServer(InetSocketAddress addr) { super(addr); }