0

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.

5
  • 2
    You need to paste your code here. Commented Jul 12, 2019 at 6:08
  • Please include code that demonstrates where the issue is caused. See stackoverflow.com/help/minimal-reproducible-example for more details. Commented Jul 12, 2019 at 12:59
  • Have you referred to learn.microsoft.com/en-us/sql/connect/jdbc/… Commented Jul 15, 2019 at 6:46
  • 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. Commented Jul 15, 2019 at 7:37
  • 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. Commented Jul 25, 2019 at 7:28

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

4 Comments

If anyone wants to know about jars to download for azure directory Password, comment below. Will give you the link.
I would appreciate your input. Using mssql-jdbc version 7.4.1.jre8 and adal4j version 1.6.6
Can you share the list of jars required?
Please share the answer and not be so vague. JAR problem doesn't explain much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.