【发布时间】:2019-06-27 23:02:16
【问题描述】:
外部 OAuth2 提供程序没有公共 JwkUri,所以我也尝试使用以下代码 sn-p 覆盖默认行为:
@EnableWebSecurity
public class DirectlyConfiguredJwkSetUri extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("**/oauth2/code/esia**", "**/code/esia**", "**esia**").permitAll()
.antMatchers("/user").fullyAuthenticated()
.anyRequest().authenticated()
.and()
.csrf().disable()
.cors().disable()
.oauth2Client()
.clientRegistrationRepository(this.clientRegistrationRepository)
.authorizationCodeGrant()
.authorizationRequestResolver(new CustomAuthorizationRequestResolver(
this.clientRegistrationRepository, esiaConfig, signatureUtil, timeUtil))
.accessTokenResponseClient(customAccessTokenResponseClient())
.and().and().oauth2Login().tokenEndpoint().accessTokenResponseClient(customAccessTokenResponseClient())
.and().and().oauth2ResourceServer().jwt();
}
@Bean
JwtDecoder jwtDecoder() {
return new CustomJwtDecoder();
}
}
class CustomJwtDecoder implements JwtDecoder {
@Override
public Jwt decode(String token) throws JwtException {
System.out.println(token);
return null;
}
}
但是 Spring Security 不知何故仍然使用默认实现,我收到以下错误...
[missing_signature_verifier] Failed to find a Signature Verifier for Client Registration: 'esia'. Check to ensure you have configured the JwkSet URI.
另外,我尝试设置自定义 AuthenticationProvider 但 spring 忽略了它。
我想问题是 spring 的 OAuth2LoginConfigurer 方法 init(B http) 调用了 new OidcAuthorizationCodeAuthenticationProvider(accessTokenResponseClient, oidcUserService)
【问题讨论】:
标签: spring spring-security oauth-2.0 spring-security-oauth2