SpringBoot2.7.8 SpringBootAdmin 集成 Spring Security(一)
创始人
2025-05-29 10:03:38

核心组件版本

2.7.8
2021.0.5
2021.0.4.0

说明

本文只是一个测试用例,需要 admin client 和 server 都配置同一个账号,才能保证 server 和 client 都需要登录,而且 server 能访问 client 的 actuator/** 地址

SpringBootAdminServer

maven 依赖

spring-boot-admin-server-ui 在 spring-boot-admin-starter-server 中依赖,无需单独引入

org.springframework.bootspring-boot-starter-securityspring-boot-starter-loggingorg.springframework.bootde.codecentricspring-boot-admin-starter-server${spring.boot.version}com.alibaba.cloudspring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-config

properties 配置

nacos 微服务等配置忽略,贴出与 SpringBootAdmin 相关的配置

spring.web.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/assets/
spring.security.user.name=actuator
spring.security.user.password=actuator# spring admin server 下探每个 client actuator 时的账号,包括下探自己的 actuator
spring.boot.admin.instance-auth.enabled=true
spring.boot.admin.instance-auth.default-user-name=${spring.security.user.name}
spring.boot.admin.instance-auth.default-password=${spring.security.user.password}

SecurityConfig

SpringBootAdminServer 中的 SecurityConfig 有些特殊,参考 Securing Spring Boot Admin Server,
springboot2.7.x 已经废弃了 WebSecurityConfigurerAdapter ,方法改写下即可,参考 Spring Security without the WebSecurityConfigurerAdapter

启动 SpringBootAdminServer

账号密码是 actuator/actuator,登录即可

SpringBootAdminClient

maven 依赖

核心包 spring-boot-admin-starter-client

de.codecentricspring-boot-admin-starter-client${spring.boot.version}com.alibaba.cloudspring-cloud-starter-alibaba-nacos-discoverycom.alibaba.cloudspring-cloud-starter-alibaba-nacos-configorg.springframework.bootspring-boot-starter-securityspring-boot-starter-loggingorg.springframework.boot

properties 配置

nacos 微服务等配置忽略,只需要配置 springsecurity 登录账号即可

spring.security.user.name=actuator
spring.security.user.password=actuator

启动SpringBootAdminClient

因为客户端采用 actuator/actuator 登录,而 AdminServer 中配置了下探账号,所以 SpringBootAdminServer中能够访问到 client/actuator/**,能够获取到所有检测数据,同时,客户端正常情况下,需要登录才能访问数据,也不存在数据泄露的问题

相关内容

热门资讯

猫咪吃了塑料袋怎么办 猫咪误食... 你知道吗?塑料袋放久了会长猫哦!要说猫咪对塑料袋的喜爱程度完完全全可以媲美纸箱家里只要一有塑料袋的响...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
阿西吧是什么意思 阿西吧相当于... 即使你没有受到过任何外语培训,你也懂四国语言。汉语:你好英语:Shit韩语:阿西吧(아,씨발! )日...
长白山自助游攻略 吉林长白山游... 昨天介绍了西坡的景点详细请看链接:一个人的旅行,据说能看到长白山天池全凭运气,您的运气如何?今日介绍...