springcloud系列六 整合security
一 Eureka注册中心认证:
Eureka自带了一个管理界面,如果不加密,所有人都可以进行访问这个地址,这样安全问题就来了,所以需要对其进行加密认证:
那么该如何进行整合呢:
1 在注册中心模块添加依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2 yml文件配置:
spring:
security:
user:
name: admin
password: admin
3 启动服务再次登录尝试:

之前是谷歌登录,所以换了一个浏览器,需要再登录,
再次启动注册模块,就出现一堆错误:

那么这个问题怎么解决呢:
eureka:
client:
serviceUrl:
defaultZone: http://admin:admin@127.0.0.1:8761/eureka/ #eureka注册中心地址
在注册服务上加上这个,名字,密码就可以了吗?
再启动还是报一堆错误,服务根本注册不进去:

可以看到报错信息:
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
百度查询:

但是好像并没有解决啊:

开启认证了,但是没有禁用CSRF
新版本的spring-cloud2.0中: Spring Security默认开启了CSRF攻击防御
CSRF会将微服务的注册也给过滤了,虽然不会影响注册中心,但是其他客户端是注册不了的
解决方案:
关闭csrf攻击:
package com.cxy.config; import org.springframework.context.annotation.Configuration;
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;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity; /***
* @ClassName: WebSecurityConfig
* @Description:
* @Auther: 陈绪友
* @Date: 2019/1/2820:34
* @version : V1.0
*/
@Configuration public class WebSecurityConfig {
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().httpBasic().and().csrf().disable();
}
}
}

springcloud系列六 整合security的更多相关文章
- springcloud系列九 整合Hystrix Dashboard
Hystrix Dashboard是Hystrix的仪表盘组件,主要用来实时监控Hystrix的各项指标信息,通过界面反馈的信息可以快速发现系统中存在的问题. 整合快速体验: pom.xml(这个是F ...
- springcloud系列八 整合Hystrix
feign本身是支持Hystrix的,所以不需要引入其他依赖: 我们可以看看feign这个项目的依赖,就是引入这个依赖的pom.xml 要想看这个很简单,点击那个依赖进去就可以了 点进去就可以看到 & ...
- SpringCloud系列六:Feign接口转换调用服务(Feign 基本使用、Feign 相关配置)
1.概念:Feign 接口服务 2.具体内容 现在为止所进行的所有的 Rest 服务调用实际上都会出现一个非常尴尬的局面,例如:以如下代码为例: Dept dept = this.restTempla ...
- SpringCloud系列六:Eureka的自我保护模式、IP选择、健康检查
1. 回顾 前面讲了很多Eureka的用法,比如Eureka Server.Eureka Server的高可用.Eureka Server的用户认证(虽然未完全实现).元数据等, 这章将讲解剩下的自我 ...
- springcloud系列11 整合微服务网关zuul
这个模块是一个独立的模块所以需要建立一个模块, 首先引入: 依赖pom.xml <?xml version="1.0" encoding="UTF-8"? ...
- springcloud系列10 整合Hystrix遇到的坑:
首先配置类: @Bean public ServletRegistrationBean getServlet(){ HystrixMetricsStreamServlet streamServlet ...
- springcloud系列七 整合slueth,zipkin 分布式链路调用系统:
首先在代码里面引入依赖: <dependency> <groupId>org.springframework.cloud</groupId> <artifac ...
- SpringCloud系列-整合Hystrix的两种方式
Hystrix [hɪst'rɪks],中文含义是豪猪,因其背上长满棘刺,从而拥有了自我保护的能力.本文所说的Hystrix是Netflix开源的一款容错框架,同样具有自我保护能力. 本文目录 一.H ...
- SpringCloud系列——Config 配置中心
前言 Spring Cloud Config为分布式系统中的外部化配置提供了服务器端和客户端支持.有了配置服务器,您就有了一个中心位置来管理跨所有环境的应用程序的外部属性.本文记录实现一个配置中心.客 ...
随机推荐
- Java8 日期和时间实用技巧
新的日期API ZoneId: 时区ID,用来确定Instant和LocalDateTime互相转换的规则 Instant: 用来表示时间线上的一个点 LocalDate: 表示没有时区的日期, Lo ...
- leetcode665
这道题目,主要是判断相邻的两个值的大小,并按照要求的方式,将数组的数值都修正为符合要求的值. 然后通过一次的遍历,计算所累积的移动次数. bool checkPossibility(vector< ...
- Python的安装以及路径的设置(python的下载地址:www.python.org)
在有的Python版本中在安装时,我们的可以再安装时选择Python路径的自动配备 在选择python的安装程序的时候,我们尽量选择python的2.版本,因为随着Python的更新,Python的数 ...
- Android排错: has leaked window com.android.internal.policy.impl.PhoneWindow$ that was originally added here
异常场景: 经常在应用中需要处理一些耗时的工作,诸如读取大文件.访问网络资源等.为了避免因程序假死而带来的糟糕用户体验,通常我们可以通过线程+Handler或者Android提供的AsyncTask来 ...
- jQuery获取多种值的方法
**jQuery 1.3.2版本下的 jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关设置** 1.判断是否已经打 ...
- 去除Activity上面的标题边框
实现方法:1.在代码中实现:在此方法setContentView(R.layout.main)之前加入:requestWindowFeature(Window.FEATURE_NO_TITLE);标题 ...
- 关于static的继承问题
今天研究了一下被static修饰的变量和方法,在子类中继承的问题,网上也看了别人的博客,自己也动手试了一下 代码如下 //父类 package com.xujingyang.test; public ...
- Python中for else注意事项
假设有如下代码: for i in range(10): if i == 5: print 'found it! i = %s' % i else: print 'not found it ...' ...
- 【转】phpize学习
为什么使用phpize? 比如刚开始安装的时候使用 ./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindi ...
- 36-图像有用区(dfs, bfs)
http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=92 图像有用区域 时间限制:3000 ms | 内存限制:65535 KB 难度:4 ...