Connecting to SQL Server resources via Java JDBC using Azure Active Directory - Universal with MFA Support

f45qwnt8  于 2023-08-02  发布在  SQL Server
关注(0)|答案(1)|浏览(119)

I am currently working on a Java project and need to establish a connection to SQL Server resources using Azure Active Directory with Universal authentication that supports Multi-Factor Authentication (MFA). I have been searching for a solution, but haven't found a comprehensive guide for this specific setup.

Could someone please assist me in achieving the required result or provide step-by-step instructions on how to connect to SQL Server resources via Java JDBC using Azure Active Directory - Universal with MFA support? Any code examples, configurations, or best practices would be greatly appreciated. Thank you!

cdmah0mi

cdmah0mi1#

Follow the instructions here: Connect using ActiveDirectoryInteractive authentication mode

The important bit is

SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName("aad-managed-demo.database.windows.net"); // Replace with your server name
ds.setDatabaseName("demo"); // Replace with your database
ds.setAuthentication("ActiveDirectoryInteractive");

// Optional login hint
ds.setUser("bob@cqclinic.onmicrosoft.com"); // Replace with your user name

And

When you run the program, a browser is displayed to authenticate the user.

If you don't want to pop up a browser window, you'll have to use some other auth flow.

相关问题