spring cloud config安全
前面两篇介绍了spring cloud config服务端和客户端的简单配置,本篇介绍如何保护config server及对应config client修改。
保护config server,主要是使用spring security进行最简单的basic安全认证(也可自定义认证方式,这里不做扩展)
配置服务端代码示例:
在pom文件中增加依赖:
<dependency>
<!-- spring security 安全认证 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
配置文件application.yml增加security配置:
security:
basic:
enabled: true #启用基本认证(默认)
user: #配置security用户名密码,默认值为“user”的用户名和随机生成的密码
name: user
password: password123
启动服务,测试一下。请求http://localhost:18083/master/config-server-dev.yml,会发现弹出了security的basic登录验证:
输入上面配置的用户名密码(user/password123),返回配置信息
客户端代码示例:
在pom文件中增加依赖:
<dependency>
<!-- spring security 安全认证 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
修改配置文件bootstrap.yml:
spring:
application:
name: config-client
cloud:
config:
profile: test #对应spring.profiles.active
label: master #分支名。当使用配置服务器是git时,默认是master
# uri: http://localhost:18083 #更改配置服务器的位置,默认地址是http://localhost:8888
uri: http://user:password123@localhost:18083 #配置服务器增加了安全认证,这里需要提供用户名密码
username: user #配置服务器的用户名密码,此配置会覆盖uri中的配置
password: password123
在上面的配置中,可以在uri上加上用户名密码,也可以直接配置spring.cloud.config.username和spring.cloud.config.password,不过后面这种会覆盖uri中的配置(至于为什么要设置这两种配置方式,是因为当spring cloud config与注册中心配合使用时,是没有uri的,所以只能在下面配置username和password)
启动服务,测试一下。请求http://localhost:18084/profile,返回配置信息:
至此,spring cloud config安全配置完成~
spring cloud config安全的更多相关文章
- spring cloud config 入门
简介 Spring cloud config 分为两部分 server client config-server 配置服务端,服务管理配置信息 config-client 客户端,客户端调用serve ...
- Spring Cloud Config
Spring Cloud Config provides server and client-side support for externalized configuration in a dist ...
- Spring Cloud官方文档中文版-Spring Cloud Config(上)
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign 文中例子我做了一些测试在:http ...
- Spring Cloud官方文档中文版-Spring Cloud Config(下)-客户端等
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#_serving_alternative_formats 文中例子我做了 ...
- SpringCloud的配置管理:Spring Cloud Config
演示如何使用ConfigServer提供统一的参数配置服务 ###################################################################一.概 ...
- 搭建spring cloud config
很久没更新了,因为不是专职研究spring cloud,因此更新速度得看工作强度大不大,每天能抽出的时间不多,如果更新太慢了,并且有小伙伴看的话,请见谅了. Spring Cloud简介 Spring ...
- Spring Cloud Config - RSA简介以及使用RSA加密配置文件
简介 RSA非对称加密有着非常强大的安全性,HTTPS的SSL加密就是使用这种方法进行HTTPS请求加密传输的.因为RSA算法会涉及Private Key和Public Key分别用来加密和解密,所以 ...
- Spring Cloud Config 分布式配置中心使用教程
一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...
- 【spring实战第五版遇到的坑】第14章spring.cloud.config.uri和token配置项无效
本文使用的Spring Boot版本为:2.1.4.RELEASE Spring Cloud版本为:Greenwich.SR1 按照书上的做法,在application.yml中配置配置服务器的地址和 ...
- .NET Core微服务之基于Steeltoe使用Spring Cloud Config统一管理配置
Tip: 此篇已加入.NET Core微服务基础系列文章索引 => Steeltoe目录快速导航: 1. 基于Steeltoe使用Spring Cloud Eureka 2. 基于Steelt ...
随机推荐
- MSF内网渗透 扫描模块
端口扫描 auxiliary/scanner/portscan scanner/portscan/ack ACK防火墙扫描 scanner/portscan/ftpbounce FTP ...
- VirtualBox中的快捷键
VirtualBox中的快捷键 VirtualBox中的 Host 键默认是: Right Ctrl 键,意思是键盘上右边那个 “Ctrl”键. Host 键可以点击 Oracle VM Virtua ...
- 几种String对象方法的区别
1.在String对象方法中,发现.slice()方法和.substring()方法的作用几乎相同,都是根据起始索引返回截取得到的字符串.经过查阅资料和实测得到区别: 正常情况下索引都为正值,返回值为 ...
- 消息中间件——kafka
1.1.1 什么是消息中间件 消息中间件利用高效可靠的消息传递机制进行平台无关的数据交流,并基于数据通信来进行分布式系统的集成.通过提供消息传递和消息排队模型,它可以在分布式环境下扩展进程间的通信.对 ...
- 背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件
[源码下载] 背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件 作者:webabcd 介绍背水一战 Windows 10 之 控件(WebVi ...
- linux安装方式
一.rpm包安装方式步骤: 1.找到相应的软件包,比如soft.version.rpm,下载到本机某个目录: 2.打开一个终端,su -成root用户: 3.cd soft.version.rpm所 ...
- POJ 1177Picture 扫描线(若干矩形叠加后周长)
Picture Description A number of rectangular posters, photographs and other pictures of the same sh ...
- Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)
C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Eclipse 中 Debug 时鼠标悬停无法查看变量值
问题描述:Eclipse在Debug模式下,当鼠标移动到某个变量上面时不自动显示该变量对应的值. 解决方法:在Eclipse中点击 Window->Preferences->Java-&g ...
- 彻底理解Java中的基本数据类型转换(自动、强制、提升)
说基本数据类型转换之前,先了解下 Java 中的 8 种基本数据类型,以及它们的占内存的容量大小和表示的范围,如下图所示. 重新温故了下原始数据类型,现在来解释下它们之间的转换关系. 自动类型转换 自 ...