azure - 将 Liquibase 与 Azure SQL 和 Azure Active Directory 身份验证结合使用
问题描述
如何将 Liquibase 与 Azure SQL 数据库和 Azure Active Directory 身份验证一起使用?具体来说,我想使用此处记录的 ActiveDirectoryPassword 身份验证模式进行连接:
我不知道如何调用 Liquibase CLI 来实现这一点。
这可能吗?
解决方案
我能够让它工作。我对 Java 不是很熟悉(我们将 Liquibase 与 C# 项目一起使用),所以我认为一些 Java 部分让我大吃一惊。
为了完成这项工作,我必须做几件事:
- 我需要在发送到 Liquibase 的 URL 中添加一些属性:
--url="jdbc:sqlserver://REDACTED.database.windows.net;databaseName=REDACTED;authentication=ActiveDirectoryPassword;encrypt=true;trustServerCertificate=true"
ActiveDirectoryPassword告诉驱动程序使用我想要的身份验证机制。我还必须添加 encrypt=true 和 trustServerCertificate=true 以避免我遇到的一些 SSL 错误(来自: https ://docs.microsoft.com/en-us/sql/connect/jdbc/connecting-with-ssl-encryption ?view=sql-server-ver15)。
我的类路径中需要 MSAL4J(Azure Active Directory)库。我将它们添加到 liquibase/lib 目录,以便默认的 Liquibase 启动器脚本为我添加它们。我也被抓住了,因为我需要使用我们不使用的 Maven。下载Maven后,我使用copy-dependencies插件下载了我需要的依赖。
mvn 依赖:复制依赖
这是我使用的简单 pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.3</version>
</dependency>
</dependencies>
</project>
我还将这些依赖项放在 liquibase/lib 目录中,以便它们自动包含在类路径中。Microsoft 的说明有助于将我带到正确的位置:
此外,不确定是否需要它来实现我的目标,但我升级到了最新的 Liquibase (3.8.7) 和最新的 SQL Server 驱动程序 (8.2):
推荐阅读
- scheme - 两个子列表的方案函数
- sql - 我可以在嵌套查询中使用 lower 吗?
- go - 如何将变量传递给 Golang 中的另一个函数并在之后将其取回
- vmware - 无 vCenter 的 VMWare ESXi 免费版本 7 升级过程
- javascript - 如何在使用@google-cloud/storage import 时阻止我的程序失败
- c++ - 如何测量从客户端发送数据到服务器所花费的时间
- c# - 运行空间中的 C# Powershell - 如何让“格式列表”工作?
- paypal - PayPal:“企业的电子邮件地址不在加密的 blob 中。请联系您的商家”。怎么修?
- java - Java 8 Streams 从列表中过滤出空字符串 []
? - javascript - 移动优先布局:为什么我的 vanilla JS 使用媒体查询隐藏内容?