Skip to content

Commit

Permalink
Merge branch 'devel' into CB-3733-close-data-editor-tabs-with-the-mid…
Browse files Browse the repository at this point in the history
…dle-mouse-button
  • Loading branch information
EvgeniaBzzz authored Jul 26, 2024
2 parents 8112d75 + 00aa2eb commit db9ef6c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.WebServerConfiguration;
import io.cloudbeaver.model.session.WebSession;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
Expand All @@ -31,6 +32,7 @@ public interface DBWServiceServerConfigurator extends DBWServiceBinding {
void configureServer(
@NotNull WebApplication application,
@Nullable WebSession session,
@NotNull WebServerConfiguration serverConfiguration,
@NotNull WebAppConfiguration appConfig
) throws DBException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,16 @@ protected void performAutoConfiguration(File configPath) {
log.info("No auto configuration was found. Server must be configured manually");
return;
}
CBServerConfig serverConfig = new CBServerConfig();
serverConfig.setServerName(autoServerName);
serverConfig.setServerURL(autoServerURL);
serverConfig.setMaxSessionIdleTime(getMaxSessionIdleTime());
try {
finishConfiguration(
autoServerName,
autoServerURL,
autoAdminName,
autoAdminPassword,
Collections.emptyList(),
getMaxSessionIdleTime(),
serverConfig,
getAppConfiguration(),
null
);
Expand Down Expand Up @@ -524,12 +526,10 @@ public List<InetAddress> getLocalInetAddresses() {
}

public synchronized void finishConfiguration(
@NotNull String newServerName,
@NotNull String newServerURL,
@NotNull String adminName,
@Nullable String adminPassword,
@NotNull List<AuthInfo> authInfoList,
long sessionExpireTime,
@NotNull CBServerConfig serverConfig,
@NotNull CBAppConfig appConfig,
@Nullable SMCredentialsProvider credentialsProvider
) throws DBException {
Expand All @@ -543,7 +543,7 @@ public synchronized void finishConfiguration(

// Save runtime configuration
log.debug("Saving runtime configuration");
getServerConfigurationController().saveRuntimeConfig(newServerName, newServerURL, sessionExpireTime, appConfig, credentialsProvider);
getServerConfigurationController().saveRuntimeConfig(serverConfig, appConfig, credentialsProvider);

// Grant permissions to predefined connections
if (appConfig.isGrantConnectionsAccessToAnonymousTeam()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import io.cloudbeaver.service.security.db.WebDatabaseConfig;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.utils.CommonUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -58,18 +55,6 @@ public class CBServerConfig implements WebServerConfiguration {
private String staticContent = "";

public String getServerURL() {
if (serverURL == null) {
String hostName = serverHost;
if (CommonUtils.isEmpty(hostName)) {
try {
hostName = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
log.debug("Error resolving localhost address: " + e.getMessage());
hostName = CBApplication.HOST_LOCALHOST;
}
}
serverURL = "http://" + hostName + ":" + serverPort;
}
return serverURL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,28 +332,21 @@ protected GsonBuilder getGsonBuilder() {

protected void saveRuntimeConfig(SMCredentialsProvider credentialsProvider) throws DBException {
saveRuntimeConfig(
serverConfiguration.getServerName(),
serverConfiguration.getServerURL(),
serverConfiguration.getMaxSessionIdleTime(),
serverConfiguration,
appConfiguration,
credentialsProvider
);
}

protected void saveRuntimeConfig(
String newServerName,
String newServerURL,
long sessionExpireTime,
CBAppConfig appConfig,
@NotNull CBServerConfig serverConfig,
@NotNull CBAppConfig appConfig,
SMCredentialsProvider credentialsProvider
) throws DBException {
if (newServerName == null) {
if (serverConfig.getServerName() == null) {
throw new DBException("Invalid server configuration, server name cannot be empty");
}
Map<String, Object> configurationProperties = collectConfigurationProperties(newServerName,
newServerURL,
sessionExpireTime,
appConfig);
Map<String, Object> configurationProperties = collectConfigurationProperties(serverConfig, appConfig);
writeRuntimeConfig(getRuntimeAppConfigPath(), configurationProperties);
}

Expand Down Expand Up @@ -382,18 +375,13 @@ public void updateServerUrl(@NotNull SMCredentialsProvider credentialsProvider,
}

protected Map<String, Object> collectConfigurationProperties(
String newServerName,
String newServerURL,
long sessionExpireTime,
CBAppConfig appConfig
@NotNull CBServerConfig serverConfig,
@NotNull CBAppConfig appConfig
) {
Map<String, Object> rootConfig = new LinkedHashMap<>();
{
var originServerConfig = BaseWebApplication.getServerConfigProps(this.originalConfigurationProperties); // get server properties from original configuration file
var serverConfigProperties = collectServerConfigProperties(newServerName,
newServerURL,
sessionExpireTime,
originServerConfig);
var serverConfigProperties = collectServerConfigProperties(serverConfig, originServerConfig);
rootConfig.put("server", serverConfigProperties);
}
{
Expand Down Expand Up @@ -511,28 +499,26 @@ protected Map<String, Object> collectConfigurationProperties(

@NotNull
protected Map<String, Object> collectServerConfigProperties(
String newServerName,
String newServerURL,
long sessionExpireTime,
@NotNull CBServerConfig serverConfig,
Map<String, Object> originServerConfig
) {
var serverConfigProperties = new LinkedHashMap<String, Object>();
if (!CommonUtils.isEmpty(newServerName)) {
if (!CommonUtils.isEmpty(serverConfig.getServerName())) {
copyConfigValue(originServerConfig,
serverConfigProperties,
CBConstants.PARAM_SERVER_NAME,
newServerName);
serverConfig.getServerName());
}
if (!CommonUtils.isEmpty(newServerURL)) {
if (!CommonUtils.isEmpty(serverConfig.getServerURL())) {
copyConfigValue(
originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_URL, newServerURL);
originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_URL, serverConfig.getServerURL());
}
if (sessionExpireTime > 0) {
if (serverConfig.getMaxSessionIdleTime() > 0) {
copyConfigValue(
originServerConfig,
serverConfigProperties,
CBConstants.PARAM_SESSION_EXPIRE_PERIOD,
sessionExpireTime);
serverConfig.getMaxSessionIdleTime());
}
var productConfigProperties = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Map<String, Object> oldProductRuntimeConfig = JSONUtils.getObject(originServerConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ public CBServerConfigurationControllerEmbedded(@NotNull T serverConfig, @NotNull
@NotNull
@Override
protected Map<String, Object> collectServerConfigProperties(
String newServerName,
String newServerURL,
long sessionExpireTime,
Map<String, Object> originServerConfig
@NotNull CBServerConfig serverConfig,
@NotNull Map<String, Object> originServerConfig
) {
Map<String, Object> serverConfigProperties = super.collectServerConfigProperties(
newServerName, newServerURL, sessionExpireTime, originServerConfig);
Map<String, Object> serverConfigProperties = super.collectServerConfigProperties(serverConfig, originServerConfig);

var databaseConfigProperties = new LinkedHashMap<String, Object>();
Map<String, Object> oldRuntimeDBConfig = JSONUtils.getObject(originServerConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.model.user.WebUser;
import io.cloudbeaver.registry.*;
import io.cloudbeaver.server.CBAppConfig;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBConstants;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.*;
import io.cloudbeaver.service.DBWServiceServerConfigurator;
import io.cloudbeaver.service.admin.*;
import io.cloudbeaver.service.security.SMUtils;
Expand Down Expand Up @@ -528,11 +525,12 @@ public boolean deleteAuthProviderConfiguration(@NotNull WebSession webSession, @
public boolean configureServer(WebSession webSession, Map<String, Object> params) throws DBWebException {
try {
CBAppConfig appConfig = new CBAppConfig(CBApplication.getInstance().getAppConfiguration());
CBServerConfig serverConfig = new CBServerConfig();
serverConfig.setServerName(CBApplication.getInstance().getServerName());
serverConfig.setServerURL(CBApplication.getInstance().getServerURL());
serverConfig.setMaxSessionIdleTime(CBApplication.getInstance().getMaxSessionIdleTime());
String adminName = null;
String adminPassword = null;
String serverName = CBApplication.getInstance().getServerName();
String serverURL = CBApplication.getInstance().getServerURL();
long sessionExpireTime = CBApplication.getInstance().getMaxSessionIdleTime();

if (!params.isEmpty()) { // FE can send an empty configuration
var config = new AdminServerConfig(params);
Expand All @@ -557,9 +555,9 @@ public boolean configureServer(WebSession webSession, Map<String, Object> params

adminName = config.getAdminName();
adminPassword = config.getAdminPassword();
serverName = config.getServerName();
serverURL = config.getServerURL();
sessionExpireTime = config.getSessionExpireTime();
serverConfig.setServerName(config.getServerName());
serverConfig.setServerURL(config.getServerURL());
serverConfig.setMaxSessionIdleTime(config.getSessionExpireTime());
}

if (CommonUtils.isEmpty(adminName)) {
Expand Down Expand Up @@ -588,7 +586,7 @@ public boolean configureServer(WebSession webSession, Map<String, Object> params
// Patch configuration by services
for (DBWServiceServerConfigurator wsc : WebServiceRegistry.getInstance().getWebServices(DBWServiceServerConfigurator.class)) {
try {
wsc.configureServer(CBApplication.getInstance(), webSession, appConfig);
wsc.configureServer(CBApplication.getInstance(), webSession, serverConfig, appConfig);
} catch (Exception e) {
log.warn("Error configuring server by web service " + wsc.getClass().getName(), e);
}
Expand All @@ -597,12 +595,10 @@ public boolean configureServer(WebSession webSession, Map<String, Object> params
boolean configurationMode = CBApplication.getInstance().isConfigurationMode();

CBApplication.getInstance().finishConfiguration(
serverName,
serverURL,
adminName,
adminPassword,
authInfos,
sessionExpireTime,
serverConfig,
appConfig,
webSession
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.model.app.WebServerConfiguration;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.service.DBWServiceServerConfigurator;
import org.jkiss.code.NotNull;
Expand All @@ -38,6 +39,7 @@ public class ReverseProxyConfigurator implements DBWServiceServerConfigurator {
public void configureServer(
@NotNull WebApplication application,
@Nullable WebSession session,
@NotNull WebServerConfiguration serverConfiguration,
@NotNull WebAppConfiguration appConfig
) throws DBException {
}
Expand Down

0 comments on commit db9ef6c

Please sign in to comment.