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版本

寫在最後

  • 其他的升級步驟還挺順風順水,多看一下官方的文檔即可。


分享到:


相關文章: