前面两篇介绍了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. 最长公共子序列(LCS)最长递增子序列(LIS)

    #include<cstring>#include<iostream>#include<stack>#include <algorithm>using ...

  2. jquery中siblings方法配合什么方法一起使用

    siblings() 获得匹配集合中每个元素的同胞,通过选择器进行筛选是可选的.接下来通过本文给大家介绍jQuery siblings()用法实例详解,需要的朋友参考下吧 siblings() 获得匹 ...

  3. java内存模型和垃圾回收(收藏)

    java内存模型: https://www.cnblogs.com/handsomeye/p/5442879.html java垃圾回收 http://www.cnblogs.com/handsome ...

  4. zabbix items

    zabbixversion:3.2.8 在添加zabbix items的时候,注意store value的设置非常实用,有三种选择: As is:d对接受到的结果不做任何处理 Delta(speed ...

  5. Tarjan算法(图论)(转)

    有点烦人的算法 贴个算法解析合辑先:https://blog.csdn.net/hurmishine/article/details/75248876

  6. [Solution] JZOJ3470 最短路

    [Solution] JZOJ3470 最短路 题面 Description 给定一个n个点m条边的有向图,有k个标记点,要求从规定的起点按任意顺序经过所有标记点到达规定的终点,问最短的距离是多少. ...

  7. ajax 删除数据无刷新

    //html页面 <!doctype html><head> <title></title> <meta http-equiv="Con ...

  8. oracle-查询-时间条件查询

    select * from 表名 where date =to_date('时间','yyyy-dd-mm');

  9. django自定义user认证系统

    第一种,彻底推翻django的user认证系统,重新定义我们想要的字段 from django.contrib.auth.models import AbstractBaseUser,Permissi ...

  10. JavaScript笔记基础版

    1.JavaScript数组: 创建数组  var cars = new Array(); 数组的初始化: 1.1 cars[0]="Saab"; cars[1]="Vo ...