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.5.12.RELEASE |

| |

+--------+---------+

|

Spring Boot |

v

+------------------+

| |

| 2.0.3.RELEASE |

| |

+------------------+

+------------------+

| |

| Edgware.SR3 |

| |

+--------+---------+

|

Srping Cloud |

v

+------------------+

| |

| Finchley.RELEASE|

| |

+------------------+

问题总结

PasswordEncoder 变化

直接使用原有代码报错:

passwordencoder mapped for the id null// 旧@Beanpublic PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder();} // 新@Beanpublic PasswordEncoder passwordEncoder() { return PasswordEncoderFactories.createDelegatingPasswordEncoder();}

在 Finchley 版本中, 出于安全性的原因,修改了PasswordEncoder 的生成和使用方法。

在注入bean 的时候不能显示指定PasswordEncoder的实现类,类比旧方法。只能通过工厂类来创建

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

PasswordEncoderFactories.createDelegatingPasswordEncoder();
oAuth2 升级Spring Cloud Finchley.RELEASE踩坑分享

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

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

第一部分为加密方式的特征码,支持的类型如上图,第二部分为密文。

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

附上官方文档介绍:https://spring.io/blog/2017/11/01/spring-security-5-0-0-rc1-released#password-storage-updated

RedisTokenStore bug

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

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

 org.springframework.security.oauth spring-security-oauth2 2.2.X

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

 org.springframework.cloud spring-cloud-starter-security    spring-security-oauth2 org.springframework.security.oauth   org.springframework.security.oauth spring-security-oauth2 2.3.3.RELEASE

Spring Boot Admin 2.0.1

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

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

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

 de.codecentric spring-boot-admin-starter-client 2.0.1 org.springframework.boot spring-boot-starter-security/** * @author lengleng * @date 2018/6/22 * 针对监控模块。全部放行 */@Configurationpublic class SecurityPermitAllConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().anyRequest().permitAll() .and().csrf().disable(); }}

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

写在最后

  • 其他的升级步骤还挺顺风顺水,多看一下官方的文档即可。


分享到:


相關文章: