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 ...
随机推荐
- W5100S芯片特性
W5100S是一款硬连线TCP / IP嵌入式以太网控制器,可使使用SPI(串行外设接口)和并行系统的嵌入式系统更容易实现互联网连接 W5100S适合需要稳定的Internet Connectivit ...
- idea配置servlet记录,tmocat当服务器,学习
没整理图片,将就看吧, Mac10.11.6 idea2018.1.3 servlet+tmocat9 遇到问题: 端口错误 java.rmi.server.ExportException: Port ...
- 基于OpenCV的图书扫描识别程序开发
1.AndroidStudio环境配置 https://www.cnblogs.com/little-monkey/p/7162340.html
- vue路由跳转到指定页面
1.this.$router.push({name:'Home'}) 2.this.$router.push({path:'/view'}) 3.this.$router.replace({name: ...
- FTP主动模式与被动模式,及java FTPClient模式设置
FTP的主动模式与被动模式 FTP服务器使用20和21两个网络端口与FTP客户端进行通信. FTP服务器的21端口用于传输FTP的控制命令,20端口用于传输文件数据. FTP主动模式: FTP客户端向 ...
- We FALL ASleep At Night, We Do REST Right
We Do Sleep At Night, We Do REST Right 前言 REST 起源 REST 约束 客户端 - 服务端 无状态 缓存 统一接口 分层系统 按需代码 统一接口约束 资源识 ...
- ajax跨域问题小结
跨域:跨域名的访问,是浏览器对ajax的一种限制,这样可以有效的房子跨站攻击 跨域的范畴: 域名不同 或 端口不同 或 二级域名不同 解决方案: 第一种:由于前端基础薄弱,且该方式老掉牙,不讲解: ...
- PHPCMS9.6.0最新版SQL注入和前台GETSHELL漏洞分析 (实验新课)
PHPCMS9.6.0最新版中,由于/modules/attachment/attachments.php的过滤函数的缺陷导致了可以绕过它的过滤机制形成SQL注入漏洞,可导致数据库中数据泄漏. 而且在 ...
- Javascript高级编程学习笔记(5)—— JS操作符
话不多说,开始今天的码字之旅. 突然有种日更小说的感觉,emm... 操作符 ECMAScript(JS核心)描述了一组用于操作数据值的操作符,也包括算术操作符等等 而JS中这些操作符最鲜明的特点就是 ...
- Mybatis框架三:DAO层开发、Mapper动态代理开发
这里是最基本的搭建:http://www.cnblogs.com/xuyiqing/p/8600888.html 接下来做到了简单的增删改查:http://www.cnblogs.com/xuyiqi ...