Spring Boot 2 + Sping Security OAuth2是否仍支持@AuthorizationServer
注释?通过阅读发行说明,还没有移植一些内容:
这是我的相关部分build.grade
:
验证服务器
// security
compile "org.springframework.boot:spring-boot-starter-security:${springBootVersion}"
// oauth
// https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2
compile "org.springframework.security.oauth:spring-security-oauth2:2.2.1.RELEASE"
客户端服务器
// support for Oauth2 user token services not yet migrated into Spring Boot 2.0
compile "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.0.1.BUILD-SNAPSHOT"
而现在我的授权服务器的oauth2端点只返回一个401,当我试图通过一个客户端ID和客户端秘密为Basic Authentication
对/oauth/token
。传递用户名和密码会给出不同的代码路径。因此,看起来OAuth过滤器的排列不完全。
我也发现了这一点:Spring Boot 2 OAuth2入门更改。
是否有配置更新,或者我需要一组不同的gradle依赖项才能将Authorization Server恢复到以前的状态?
谢谢!
更新
我想结束这个问题的循环。除了加密客户端秘密。从Spring OAuth 2.3.2开始,RedisTokenStore问题也已解决:Spring OAuth 2.3.2
Spring Security 5使用现代化的密码存储,请参阅OAuth2 Autoconfig:
如果您使用自己的授权服务器配置通过
ClientDetailsServiceConfigurer
如下所示的实例配置有效客户端列表,请注意,此处配置的密码受Spring Security 5随附的现代化密码存储的约束。
要解决您的问题,请参阅Spring Security Reference:
故障排除
当存储的密码之一没有ID(如“密码存储格式”一节中所述)时,会发生以下错误。
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null" at org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder.matches(DelegatingPasswordEncoder.java:233) at org.springframework.security.crypto.password.DelegatingPasswordEncoder.matches(DelegatingPasswordEncoder.java:196)
解决该错误的最简单方法是切换为显式提供
PasswordEncoder
密码进行编码的方式。解决此问题的最简单方法是弄清楚密码的当前存储方式,并明确提供正确的密码PasswordEncoder
。如果您是从Spring Security 4.2.x迁移的,则可以通过公开一个NoOpPasswordEncoder
bean恢复到以前的行为。例如,如果您使用的是Java配置,则可以创建如下所示的配置:还原为
NoOpPasswordEncoder
不安全。您应该改为使用DelegatingPasswordEncoder
来支持安全密码编码。@Bean public static NoOpPasswordEncoder passwordEncoder() { return NoOpPasswordEncoder.getInstance(); }
如果您使用的是XML配置,则可以公开
PasswordEncoder
带有id的passwordEncoder
:<b:bean id="passwordEncoder"
class="org.springframework.security.crypto.NoOpPasswordEncoder" factory-method="getInstance"/>
或者,您可以为所有密码加上正确的ID前缀,然后继续使用
DelegatingPasswordEncoder
。例如,如果您使用的是BCrypt,则可以从以下方式迁移密码:$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG
至
{bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句