From 1e2eee87d38b04ae6b0ee2e87c7ec266e68ea447 Mon Sep 17 00:00:00 2001 From: Alexander Skoblikov Date: Tue, 2 Jul 2024 19:04:42 +0300 Subject: [PATCH] CB-5138 force use default properties for default database (#2751) * CB-5138 force use default properties for default database * CB-5138 review fix --------- Co-authored-by: Evgenia Bezborodova <139753579+EvgeniaBzzz@users.noreply.github.com> --- .../service/security/db/CBDatabase.java | 17 ++++++++++++++++- .../service/security/db/WebDatabaseConfig.java | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/CBDatabase.java b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/CBDatabase.java index 609d1fe54e..ea1a858221 100644 --- a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/CBDatabase.java +++ b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/CBDatabase.java @@ -127,8 +127,17 @@ public void initialize() throws DBException { LoggingProgressMonitor monitor = new LoggingProgressMonitor(log); + if (isDefaultH2Configuration(databaseConfiguration)) { + //force use default values even if they are explicitly specified + databaseConfiguration.setUser(null); + databaseConfiguration.setPassword(null); + databaseConfiguration.setSchema(null); + } + String dbUser = databaseConfiguration.getUser(); String dbPassword = databaseConfiguration.getPassword(); + String schemaName = databaseConfiguration.getSchema(); + if (CommonUtils.isEmpty(dbUser) && driver.isEmbedded()) { File pwdFile = application.getDataDirectory(true).resolve(DEFAULT_DB_PWD_FILE).toFile(); if (!driver.isAnonymousAccess()) { @@ -191,7 +200,6 @@ public void initialize() throws DBException { DatabaseMetaData metaData = connection.getMetaData(); log.debug("\tConnected to " + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion()); - var schemaName = databaseConfiguration.getSchema(); if (dialect instanceof SQLDialectSchemaController && CommonUtils.isNotEmpty(schemaName)) { var dialectSchemaController = (SQLDialectSchemaController) dialect; var schemaExistQuery = dialectSchemaController.getSchemaExistQuery(schemaName); @@ -578,4 +586,11 @@ public SQLDialect getDialect() { return dialect; } + public static boolean isDefaultH2Configuration(WebDatabaseConfig databaseConfiguration) { + var v1DefaultUrl = "jdbc:h2:/opt/cloudbeaver/workspace/.data/" + V1_DB_NAME; + var v2DefaultUrl = "jdbc:h2:/opt/cloudbeaver/workspace/.data/" + V2_DB_NAME; + return v1DefaultUrl.equals(databaseConfiguration.getUrl()) + || v2DefaultUrl.equals(databaseConfiguration.getUrl()); + } + } diff --git a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/WebDatabaseConfig.java b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/WebDatabaseConfig.java index da58362d03..fb7243462a 100644 --- a/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/WebDatabaseConfig.java +++ b/server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/WebDatabaseConfig.java @@ -84,4 +84,16 @@ public boolean isBackupEnabled() { public String getSchema() { return schema; } + + void setPassword(String password) { + this.password = password; + } + + void setSchema(String schema) { + this.schema = schema; + } + + void setUser(String user) { + this.user = user; + } }