Spring 2+ Sping Security OAuth2是否仍然支持@AuthorizationServer注释?通过阅读发布说明,有些东西还没有被移植:
这是我的build.grade的相关部分
Auth Server
// 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"现在,当我试图将客户端id和客户端秘密作为Oauth2传递给/oauth/token时,我的授权服务器Basic Authentication端点只返回401。传入用户名和密码将提供不同的代码路径。因此,看起来OAuth过滤器没有完全排列起来。
我也发现了这个:弹簧引导2 OAuth2启动器的变化。
是否有配置更新,还是需要一组不同的gradle依赖项才能将授权服务器恢复到以前的状态?
谢谢!
更新
我想结束这个问题的循环。除了加密客户端的机密。RedisTokenStore问题也在Spring2.3.2:弹簧OAuth 2.3.2中得到了解决。
发布于 2018-03-06 18:19:25
Security 5使用现代化的密码存储,请参阅OAuth2自动配置
如果您使用自己的授权服务器配置来通过下面所示的
ClientDetailsServiceConfigurer实例配置有效客户端列表,请注意,您在这里配置的密码受Security 5附带的现代化密码存储的限制。
要解决问题,请参阅弹簧安全参考
Troubleshooting 如“密码存储格式”部分所述,当存储的密码之一没有id时,会发生以下错误。 org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder.matches(DelegatingPasswordEncoder.java:233) at org.springframework.security.crypto.password.DelegatingPasswordEncoder.matches(DelegatingPasswordEncoder.java:196)的id "null“没有映射的PasswordEncoder 解决错误的最简单方法是切换到显式提供密码编码的
PasswordEncoder。解决这个问题的最简单方法是找出您的密码当前是如何存储的,并显式地提供正确的PasswordEncoder。如果要从SpringSecurity4.2.x迁移,可以通过公开NoOpPasswordEncoderbean恢复到以前的行为。例如,如果使用Java配置,则可以创建如下所示的配置: 恢复到NoOpPasswordEncoder并不是安全的。相反,您应该迁移到使用DelegatingPasswordEncoder来支持安全密码编码。 @Bean公共静态NoOpPasswordEncoder passwordEncoder() {返回NoOpPasswordEncoder.getInstance();} 如果使用的是XML配置,则可以使用idPasswordEncoder公开passwordEncoder:
发布于 2018-03-29 10:14:57
OAuth2 AuthorizationServer使用基本身份验证。
因此,您还需要使用delegatedPasswordEncoder在AuthorizationServerConfig中对客户端秘密进行编码,以完全解决“id”"null“异常没有映射的PasswordEncoder。
姚刘的回答解决了我的问题。
( 1)创建了一个自动布线PasswordEncoder;
@Bean
public PasswordEncoder passwordEncoder() {
String idForEncode = "bcrypt";
Map<String, PasswordEncoder> encoderMap = new HashMap<>();
encoderMap.put(idForEncode, new BCryptPasswordEncoder());
return new DelegatingPasswordEncoder(idForEncode, encoderMap);
}2)自动有线passwordEncoder在AuthorizationServerConfig类中;
@Autowired
private PasswordEncoder passwordEncoder;3)用CLIENT_SECRET编码passwordEncoder。
@Override
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception {
configurer
.inMemory()
.withClient(CLIENT_ID)
.secret(passwordEncoder.encode(CLIENT_SECRET))
.authorizedGrantTypes(GRANT_TYPE_FOR_LOGIN, GRANT_TYPE_FOR_REFRESH)
.scopes(SCOPE_READ, SCOPE_WRITE)
.accessTokenValiditySeconds(TOKEN_VALIDITY_SECONDS)
.refreshTokenValiditySeconds(TOKEN_VALIDITY_SECONDS)
.resourceIds(RESOURCES_IDS);
}就这样。
发布于 2018-03-28 06:26:59
正如上面@false_memories所述,使用Spring 2,您需要对您的秘密进行编码。在我的项目中,它看起来是:
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
String secretEncoded = passwordEncoder().encode("secret");
clients.inMemory().withClient("some-web-app").secret(secretEncoded).accessTokenValiditySeconds(expiration)
.scopes("read", "write").authorizedGrantTypes("password", "refresh_token").resourceIds("resource");
}https://stackoverflow.com/questions/49122867
复制相似问题