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为分布式系统中的外部化配置提供了服务器端和客户端支持.有了配置服务器,您就有了一个中心位置来管理跨所有环境的应用程序的外部属性.本文记录实现一个配置中心.客 ...
随机推荐
- vue日常练习一
<html lang="en"> <head> <meta charset="UTF-8"> <title>Ti ...
- C语言学习笔记--指针和数组的关系
1.数组的本质 (1)数组是一段连续的内存空间 (2)数组的空间大小:sizeof(array_type)*array_size; (3)数组名可看做指向数组第一个元素的常量指针 (4)数组声明时编译 ...
- MVC5网站部署到IIS7
server 2008R2+IIS7.5下配置不会出现什么问题,这里记录下在server2008+IIS7下的配置 参考了一下:http://www.cnblogs.com/fcu3dx/p/3773 ...
- springmvc 注解式开发 解决中文乱码问题
- CSS制作水平垂直居中对齐 多种方式各有千秋
作为前端攻城师,在制作Web页面时都有碰到CSS制作水平垂直居中,我想大家都有研究过或者写过,特别的其中的垂直居中,更是让人烦恼.这段时间,我收 集了几种不同的方式制作垂直居中方法,但每种方法各有千秋 ...
- JSON数据格式简介
---------------siwuxie095 JSON 简介 JSON:JavaScript 对象表示法(JavaScript Objec ...
- python http认证
Requests 库有一个auth 模块专门用来处理HTTP 认证: import requestsfrom requests.auth import AuthBasefrom requests.au ...
- 用批处理,批量安装字体文件 (Erector.bat)
@echo off color 0A title 字体安装器 Powered by Cheney_Yang cls xcopy /y "Fonts\*.ttf" "%wi ...
- 激光SLAM Vs 视觉SLAM
博客转载自:https://www.leiphone.com/news/201707/ETupJVkOYdNkuLpz.html 雷锋网(公众号:雷锋网)按:本文作者SLAMTEC(思岚科技公号sla ...
- wpf 窗口打开后默认设置控件焦点
https://blog.csdn.net/Vblegend_2013/article/details/81771872 <Grid FocusManager.FocusedElement=&q ...