1.说明

为了保护配置中心的敏感数据,
需要对Config Server进行安全保护,
本文基于Spring Security方案,
为Config Server增加最简单的Basic安全认证。

2.Config Server添加安全依赖

修改pom.xml,添加spring-boot-starter-security依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

3.Config Server配置用户名密码

修改application.yml,配置用户名密码:

spring:
security:
user:
name: config
password: config123456

4.启动Config Server,测试验证

先只启动Config Server,
通过浏览器的URL访问配置中心,
http://localhost:9009/master/application-dev.yml
首先会跳到登录界面,
要求输入用户名密码:

认证成功后,访问到对应的配置:

5.Config Client配置用户名密码

客户端要访问配置中心,
需要修改bootstrap.yml,
配置上面的用户名密码:

spring:
cloud:
config:
discovery:
enabled: true
service-id: config-server
username: config
password: config123456

上面是通过service-id指定配置中心,
如果使用uri方式指定配置中心,
不仅可以通过username和password配置用户名密码:

spring:
cloud:
config:
uri: http://localhost:9009
username: config
password: config123456

还可以在uri中配置用户名密码:

spring:
cloud:
config:
uri: http://config:config123456@localhost:9009

如果在uri中指定了用户名密码,
又在下面设置username和password,
则以username和password配置的为准:

spring:
cloud:
config:
label: master
name: config-client-demo
profile: test
uri: http://config:configXXX@localhost:9009
username: config
password: config123456

上面的配置中uri的密码错误了,
但是password配置的是正确的,
Config Client仍然能够正确访问配置中心。

最新文章

  1. PCA and kmeans MATLAB实现
  2. JKS TO PEM
  3. Linux学习笔记——切换并取代用户身份命令——su
  4. MatLab计算图像圆度
  5. xcode6制作IOS .a静态库小记
  6. 企业架构研究总结(39)——TOGAF架构能力框架之架构委员会和架构合规性
  7. 使用JavaMail发送带附件的邮件
  8. JS获取元素的宽高以及offsetTop,offsetLeft等的属性值
  9. Docker安装MySQL并配置远程访问
  10. SECCON 2014 CTF:Shuffle
  11. Squid作代理服务器,用户密码验证,高匿代理
  12. DataGrid列表信息保存为EXCEL到指定的路径 ---------继续DataGrid在WPF的数据绑定
  13. [leetcode]Best Time to Buy and Sell Stock II @ Python
  14. Python学习摘录(下)
  15. Oracle EBS PO 接收事务处理查不到对应的数据
  16. UNITY_资源路径与加载外部文件
  17. HDU 4217 Hamming Distance 随机化水过去
  18. ruby中的回调方法和钩子方法
  19. RSA算法笔记+理解
  20. IOS AFN请求 总结

热门文章

  1. rust常用技巧
  2. Flask + Nginx + uwsgi 部署过程
  3. entfrm-boot开发平台一览【entfrm开源模块化无代码开发平台】
  4. redis入门到精通系列(八):redis的高可用--主从复制详解
  5. 【Spring Framework】Spring 入门教程(一)控制反转和依赖注入
  6. 基于war的Spring Boot工程
  7. 【Spring Framework】spring管理自己new的对象
  8. JSP页面的基本结构
  9. python3.6.4 scrapy框架from PIL import Image报错 from . import _imaging as core
  10. [BUUCTF]REVERSE——Youngter-drive