Skip to content

Commit 97afdd4

Browse files
committed
Small refactor for bearer token
1 parent 4742671 commit 97afdd4

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ public Builder setOption(String key, String value) {
361361
if (key.equals(ClientConfigProperties.PRODUCT_NAME.getKey())) {
362362
setClientName(value);
363363
}
364+
if (key.equals(ClientConfigProperties.BEARERTOKEN_AUTH.getKey())) {
365+
useBearerTokenAuth(value);
366+
}
364367
return this;
365368
}
366369

client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public enum ClientConfigProperties {
123123
@Deprecated
124124
PRODUCT_NAME("product_name"),
125125

126-
126+
BEARERTOKEN_AUTH ("bearer_token")
127127
;
128128

129129
private String key;

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/DriverProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public enum DriverProperties {
2222
* query settings to be passed along with query operation.
2323
* {@see com.clickhouse.client.api.query.QuerySettings}
2424
*/
25-
DEFAULT_QUERY_SETTINGS("default_query_settings", null);
26-
25+
DEFAULT_QUERY_SETTINGS("default_query_settings", null),
26+
BEARER_TOKEN("jdbc_bearer_token", null);
2727
private final String key;
2828

2929
private final String defaultValue;

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ public JdbcConfiguration(String url, Properties info) throws SQLException {
5757
initProperties(urlProperties, info);
5858

5959
// after initializing all properties - set final connection URL
60-
boolean useSSL = Boolean.parseBoolean(info.getProperty("ssl", "false"));
60+
boolean useSSL = Boolean.parseBoolean(info.getProperty(DriverProperties.SECURE_CONNECTION.getKey(), "false"));
61+
String bearerToken = info.getProperty(DriverProperties.BEARER_TOKEN.getKey(), null);
62+
if (bearerToken != null) {
63+
clientProperties.put(ClientConfigProperties.BEARERTOKEN_AUTH.getKey(), bearerToken);
64+
}
6165
this.connectionUrl = createConnectionURL(tmpConnectionUrl, useSSL);
6266
this.isIgnoreUnsupportedRequests= Boolean.parseBoolean(getDriverProperty(DriverProperties.IGNORE_UNSUPPORTED_VALUES.getKey(), "false"));
6367
}
@@ -240,9 +244,6 @@ public String getDriverProperty(String key, String defaultValue) {
240244
public Client.Builder applyClientProperties(Client.Builder builder) {
241245
builder.addEndpoint(connectionUrl)
242246
.setOptions(clientProperties);
243-
if (clientProperties.containsKey("access_token")) {
244-
builder.useBearerTokenAuth(clientProperties.get("access_token"));
245-
}
246247
return builder;
247248
}
248249

jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ public void testBearerTokenAuth() throws Exception {
504504
"{ \"read_bytes\": \"10\", \"read_rows\": \"1\"}")).build());
505505

506506
Properties properties = new Properties();
507-
properties.put("access_token", jwtToken1);
507+
properties.put(DriverProperties.BEARER_TOKEN.getKey(), jwtToken1);
508508
properties.put("compress", "false");
509509
String jdbcUrl = "jdbc:clickhouse://" + "localhost" + ":" + mockServer.port();
510510
try (Connection conn = new ConnectionImpl(jdbcUrl, properties);

0 commit comments

Comments
 (0)