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

豹子头
• 阅读 4075

背景

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
// 旧
@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}
 
// 新
@Bean
public 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/1...

RedisTokenStore bug

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

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

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

<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.2.X</version>
</dependency>

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

<!--spring security 、oauth、jwt依赖-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-security</artifactId>
    <exclusions>
        <!--旧版本 redis操作有问题-->
        <exclusion>
            <artifactId>spring-security-oauth2</artifactId>
            <groupId>org.springframework.security.oauth</groupId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.3.3.RELEASE</version>
</dependency>

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踩坑分享

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.0.1</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>
/**
 * @author lengleng
 * @date 2018/6/22
 * 针对监控模块。全部放行
 */
@Configuration
public 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版本

写在最后

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

http://cloud.spring.io/spring...

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
美凌格栋栋酱 美凌格栋栋酱
6个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
Stella981 Stella981
3年前
OAuth2 升级Spring Cloud Finchley.RELEASE踩坑分享
背景6.19号,spring团队发布了期待已久的SpringCloudFinchley.RELEASE版本。重要变化:基于SpringBoot2.0.X不兼容SpringBoot1.5.X期间踩过几个坑,分享出来给大伙,主要是关于SpringCloudoAuth部分目标基于
Wesley13 Wesley13
3年前
VBox 启动虚拟机失败
在Vbox(5.0.8版本)启动Ubuntu的虚拟机时,遇到错误信息:NtCreateFile(\\Device\\VBoxDrvStub)failed:0xc000000034STATUS\_OBJECT\_NAME\_NOT\_FOUND(0retries) (rc101)Makesurethekern
Wesley13 Wesley13
3年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Stella981 Stella981
3年前
Node.js 中使用 ECDSA 签名遇到的坑
文/Fenying最近有个朋友问我关于Node.js下使用ECDSA的问题,主要是使用Node.js的Crypto模块无法校验网络传输过来的签名结果。在踩坑无数后,终于搞清楚了原因。坑0x00:签名输出格式在排除了证书、消息不一致的可能之后,我开始对比使用Node.js签名的结果与网络传输过来的签
Stella981 Stella981
3年前
Spring Boot Admin 2 值得了解的新变化
6.19号,spring团队发布了期待已久的SpringCloudFinchley.RELEASE版本。期间SpringBootAdmin也发布了2.0.1兼容它,我在升级pig到Finchley.RELEASE的同时发现很多有意思的变化整理发出来关于pig:基于SpringCloud、oAut
linbojue linbojue
1年前
超完整的Electron打包签名更新指南,这真是太酷啦!
大家好,我是多喝热水。在踩了数不清的坑之后,终于从0到1完成了一个桌面端应用,但万万没想到,最最痛苦的还不是开发过程,而是开发完成后的打包签名阶段,这真是踩坑踩麻了!!!超完整的Electron打包签名更新指南,这真是太酷啦!ok,踩坑归踩坑,收获也是不小