一 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();
}
}
}

最新文章

  1. 【Java心得总结五】Java容器上——容器初探
  2. CSS初始化样式
  3. iOS常用设计模式和机制之代理
  4. 【LEETCODE OJ】Clone Graph
  5. .Net知识点总结(一)
  6. js set
  7. jquery $.trim()方法使用介绍
  8. ARM体系的异常中断
  9. C# 内存管理优化畅想(二)---- 巧用堆栈
  10. thinkphp G方法的华丽升级
  11. 创建出多个app
  12. HDU 4946 Area of Mushroom 凸包
  13. 3386/1752: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
  14. 关于access_token过期的解决办法
  15. Python_day1 Learning record
  16. Window通过zip安装并启动mariadb
  17. ExceptionLess使用
  18. kbmMW随机数与强密码
  19. centos7安装zabbix4.2
  20. C#串口传输中文字符

热门文章

  1. 类型:Oracle;问题:oracle 查询表详细信息;结果:oracle查询表信息(索引,外键,列等)
  2. C# 正规表达式
  3. UML在需求分析阶段的应用
  4. Plist文件存储
  5. NSThread 基本使用
  6. Xshell的简单使用
  7. kernel下制作动态logo
  8. springmvc配置式开发下的视图解析器
  9. R: 对向量中的每个元素,检查其是否包含某个“单词”
  10. kindeditor坑