Spring Cloud Config安全保护 整合Spring Security
生产环境中我们的配置中心肯定是不能随随便便被人访问的,我们可以加上适当的保护机制,由于微服务是构建在Spring Boot之上,所以整合Spring Security是最方便的方式。
1.在springcloud config server项目中添加依赖
<!-- 整合spring security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2.在springcloud config server项目的application.properties 中配置用户名密码:
server:
port: 8089
spring:
application:
name: 06-springcloud-config-server
cloud:
config:
server:
git:
uri: https://github.com/89929665/spring-cloud-config.git
search-paths: config-center
username: xxx@qq.com
password: xxx123456
# 整合 security
security:
user:
name: wjm
password: 123456
3.在springcloud config client上配置用户名和密码:
配置在 bootstrap.properties
server.port=8090
spring.application.name=application
# 通过修改这个来 访问不同的 online test
spring.cloud.config.profile=dev
spring.cloud.config.label=master
spring.cloud.config.uri=http://localhost:8089/
# 在springcloud config client上配置用户名和密码: 整合security
spring.cloud.config.username=wjm
spring.cloud.config.password=123456
4.测试 启动配置中心 客户端
访问服务端 http://localhost:8089/application/dev/master