【发布时间】:2020-10-04 20:47:53
【问题描述】:
我在从2.1.5 升级到Spring boot 2.3.0 时遇到spring-security 的错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.ClassCastException: org.springframework.security.oauth2.jwt.NimbusJwtDecoder cannot be cast to org.springframework.security.oauth2.jwt.NimbusJwtDecoderJwkSupport
我的安全配置是
public class OpenIdSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private OAuth2ResourceServerProperties resourceServerProperties;
@Autowired
private MyJwtValidator myJwtValidator;
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.authorizeRequests().anyRequest().authenticated().and()
.oauth2ResourceServer().jwt().decoder(jwtDecoder())
.jwtAuthenticationConverter(new MyAuthenticationConverter());
}
private JwtDecoder jwtDecoder() {
String issuerUri = this.resourceServerProperties.getJwt().getIssuerUri();
NimbusJwtDecoderJwkSupport jwtDecoder = (NimbusJwtDecoderJwkSupport) JwtDecoders
.fromOidcIssuerLocation(issuerUri);
OAuth2TokenValidator<Jwt> issuer = JwtValidators.createDefaultWithIssuer(issuerUri);
OAuth2TokenValidator<Jwt> myIssuer = new DelegatingOAuth2TokenValidator<>(issuer, myJwtValidator);
jwtDecoder.setJwtValidator(myIssuer);
return jwtDecoder;
}
}
我相信在这两者之间发生了一些变化,但我无法得到它。
任何帮助或想法都会得到重视
谢谢!!
【问题讨论】:
标签: java spring-boot oauth-2.0 jwt spring-security-oauth2