SpringCloud集成Security安全(Eureka注册中心)
1.说明
为了保护注册中心的服务安全,
避免恶意服务注册到Eureka,
需要对Eureka Server进行安全保护,
本文基于Spring Security方案,
为Eureka Server增加最简单的Basic安全认证。
2.Eureka Server添加安全依赖
修改pom.xml,添加spring-boot-starter-security依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
3.Eureka Server配置用户名密码
修改application.yml,配置用户名密码:
spring:
security:
user:
name: eureka
password: eureka123456
4.Eureka Server,测试验证
先只启动Eureka Server,
通过浏览器的URL访问注册中心,
http://localhost:7001/
首先会跳到登录界面,
要求输入用户名密码:
认证成功后,访问到管理界面:
5.Eureka Server关闭csrf检验
Security默认启用了csrf检验,
CSRF一般指跨站请求伪造攻击,
要在Eureka Server端配置关闭csrf检验,
否则Eureka Client无法访问注册中心,
新建类WebSecurityConfig.java如下:
package com.yuwen.spring.eureka.config;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
super.configure(http);
}
}
6.Eureka Client配置用户名密码
客户端要访问配置中心,
需要修改application.yml,
配置上面的用户名密码:
eureka:
client:
service-url:
defaultZone: http://eureka:eureka123456@localhost:7001/eureka
目前配置文件支持如下格式配置用户名密码:
http://user:password@localhost:7001/eureka,
HTTP基本身份认证将自动添加到Eureka Client。
对于更复杂的需求,
可以创建类型为DiscoveryClientOptionalArgs的@Bean,
并将ClientFilter实例注入其中。
注意由于Eureka的限制,
不可能支持每台服务器的基本身份认证凭证,
因此集群时只使用找到的第一组身份认证凭证。
7.参考文章
Spring cloud eureka 安全认证基本配置
1.3. Authenticating with the Eureka Server
SpringCloud集成Security安全(Eureka注册中心)的更多相关文章
- SpringCloud学习心得之Eureka注册中心的基本使用
SpringCloud学习心得——Eureka注册中心 示范代码链接 定义 SpringCloud Eureka是 SpringCloud Netflix微服务套件的一部分,基于 REST 的服务 ...
- SpringCloud (一)Eureka注册中心搭建
前提 系统安装jdk1.8及以上,配置好maven的ide(这里用idea进行演示,maven版本3.5,配置阿里云源) 项目搭建 新建一个maven项目,创建最简单的那种就好,项目名这里为Eurek ...
- Spring-Cloud(三)Eureka注册中心实现高可用
前言: spring-cloud为基础的微服务架构,所有的微服务都需要注册到注册中心,如果这个注册中心阻塞或者崩了,那么整个系统都无法继续正常提供服务,所以,这里就需要对注册中心进行集群,换言之,高可 ...
- SpringCloud集成Security安全(Config配置中心)
1.说明 为了保护配置中心的敏感数据, 需要对Config Server进行安全保护, 本文基于Spring Security方案, 为Config Server增加最简单的Basic安全认证. 2. ...
- SpringCloud实战之初级入门(一)— eureka注册中心
目录 写在前面 1.资料目录 2.环境介绍 3.eureka注册中心 3.1 创建工程 3.2 启动工程 5.eureka注册中心集群高可用 6.结语 7.一点点重要的事情 写在前面 我在软件行业浸泡 ...
- SpringCloud之Eureka注册中心原理及其搭建
一.Eureka简介 Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡和中间层服务故障转移的目的.SpringCl ...
- SpringCloud的入门学习之深入理解Eureka注册中心
1.Eureka 注册中心三种角色. 答:a.Eureka Server,注册中心,通过 Register.Get.Renew 等接口提供服务的注册和发现. b.Application Service ...
- SpringCloud学习心得—1.2—Eureka注册中心的密码认证、高可用的设置
SpringCloud学习心得—1.2—Eureka注册中心的密码认证.高可用的设置 这是相关代码 链接 Eureka开启密码配置 添加依赖 <dependency> <grou ...
- Spring-cloud微服务实战【二】:eureka注册中心(上)
## 前言 本系列教程旨在为大家演示如何一步一步构建一整套微服务系统,至于其中的数据库用什么,订单ID如何保持唯一,分布式相关问题等等不在我们讨论范围内,本教程为了方便大家后续下载代码运行测试,不 ...
随机推荐
- Output of C++ Program | Set 11
Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 using namespac ...
- OpenStack之十: 安装dashboard
官网地址 https://docs.openstack.org/horizon/stein/install/install-rdo.html #:安装包 [root@cobbler ~]# yum i ...
- Why is the size of an empty class not zero in C++?
Predict the output of the following program? 1 #include<iostream> 2 using namespace std; 3 4 c ...
- mysql 执行报错:Error querying database. Cause: java.sql.SQLSyntaxErrorException:which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
1.这个错误发生在mysql 5.7 版本及以上版本会出现的问题: mysql 5.7版本默认的sql配置是:sql_mode="ONLY_FULL_GROUP_BY",这个配置严 ...
- Shell脚本实现乱序排列文件内容的多种方法(洗牌问题)
洗牌问题:洗一副扑克,有什么好办法?既能洗得均匀,又能洗得快?即相对于一个文件来说怎样高效率的实现乱序排列? ChinaUnix 确实是 Shell 高手云集的地方,只要你想得到的问题,到那里基本上都 ...
- 基于docker 操作mysql5.7
1. 安装好 docker 2. 拉取 mysql5.7 镜像: docker pull mysql:5.7 其他版本 mysql:https://hub.docker.com/_/mysql?tab ...
- 【Services】【Web】【Nginx】静态下载页面的安装与配置
1. 拓扑 F5有自动探活机制,如果一台机器宕机,请求会转发到另外一台,省去了IPVS漂移的麻烦 F5使用轮询算法,向两台服务器转发请求,实现了负载均衡 2. 版本: 2.1 服务器版本:RHEL7. ...
- java 动态代理—— Mybaties 拦截器链基本原理实现
1.摘要 Mybaties 中有个分页插件,之前有特意的去了解了一下原理 :https://www.cnblogs.com/jonrain0625/p/11168247.html,从了解中得知分页插件 ...
- promise ,async 小记
Promise Promise 对象用于表示一个异步操作的最终状态(完成或失败),以及该异步操作的结果值. 摇色子游戏,随机1-6的一个整数,并且将其返回. function fn() { retur ...
- Mysql配置文件 客户端
[client] #默认链接的端口 port=3306 #默认链接的socket的位置 socket=/var/lib/mysql.sock #默认编码格式 default-character-set ...