0
votes

I am trying to connect to SQL server using Active Directory Password authentication mode. But on executing the code I get the Following error:

    [pool-2-thread-1] INFO com.microsoft.aad.adal4j.AuthenticationAuthority 
  - [Correlation ID: 2febb587-963f-462a-9937-98b05d3a3fc8] Instance 
    discovery was successful
    [pool-2-thread-1] ERROR com.microsoft.aad.adal4j.AuthenticationContext - 
    [Correlation ID: 2febb587-963f-462a-9937-98b05d3a3fc8] Execution of 
    class com.microsoft.aad.adal4j.AcquireTokenCallable failed.
    java.lang.ClassCastException: java.util.Collections$SingletonList cannot 
    be cast to java.lang.String
    at com.nimbusds.oauth2.sdk.util.URLUtils.serializeParameters(URLUtils.java:88)
    at com.microsoft.aad.adal4j.AdalTokenRequest.toOAuthRequest(AdalTokenRequest.java:160)
    at com.microsoft.aad.adal4j.AdalTokenRequest.executeOAuthRequestAndProcessResponse(AdalTokenRequest.java:86)
    at com.microsoft.aad.adal4j.AuthenticationContext.acquireTokenCommon(AuthenticationContext.java:930)
at com.microsoft.aad.adal4j.AcquireTokenCallable.execute(AcquireTokenCallable.java:70)
at com.microsoft.aad.adal4j.AcquireTokenCallable.execute(AcquireTokenCallable.java:38)
at com.microsoft.aad.adal4j.AdalCallable.call(AdalCallable.java:47)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: Failed to authenticate the user [email protected] in Active Directory (Authentication=ActiveDirectoryPassword).
at com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken(SQLServerADAL4JUtils.java:57)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getFedAuthToken(SQLServerConnection.java:3853)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.onFedAuthInfo(SQLServerConnection.java:3829)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.processFedAuthInfo(SQLServerConnection.java:3797)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onFedAuthInfo(tdsparser.java:261)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:103)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4545)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3406)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:85)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3370)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7347)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2713)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2261)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1921)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1762)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1077)
at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnectionInternal(SQLServerDataSource.java:1025)
at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnection(SQLServerDataSource.java:69)
at main.AADUserPassword.main(AADUserPassword.java:22)
  Caused by: java.util.concurrent.ExecutionException: 
  com.microsoft.aad.adal4j.AuthenticationException: 
  java.util.Collections$SingletonList cannot be cast to java.lang.String
  at com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken(SQLServerADAL4JUtils.java:55) 
 ... 18 more  Caused by: com.microsoft.aad.adal4j.AuthenticationException: java.util.Collections$SingletonList cannot be cast to java.lang.String
at com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken(SQLServerADAL4JUtils.java:50)
... 18 more

I am not able to figure out, what exactly that exception(cannot cast to java.lang.string) means; also I have given correct username and password. I checked it using sql server management studio and it got connected. Please help. I am in a fix. Any help would be appreciated greatly.

1
You need to paste your code here. - Tony Ju
Please include code that demonstrates where the issue is caused. See stackoverflow.com/help/minimal-reproducible-example for more details. - Philippe Signoret
Thanks for your response guys....that issue is fixe. It was some JAR Problem. Now it gets connected to Azure directory Password Authentication mode using JDBC. - Rik
Hi @Rik, I helped you post this as the answer, you think about to accept it as answer( click on the check mark beside the answer to toggle it from greyed out to filled in.). This can be beneficial to other community members. Thank you. - Leon Yue

1 Answers

1
votes

According comment, the error is solved by himself:

It was some JAR Problem. Now it gets connected to Azure directory Password Authentication mode using JDBC.

I posted this as answer and this can be beneficial to other community members.