From 6920075c845896e518ba27999ee4ef5587fbc7bb Mon Sep 17 00:00:00 2001 From: kslex <68408844+kslex@users.noreply.github.com> Date: Wed, 2 Apr 2025 15:01:56 +0800 Subject: [PATCH 1/4] fix null SSLSocket (#2206) --- .../com/clickhouse/jdbc/internal/JdbcConfiguration.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java index f2817ef0a..93a21c6c3 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java @@ -57,11 +57,7 @@ public JdbcConfiguration(String url, Properties info) throws SQLException { initProperties(urlProperties, info); // after initializing all properties - set final connection URL - boolean useSSL = Boolean.parseBoolean(info.getProperty(DriverProperties.SECURE_CONNECTION.getKey(), "false")); - String bearerToken = info.getProperty(ClientConfigProperties.BEARERTOKEN_AUTH.getKey(), null); - if (bearerToken != null) { - clientProperties.put(ClientConfigProperties.BEARERTOKEN_AUTH.getKey(), bearerToken); - } + boolean useSSL = Boolean.parseBoolean(clientProperties.getOrDefault(DriverProperties.SECURE_CONNECTION.getKey(), "false")); this.connectionUrl = createConnectionURL(tmpConnectionUrl, useSSL); this.isIgnoreUnsupportedRequests= Boolean.parseBoolean(getDriverProperty(DriverProperties.IGNORE_UNSUPPORTED_VALUES.getKey(), "false")); } From abbd25edac9160a3799423198de0ba374f361f8c Mon Sep 17 00:00:00 2001 From: kslex <68408844+kslex@users.noreply.github.com> Date: Thu, 10 Apr 2025 17:38:15 +0800 Subject: [PATCH 2/4] add JdbcConfiguration test case --- .../jdbc/internal/JdbcConfigurationTest.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java index 293d9d091..9eed81c48 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java @@ -7,11 +7,8 @@ import java.sql.DriverPropertyInfo; import java.util.Arrays; -import java.util.Collections; import java.util.Map; import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; import static org.testng.Assert.assertEquals; @@ -27,27 +24,31 @@ public void testConnectionUrl(String jdbcUrl, String connectionUrl, Properties p @DataProvider(name = "testConnectionUrlDataProvider") public static Object[][] testConnectionUrlDataProvider() { + Properties emptyProps = new Properties(); Properties defaultProps = new Properties(); defaultProps.setProperty(ClientConfigProperties.USER.getKey(), "default"); defaultProps.setProperty(ClientConfigProperties.PASSWORD.getKey(), ""); Properties useSSL = new Properties(); useSSL.put(JdbcConfiguration.USE_SSL_PROP, "true"); + Properties bearerToken = new Properties(); + bearerToken.put(ClientConfigProperties.BEARERTOKEN_AUTH.getKey(), "jwtToken"); Map defaultParams = Map.of( "user", "default", "password", ""); Map simpleParams = Map.of( "database", "clickhouse", "param1", "value1", "param2", "value2", "user", "default", "password", ""); - Map useSSLParams = Map.of("ssl", "true"); + Map useSSLParams = Map.of("database", "clickhouse", "ssl", "true"); + Map bearerTokenParams = Map.of("database", "clickhouse", "bearer_token", "jwtToken"); Map withListParams = Map.of("database", "default", "param1", "value1", "custom_header1", "val1,val2,val3", "user", "default", "password", ""); Map withListParamsQuotes = Map.of("database", "default", "param1", "value1", "custom_header1", "\"role 1,3,4\",'val2',val3", "user", "default", "password", ""); - return new Object[][] { {"jdbc:clickhouse://localhost:8123/", "http://localhost:8123", defaultProps, defaultParams}, {"jdbc:clickhouse://localhost:8443/clickhouse?param1=value1¶m2=value2", "http://localhost:8443", defaultProps, simpleParams}, {"jdbc:clickhouse:https://localhost:8123/clickhouse?param1=value1¶m2=value2", "https://localhost:8123", defaultProps, simpleParams}, - {"jdbc:clickhouse://localhost:8443/", "https://localhost:8443", useSSL, useSSLParams}, + {"jdbc:clickhouse://localhost:8443/clickhouse", "https://localhost:8443", useSSL, useSSLParams}, + {"jdbc:clickhouse://localhost:8443/clickhouse?ssl=true", "https://localhost:8443", emptyProps, useSSLParams}, + {"jdbc:clickhouse://localhost:8443/clickhouse", "http://localhost:8443", bearerToken, bearerTokenParams}, {"jdbc:clickhouse://localhost:8443/default?param1=value1&custom_header1=val1,val2,val3", "http://localhost:8443", defaultProps, withListParams}, {"jdbc:clickhouse://localhost:8443/default?custom_header1=\"role 1,3,4\",'val2',val3¶m1=value1", "http://localhost:8443", defaultProps, withListParamsQuotes}, - }; } From a372769531de6a69e16e540e1af91f1c58ceb1ee Mon Sep 17 00:00:00 2001 From: Mark Zitnik Date: Thu, 10 Apr 2025 15:17:43 +0300 Subject: [PATCH 3/4] Update JdbcConfiguration.java --- .../java/com/clickhouse/jdbc/internal/JdbcConfiguration.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java index 0f9ea5a02..03126071b 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java @@ -62,6 +62,11 @@ public JdbcConfiguration(String url, Properties info) throws SQLException { // after initializing all properties - set final connection URL boolean useSSL = Boolean.parseBoolean(clientProperties.getOrDefault(DriverProperties.SECURE_CONNECTION.getKey(), "false")); + String bearerToken = info.getProperty(ClientConfigProperties.BEARERTOKEN_AUTH.getKey(), null); + if (bearerToken != null) { + clientProperties.put(ClientConfigProperties.BEARERTOKEN_AUTH.getKey(), bearerToken); + } + this.connectionUrl = createConnectionURL(tmpConnectionUrl, useSSL); this.isIgnoreUnsupportedRequests= Boolean.parseBoolean(getDriverProperty(DriverProperties.IGNORE_UNSUPPORTED_VALUES.getKey(), "false")); } From aa15d8945299abd3c5cb6ee0c455b3e1736085e3 Mon Sep 17 00:00:00 2001 From: Mark Zitnik Date: Thu, 10 Apr 2025 15:30:59 +0300 Subject: [PATCH 4/4] Update JdbcConfiguration.java --- .../java/com/clickhouse/jdbc/internal/JdbcConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java index 03126071b..024774f0c 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java @@ -61,7 +61,7 @@ public JdbcConfiguration(String url, Properties info) throws SQLException { initProperties(urlProperties, info); // after initializing all properties - set final connection URL - boolean useSSL = Boolean.parseBoolean(clientProperties.getOrDefault(DriverProperties.SECURE_CONNECTION.getKey(), "false")); + boolean useSSL = Boolean.parseBoolean(info.getProperty(DriverProperties.SECURE_CONNECTION.getKey(), "false")); String bearerToken = info.getProperty(ClientConfigProperties.BEARERTOKEN_AUTH.getKey(), null); if (bearerToken != null) { clientProperties.put(ClientConfigProperties.BEARERTOKEN_AUTH.getKey(), bearerToken);