【问题标题】:ClassCastException NimbusJwtDecoder cannot be cast to NimbusJwtDecoderJwkSupportClassCastException NimbusJwtDecoder 无法转换为 NimbusJwtDecoderJwkSupport
【发布时间】: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


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-28
      • 2014-05-30
      • 2017-07-18
      相关资源
      最近更新 更多