前面两篇介绍了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安全的更多相关文章

  1. spring cloud config 入门

    简介 Spring cloud config 分为两部分 server client config-server 配置服务端,服务管理配置信息 config-client 客户端,客户端调用serve ...

  2. Spring Cloud Config

    Spring Cloud Config provides server and client-side support for externalized configuration in a dist ...

  3. Spring Cloud官方文档中文版-Spring Cloud Config(上)

    官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign 文中例子我做了一些测试在:http ...

  4. Spring Cloud官方文档中文版-Spring Cloud Config(下)-客户端等

    官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#_serving_alternative_formats 文中例子我做了 ...

  5. SpringCloud的配置管理:Spring Cloud Config

    演示如何使用ConfigServer提供统一的参数配置服务 ###################################################################一.概 ...

  6. 搭建spring cloud config

    很久没更新了,因为不是专职研究spring cloud,因此更新速度得看工作强度大不大,每天能抽出的时间不多,如果更新太慢了,并且有小伙伴看的话,请见谅了. Spring Cloud简介 Spring ...

  7. Spring Cloud Config - RSA简介以及使用RSA加密配置文件

    简介 RSA非对称加密有着非常强大的安全性,HTTPS的SSL加密就是使用这种方法进行HTTPS请求加密传输的.因为RSA算法会涉及Private Key和Public Key分别用来加密和解密,所以 ...

  8. Spring Cloud Config 分布式配置中心使用教程

    一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...

  9. 【spring实战第五版遇到的坑】第14章spring.cloud.config.uri和token配置项无效

    本文使用的Spring Boot版本为:2.1.4.RELEASE Spring Cloud版本为:Greenwich.SR1 按照书上的做法,在application.yml中配置配置服务器的地址和 ...

  10. .NET Core微服务之基于Steeltoe使用Spring Cloud Config统一管理配置

    Tip: 此篇已加入.NET Core微服务基础系列文章索引 =>  Steeltoe目录快速导航: 1. 基于Steeltoe使用Spring Cloud Eureka 2. 基于Steelt ...

随机推荐

  1. django的简单原理

    一.自定义客户端和服务端的请求响应 1.客户端打开url,向服务器发出请求 2.服务端用socket写一个py,用于接收请求和做出响应 3.服务端接收请求 4.服务端模拟HTTP协议做出响应,状态行为 ...

  2. JavaScript:原生模拟$.ajax以及jsonp

    现实项目中,常常会用到请求,但是在考虑低版本的浏览器时,promise相关的axios,fetch这类第三方库的支持率就不那么好了,再考虑到最大的一个问题,跨域,更是让人头痛,虽然也有fetch-js ...

  3. 在linux中文件的权限讲解

    1.d:directory(目录): 表示这个文件是个目录,其他的还有f(file文件)等等: 2.r:read(可读) 3.w:write(可写) 4 x :execute(可执行) 一般Linux ...

  4. save to project-level dictionary? save to application-level dictionary?

    通过静态代码分析工具lint在Spelling typo得到save to project-level dictionary? save to application-level dictionary ...

  5. 【python-appium】手机一直提示重新安装settings unlock 输入法等 注释掉以下代码

    注释掉目录:C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js this.initUnic ...

  6. Vuejs——(11)组件——slot内容分发

    版权声明:出处http://blog.csdn.net/qq20004604   目录(?)[+]   本篇资料来于官方文档: http://cn.vuejs.org/guide/components ...

  7. 在jenkins中调用maven的变量

    Maven内置变量说明: ${basedir} 项目根目录(即pom.xml文件所在目录) ${project.build.directory} 构建目录,缺省为target目录 ${project. ...

  8. [UWP]使用Picker构建应用内图片公共裁剪组件

    在上一篇博文<[UWP]如何实现UWP平台最佳图片裁剪控件>中我讲解了编写ImageCropper控件的过程及知识分享.在那篇文章里,我大言不惭的称其为UWP平台最佳图片裁剪控件(主要是没 ...

  9. uboot处理dtb

    目录 uboot处理dtb 传递参数给内核 dtb 地址选择 dtb修改 移植fdt title: uboot处理dtb date: 2019/4/28 17:18:19 toc: true --- ...

  10. jsapi微信支付

    JSAPI微信支付 引用js <script type="text/javascript" src="http://res.wx.qq.com/open/js/jw ...