Skip to content

Commit

Permalink
Merge branch 'devel' into fix/cb-4097/set-user-role
Browse files Browse the repository at this point in the history
  • Loading branch information
dariamarutkina authored Nov 1, 2023
2 parents 16e6f48 + 0610759 commit 444611f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/sample-databases/DefaultConfiguration/cloudbeaver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
contentRoot: "web",
driversLocation: "drivers",

sslConfigurationPath:"${CLOUDBEAVER_SSL_CONF_PATH:workspace/.data/ssl-config.xml}",

rootURI: "/",
serviceURI: "/api/",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -554,6 +555,7 @@ protected void parseConfiguration(Map<String, Object> 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);
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

{
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 444611f

Please sign in to comment.