OAuth2 升级Spring Cloud Finchley.RELEASE踩坑分享

背景

6.19号,spring团队发布了期待已久的 Spring Cloud Finchley.RELEASE 版本。 重要变化:

  • 基于Spring Boot 2.0.X
  • 不兼容 Spring Boot 1.5.X

期间踩过几个坑,分享出来给大伙,主要是关于 Spring Cloud oAuth 部分

目标

基于现有Spring Cloud 脚手架pig开始动手升级。

关于pig:

基于Spring Cloud、oAuth2.0开发基于Vue前后分离的开发平台,支持账号、短信、SSO等多种登录,提供配套视频开发教程。

码云地址:https://gitee.com/log4j/pig

版本变化

1 +------------------+ 2 | | 3 | 1.5.12.RELEASE | 4 | | 5 +--------+---------+ 6 | 7Spring Boot | 8 v 9 10 +------------------+ 11 | | 12 | 2.0.3.RELEASE | 13 | | 14 +------------------+ 15 16 17 18 +------------------+ 19 | | 20 | Edgware.SR3 | 21 | | 22 +--------+---------+ 23 | 24Srping Cloud | 25 v 26 27 +------------------+ 28 | | 29 | Finchley.RELEASE| 30 | | 31 +------------------+ 32

问题总结

PasswordEncoder 变化

直接使用原有代码报错:

1passwordencoder mapped for the id null 2 3 4// 旧 5@Bean 6public PasswordEncoder passwordEncoder() { 7 return new BCryptPasswordEncoder(); 8} 9 10// 新 11@Bean 12public PasswordEncoder passwordEncoder() { 13 return PasswordEncoderFactories.createDelegatingPasswordEncoder(); 14} 15

在 Finchley 版本中, 出于安全性的原因,修改了PasswordEncoder 的生成和使用方法。
在注入bean 的时候不能显示指定PasswordEncoder的实现类,类比旧方法。只能通过工厂类来创建 image

PasswordEncoderFactories.createDelegatingPasswordEncoder();

image 通过传入密码的特征码,动态去获取密码匹配器,这也就意味着保存在同一个库中密码可以使用多种加密方式。

{bcrypt}$2a$10$p0JC.ofpM8RxVTSubkKLDOUloGrQAX.lx/67HwnnyumATT69mwYm2

第一部分为加密方式的特征码,支持的类型如上图,第二部分为密文。 image 附上官方文档介绍:https://spring.io/blog/2017/11/01/spring-security-5-0-0-rc1-released#password-storage-updated

RedisTokenStore bug

当授权Auth-Server 配置token 保存在redis 时,报了下面的错误。

NoSuchMethodError.RedisConnection.set([B[B)V #16

Finchley.RELEASE 依赖的版本为 2.2.X版本。

1<dependency> 2 <groupId>org.springframework.security.oauth</groupId> 3 <artifactId>spring-security-oauth2</artifactId> 4 <version>2.2.X</version> 5</dependency>

升级到 2.3.3版本即可解决Redis操作问题

1<!--spring security 、oauth、jwt依赖--> 2<dependency> 3 <groupId>org.springframework.cloud</groupId> 4 <artifactId>spring-cloud-starter-security</artifactId> 5 <exclusions> 6 <!--旧版本 redis操作有问题--> 7 <exclusion> 8 <artifactId>spring-security-oauth2</artifactId> 9 <groupId>org.springframework.security.oauth</groupId> 10 </exclusion> 11 </exclusions> 12</dependency> 13 14<dependency> 15 <groupId>org.springframework.security.oauth</groupId> 16 <artifactId>spring-security-oauth2</artifactId> 17 <version>2.3.3.RELEASE</version> 18</dependency>

Spring Boot Admin 2.0.1

Spring Boot Admin 监控组件也发布了 兼容Finchley.RELEASE的 2.0.1版本,相较之前版本不同,当前版本需要和_spring security_配合使用 客户端: image image

1<dependency> 2 <groupId>de.codecentric</groupId> 3 <artifactId>spring-boot-admin-starter-client</artifactId> 4 <version>2.0.1</version> 5</dependency> 6<dependency> 7 <groupId>org.springframework.boot</groupId> 8 <artifactId>spring-boot-starter-security</artifactId> 9</dependency> 10 11 12/** 13 * @author lengleng 14 * @date 2018/6/22 15 * 针对监控模块。全部放行 16 */ 17@Configuration 18public class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter { 19 @Override 20 protected void configure(HttpSecurity http) throws Exception { 21 http.authorizeRequests().anyRequest().permitAll() 22 .and().csrf().disable(); 23 } 24}

详细使用我会再分享一篇关于 spring boot admin 2.0.X版本

写在最后

点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Spring Cloud:多环境配置、eureka 安全认证、容器宿主机IP注册

记录一下搭建SpringCloud过程中踩过的一些坑,测试的东西断断续续已经弄了好多了,一直没有时间整理搭建过程,时间啊~时间~Spring版本SpringBoot:2.0.6.RELEASESpringCloud:Finchley.SR2多环境配置切换使用Sp

Groovy防PermOOM与OldOOM心得

作为Groovy重度用户,踩了新版本因为无法unloadclass导致permoom的坑,踩了classLoader.parallelLockMap不断添加新锁导致oldoom的坑。本文的意图就是记录一点埋坑心得。踩坑详情可见:https://my.oschina.net/chenxiaojie/blog/835934(https://my.o

Feign2.0用Apache的Httpclient发送请求并配置连接池

主要是针对SpringCloud新出的版本(CloudFinchley.RC2与Springboot2.0.2.RELEASE),一些新的改动,与在使用中遇见的一些问题,踩过的坑,希望后面的人就不用踩了。服务注入到Eureka需要的MAVEN配置<dependency<groupId

SpringBoot整合升级Spring Security 报错 【The request was rejected because the URL was not normalized】

前言最近LZ给项目框架升级,从Spring1.x升级到Spring2.x,在这里就不多赘述两个版本之间的区别以及升级的原因。关于升级过程中踩的坑,在其他博文中会做比较详细的记录,以便给读者参考,不要掉进同样的坑里。这里我们讨论一个关于URL中包含双斜杠被拦截的问题。发现问题升级框架之后,测试一个功能时,发现报错Htt

SpringBoot整合升级Spring Security 报错 【The request was rejected because the URL was not normalized】

前言最近LZ给项目框架升级,从Spring1.x升级到Spring2.x,在这里就不多赘述两个版本之间的区别以及升级的原因。关于升级过程中踩的坑,在其他博文中会做比较详细的记录,以便给读者参考,不要掉进同样的坑里。这里我们讨论一个关于URL中包含双斜杠被拦截的问题。发现问题升级框架之后,测试一个功能时,发现报错Htt