From 45c4d3e653f4fda50461f78a39a02011fbef7cf7 Mon Sep 17 00:00:00 2001 From: Serge Rider Date: Fri, 18 Jun 2021 11:54:09 +0300 Subject: [PATCH] CB-1061 Server URL configuration parameter --- .../io.cloudbeaver.server/schema/service.core.graphqls | 2 ++ .../src/io/cloudbeaver/model/WebServerConfig.java | 5 +++++ .../src/io/cloudbeaver/server/CBApplication.java | 10 +++++++--- .../schema/service.admin.graphqls | 1 + .../cloudbeaver/service/admin/AdminServerConfig.java | 10 ++++++++++ .../service/admin/impl/WebServiceAdmin.java | 1 + 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/server/bundles/io.cloudbeaver.server/schema/service.core.graphqls b/server/bundles/io.cloudbeaver.server/schema/service.core.graphqls index 5425bb9bca..04f0bc0b15 100644 --- a/server/bundles/io.cloudbeaver.server/schema/service.core.graphqls +++ b/server/bundles/io.cloudbeaver.server/schema/service.core.graphqls @@ -90,6 +90,8 @@ type ServerConfig { version: String! workspaceId: ID! + serverURL: String! + anonymousAccessEnabled: Boolean authenticationEnabled: Boolean @deprecated supportsCustomConnections: Boolean diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebServerConfig.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebServerConfig.java index b65aae1202..611b731d85 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebServerConfig.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebServerConfig.java @@ -59,6 +59,11 @@ public class WebServerConfig { return DBWorkbench.getPlatform().getWorkspace().getWorkspaceId(); } + @Property + public String getServerURL() { + return CommonUtils.notEmpty(application.getServerURL()); + } + @Property public boolean isAnonymousAccessEnabled() { return application.getAppConfiguration().isAnonymousAccessEnabled(); 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 8860f4fdec..cf1d960f2a 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 @@ -533,6 +533,7 @@ public class CBApplication extends BaseApplicationImpl { public synchronized void finishConfiguration( @NotNull String newServerName, + @NotNull String newServerURL, @NotNull String adminName, @Nullable String adminPassword, @NotNull List authInfoList, @@ -549,7 +550,7 @@ public class CBApplication extends BaseApplicationImpl { // Save runtime configuration log.debug("Saving runtime configuration"); - saveRuntimeConfig(newServerName, sessionExpireTime, appConfig); + saveRuntimeConfig(newServerName, newServerURL, sessionExpireTime, appConfig); // Grant permissions to predefined connections if (isConfigurationMode() && appConfig.isAnonymousAccessEnabled()) { @@ -572,7 +573,7 @@ public class CBApplication extends BaseApplicationImpl { } public synchronized void flushConfiguration() throws DBException { - saveRuntimeConfig(serverName, maxSessionIdleTime, appConfiguration); + saveRuntimeConfig(serverName, serverURL, maxSessionIdleTime, appConfiguration); } @@ -594,7 +595,7 @@ public class CBApplication extends BaseApplicationImpl { } } - private void saveRuntimeConfig(String newServerName, long sessionExpireTime, CBAppConfig appConfig) throws DBException { + private void saveRuntimeConfig(String newServerName, String newServerURL, long sessionExpireTime, CBAppConfig appConfig) throws DBException { File runtimeConfigFile = getRuntimeAppConfigFile(); try (Writer out = new OutputStreamWriter(new FileOutputStream(runtimeConfigFile), StandardCharsets.UTF_8)) { @@ -611,6 +612,9 @@ public class CBApplication extends BaseApplicationImpl { if (!CommonUtils.isEmpty(newServerName)) { JSONUtils.field(json, CBConstants.PARAM_SERVER_NAME, newServerName); } + if (!CommonUtils.isEmpty(newServerURL)) { + JSONUtils.field(json, CBConstants.PARAM_SERVER_URL, newServerURL); + } if (sessionExpireTime > 0) { JSONUtils.field(json, CBConstants.PARAM_SESSION_EXPIRE_PERIOD, sessionExpireTime); } diff --git a/server/bundles/io.cloudbeaver.service.admin/schema/service.admin.graphqls b/server/bundles/io.cloudbeaver.service.admin/schema/service.admin.graphqls index 46b706fe95..468655d8a0 100644 --- a/server/bundles/io.cloudbeaver.service.admin/schema/service.admin.graphqls +++ b/server/bundles/io.cloudbeaver.service.admin/schema/service.admin.graphqls @@ -50,6 +50,7 @@ type AdminPermissionInfo { input ServerConfigInput { serverName: String + serverURL: String adminName: String adminPassword: String diff --git a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/AdminServerConfig.java b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/AdminServerConfig.java index db231e48ce..8a4888727a 100644 --- a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/AdminServerConfig.java +++ b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/AdminServerConfig.java @@ -30,6 +30,7 @@ import java.util.Map; public class AdminServerConfig { private String serverName; + private String serverURL; private String adminName; private String adminPassword; @@ -44,6 +45,7 @@ public class AdminServerConfig { public AdminServerConfig(Map params) { this.serverName = JSONUtils.getString(params, "serverName"); + this.serverURL = JSONUtils.getString(params, "serverURL"); this.adminName = JSONUtils.getString(params, "adminName"); this.adminPassword = JSONUtils.getString(params, "adminPassword"); @@ -69,6 +71,14 @@ public class AdminServerConfig { this.serverName = serverName; } + public String getServerURL() { + return serverURL; + } + + public void setServerURL(String serverURL) { + this.serverURL = serverURL; + } + public String getAdminName() { return adminName; } diff --git a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java index f2aa4a383e..1f151c7dcf 100644 --- a/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java +++ b/server/bundles/io.cloudbeaver.service.admin/src/io/cloudbeaver/service/admin/impl/WebServiceAdmin.java @@ -419,6 +419,7 @@ public class WebServiceAdmin implements DBWServiceAdmin { CBApplication.getInstance().finishConfiguration( config.getServerName(), + config.getServerURL(), adminName, adminPassword, authInfoList,