Connecting to Azure SQL with Azure Active Directory Integration

Thanks for documenting this! Would you mind if I re-used your content on the main liquibase.org site? 

Steve Donie
Principal Software Engineer
Liquibase Community Engagement
Datical, Inc. http://www.datical.com/

Not at all. Happy to help contribute!

I posted this on SO, but also wanted to draw attention to the post from this community:

https://stackoverflow.com/questions/60618475/using-liquibase-with-azure-sql-and-azure-active-directory-authentication

I am trying to connect to an Azure SQL database using Azure Active Directory. Specifically, I want to use the ActiveDirectoryPassword authentication mode which is documented here:

https://docs.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver15#connecting-using-activedirectorypassword-authentication-mode

How can I construct my parameters to Liquibase to make this work?

I was able to get this to work. I am not very familiar with Java (we use Liquibase with a C# project), so I think some of the Java pieces tripped me up.

There were a few things I had to do to make this work:

  1. I needed to add some properties to the URL I sent to Liquibase:

–url=“jdbc:sqlserver://REDACTED.database.windows.net;databaseName=REDACTED;authentication=ActiveDirectoryPassword;encrypt=true;trustServerCertificate=true”

ActiveDirectoryPassword is what tells the driver to use the authentication mechanism I wanted. I also had to add encrypt=true and trustServerCertificate=true to avoid some SSL errors I was getting (from:  https://docs.microsoft.com/en-us/sql/connect/jdbc/connecting-with-ssl-encryption?view=sql-server-ver15).

  1. I needed the MSAL4J (Azure Active Directory) libraries in my classpath. I added them to the liquibase/lib directory so that the default Liquibase launcher scripts would add them for me. I got caught on this, too, because I needed to use Maven which we do not use. After downloading Maven, I used the copy-dependencies plugin to download the dependencies I needed.

mvn dependency:copy-dependencies

Here was the simple pom.xml I used:

https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15

Hope that is useful to future people!