【Azure Spring Cloud】Azure Spring Cloud connect to SQL using MSI
问题描述
在Azure Spring Cloud中,通过ActiveDirectoryMSI方式来连接到SQL Service,需要如何配置呢?
问题分析
在SQL Service中启用Active Directory MSI认证方式,需要执行两个步骤:
1)在Auzre Spring Cloud App中分配一个Managed Identity。

2)在SQL Service中,使用CREATE USER 命令创建一个Contained User,并且与第一步中的Managed Identity关联。
- 创建映射到 Azure AD 标识的包含的用户:https://docs.microsoft.com/zh-cn/azure/azure-sql/database/authentication-aad-configure?tabs=azure-powershell&view=azuresql#create-contained-users-mapped-to-azure-ad-identities
- CREATE USER [<Azure_AD_principal_name>] FROM EXTERNAL PROVIDER;
完成以上配置后,使用JDBC + ActiveDirectoryMSI的示例代码为:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; public class AAD_MSI {
public static void main(String[] args) throws Exception { SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName("aad-managed-demo.database.chinacloudapi.cn"); // Replace with your server name
ds.setDatabaseName("demo"); // Replace with your database name
ds.setAuthentication("ActiveDirectoryMSI");
// Optional
ds.setMSIClientId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); // Replace with Client ID of User-Assigned Managed Identity to be used try (Connection connection = ds.getConnection();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT SUSER_SNAME()")) {
if (rs.next()) {
System.out.println("You have successfully logged on as: " + rs.getString(1));
}
}
}
}
或者使用SQLServerDataSource.setURL()来设置SQL的连接字符串
SQLServerDataSource.setURL(): Sets the URL that is used to connect to the data source.
=================================================================================================================
jdbc:sqlserver://aad-managed-demo.database.chinacloudapi.cn:1433;
database=hsp-sql-database1-dev;
authentication=ActiveDirectoryMSI;
msiClientId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;
encrypt=true;
trustServerCertificate=false;
hostNameInCertificate=*.database.chinacloudapi.cn;
loginTimeout=3000;
=================================================================================================================
参考资料
创建映射到 Azure AD 标识的包含的用户: https://docs.microsoft.com/zh-cn/azure/azure-sql/database/authentication-aad-configure?tabs=azure-powershell&view=azuresql#create-contained-users-mapped-to-azure-ad-identities
Connect using ActiveDirectoryMSI authentication mode:https://docs.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver15#connect-using-activedirectorymsi-authentication-mode
setURL Method (SQLServerDataSource):https://docs.microsoft.com/en-us/sql/connect/jdbc/reference/seturl-method-sqlserverdatasource?view=sql-server-ver15
【Azure Spring Cloud】Azure Spring Cloud connect to SQL using MSI的更多相关文章
- 【Azure Redis 缓存】Azure Redis 功能性讨论二
继承上一次讨论了Azure Redis的可用性,可靠性,稳定性,安全性,监控方面的九大功能点.详情可回顾文章:[Azure Redis 缓存]Azure Redis功能性讨论 这次我们继续讨论Azur ...
- 【SFA官方译文】:Spring Cloud Data Flow中的ETL
原创: 影宸风洛 SpringForAll社区 昨天 原文链接:https://www.baeldung.com/spring-cloud-data-flow-etl 作者:Norberto Ritz ...
- 【spring】【spring mvc】【spring boot】获取spring cloud项目中所有spring mvc的请求资源
实现的方法: 1.在父级项目中 或者 每个微服务都引用的项目中添加实体类Resource 2.在父级项目中 或者 每个为服务都引用的项目中写一个工具类,作用是用来获取请求资源 3.在每一个微服务的启动 ...
- 【spring boot】15.spring boot项目 采用Druid数据库连接池,并启用druid监控功能
在http://www.cnblogs.com/sxdcgaq8080/p/9039442.html的基础上,来看看spring boot项目中采用Druid连接池. GitHub地址:示例代码 == ...
- 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法
spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...
- 【spring boot】8.spring boot的日志框架logback使用
在继续上一篇的Debug调试之后,把spring boot的日志框架使用情况逐步蚕食. 参考:http://tengj.top/2017/04/05/springbo 开篇之前,贴上完整applica ...
- 【spring boot】12.spring boot对多种不同类型数据库,多数据源配置使用
2天时间,终于把spring boot下配置连接多种不同类型数据库,配置多数据源实现! ======================================================== ...
- 【spring boot】9.spring boot+spring-data-jpa的入门使用,实现数据持久化
spring-data-jpa官方使用说明文档:https://docs.spring.io/spring-data/jpa/docs/current/reference/html/ spring-d ...
- 【Spring Boot】利用 Spring Boot Admin 进行项目监控管理
利用 Spring Boot Admin 进行项目监控管理 一.Spring Boot Admin 是什么 Spring Boot Admin (SBA) 是一个社区开源项目,用于管理和监视 Spri ...
- 【应用服务 App Service】Azure 应用服务测试网络访问其他域名及请求超时限制(4分钟 ≈ 230秒)
测试App Service是否可以访问其他DNS 当应用服务(Azure App Service)创建完成后,想通过ping命令来查看是否可以访问其他站点或解析DNS,但是发现ping命令无法使用.这 ...
随机推荐
- ccs3动画-div向上移动的动画
<head> <meta charset="UTF-8"> <meta name="viewport" content=" ...
- VictoriaMetrics源码阅读:极端吝啬,vm序列化数据到磁盘的细节
作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu 公众号:一本正经的瞎扯 源码请看:https://github.com/ahfuzhang/vi ...
- [3] 以逆向的角度来看循环语句——do、while、for的比较
[3] 以逆向的角度来看循环语句--do.while.for的比较 1. do循环 先执行循环体,后比较判断 #include <stdio.h> int main(int argc, ...
- 蘑菇街大三Java后端暑期实习面经
「Java学习+面试指南」一份涵盖大部分 Java 程序员所需要掌握的核心知识.准备 Java 面试,首选 JavaGuide! 分享一位热心读者分享的实习面经给博客园的小伙伴们看看. 一面 1.自我 ...
- 14.4 Socket 双向数据通信
所谓双向数据传输指的是客户端与服务端之间可以无差异的实现数据交互,此类功能实现的核心原理是通过创建CreateThread()函数多线程分别接收和发送数据包,这样一旦套接字被建立则两者都可以异步发送消 ...
- MySQL8.0清空binlog
环境 centos7.9 mysql Ver 8.0.32 登录MySQL,查看binlog日志 #查看binlog日志开启状态,log_bin值为ON表示开启状态 mysql> show v ...
- vue-cli3创建多页面应用
首先用vue-cli3创建工程,我的全局安装了vue-cli2,又不想卸载掉:所以新建了一个文件夹安装vue-cli3:然后在该文件夹下创建工程: 同时安装vue-cli2和vue-cli3参考:ht ...
- 苹果iOS 17.2年底推送:iPhone 15 Pro的自定义操作按钮功能升级
据报道,苹果会在年底推送iOS 17.2版本,新版系统将会修复iPhone 15系列WiFi速度慢的问题. 与此同时,iOS 17.2将会带来翻译功能,iPhone 15 Pro的自定义操作按钮切换到 ...
- Mygin上下文之sync.Pool复用
sync.Pool 的作用 先看看官方文档怎样说的吧,我截取了官方文档的第一句. // A Pool is a set of temporary objects that may be individ ...
- Centos7部署django+uwsgi+nginx 转载: https://www.cnblogs.com/wztshine/p/16172154.html
Centos7部署django+uwsgi+nginx Django + uwsgi + nginx on Centos7 wsgi 介绍 本小节来自 廖雪峰 wsgi 一文 一个Web应用的本质 ...