File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
main/java/tech/ydb/jdbc/settings
test/java/tech/ydb/jdbc/settings Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change 88import java .util .logging .Logger ;
99import java .util .regex .Pattern ;
1010
11+ import tech .ydb .auth .AuthProvider ;
1112import tech .ydb .auth .TokenAuthProvider ;
1213import tech .ydb .auth .iam .CloudAuthHelper ;
1314import tech .ydb .core .auth .StaticCredentials ;
@@ -205,6 +206,9 @@ public GrpcTransportBuilder applyToGrpcTransport(GrpcTransportBuilder builder) t
205206 if (provider instanceof Supplier ) {
206207 Supplier <?> prov = (Supplier <?>) provider ;
207208 builder = builder .withAuthProvider ((rpc ) -> () -> prov .get ().toString ());
209+ } else if (provider instanceof AuthProvider ) {
210+ AuthProvider prov = (AuthProvider ) provider ;
211+ builder = builder .withAuthProvider (prov );
208212 } else if (provider instanceof String ) {
209213 String className = (String ) provider ;
210214 if (!FQCN .matcher (className ).matches ()) {
@@ -226,7 +230,7 @@ public GrpcTransportBuilder applyToGrpcTransport(GrpcTransportBuilder builder) t
226230 | IllegalArgumentException | InvocationTargetException ex ) {
227231 throw new SQLException ("Cannot construct tokenProvider " + className , ex );
228232 }
229- } else {
233+ } else if ( provider != null ) {
230234 throw new SQLException ("Cannot parse tokenProvider " + provider .getClass ().getName ());
231235 }
232236 }
Original file line number Diff line number Diff line change 88import org .junit .jupiter .api .Test ;
99
1010import tech .ydb .auth .AuthIdentity ;
11+ import tech .ydb .auth .AuthProvider ;
1112import tech .ydb .core .grpc .GrpcTransport ;
1213import tech .ydb .core .grpc .GrpcTransportBuilder ;
1314import tech .ydb .jdbc .impl .helper .ExceptionAssert ;
@@ -20,7 +21,18 @@ public class YdbConnectionPropertiesTest {
2021 private static final String YDB_URL = "grpc://localhost/local" ;
2122
2223 @ Test
23- public void tokenProviderObject () throws SQLException {
24+ public void tokenProviderTest () throws SQLException {
25+ Properties props = new Properties ();
26+ props .put ("tokenProvider" , (AuthProvider ) () -> () -> "AUTH_PROVIDER" );
27+ YdbConnectionProperties cp = new YdbConnectionProperties (null , null , props );
28+ GrpcTransportBuilder builder = cp .applyToGrpcTransport (GrpcTransport .forConnectionString (YDB_URL ));
29+ try (AuthIdentity identity = builder .getAuthProvider ().createAuthIdentity (null )) {
30+ Assertions .assertEquals ("AUTH_PROVIDER" , identity .getToken ());
31+ }
32+ }
33+
34+ @ Test
35+ public void tokenProviderSupplierTest () throws SQLException {
2436 Properties props = new Properties ();
2537 props .put ("tokenProvider" , (Supplier <String >) () -> "SUPPLIER" );
2638 YdbConnectionProperties cp = new YdbConnectionProperties (null , null , props );
You can’t perform that action at this time.
0 commit comments