前面两篇介绍了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. 20175316盛茂淞 迭代和JDB

    迭代和JDB 题目 1 使用C(n,m)=C(n-1,m-1)+C(n-1,m)公式进行递归编程实现求组合数C(m,n)的功能 2 m,n 要通过命令行传入 3 提交测试运行截图(至少三张:正常如c( ...

  2. OKR 与 KPI

    作者:Cat Chen链接:https://www.zhihu.com/question/22478049/answer/23833548来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业 ...

  3. centos7.2 下 nginx 开机启动

    1.在系统服务目录里创建nginx.service文件 1 vi /lib/systemd/system/nginx.service 内容如下 1 2 3 4 5 6 7 8 9 10 11 12 1 ...

  4. 为opencv添加contrib库

    自从进入3.X时代以后,OpenCV将代码库分成了两部分,分别是稳定的核心功能库和试验性质的contrib库,之前已经讲过opencv的核心库的安装,现在讲解一下其附带的依赖库的安装. 一.Cmake ...

  5. ubuntu16.04下idea、webstorm等开发工具不能输入中文问题

    问题: ubuntu16.04下idea.webstorm开发工具不能输入中文,就算切换到中文输入法输入的也是英文字母. 解决方案: 1.vim打开开发工具的启动文件(idea下就是idea.sh) ...

  6. MySQL--CREATE INDEX在各版本的优化

    在MySQL 5.5版本中引入FIC(Fast index creation)特性,提升索引的创建速度. FCI 操作流程: (1)对表加共享S锁,允许其他会话读操作,但禁止写操作, (2)扫描Clu ...

  7. sql-向已有数据的表添加约束

    语法: alter table 表名 with nocheck add constraint 约束名 约束类型 具体的约束说明 对表中现有的数据不做检查, 只对添加约束后再录入的数据进行检查. 例子: ...

  8. SSD报告 - QRadar远程命令执行

    SSD报告 - QRadar远程命令执行 漏洞摘要 QRadar中的多个漏洞允许远程未经身份验证的攻击者使产品执行任意命令.每个漏洞本身并不像链接那么强大 - 这允许用户从未经身份验证的访问更改为经过 ...

  9. js验证身份证号,超准确

    js验证身份证号,超准确 看程序前先来了解下身份证号的构成:身份证号分为两种,旧的为15位,新的为18位.身份证15位编码规则:dddddd yymmdd xx p    其中 dddddd:地区码  ...

  10. 使用 PLSQL 提示动态执行表不可访问,本会话的自动统计被禁止

    使用PLSQL,第一次执行表的select操作的时候,提示"动态执行表不可访问,本会话的自动统计被禁止",如上图: 这种问题,一看就是当前连接用户没有对sys用户下的表v$sess ...