Экспонирование bean-компонента JwtDecoder не имеет эффекта - PullRequest
0 голосов
/ 30 сентября 2019

Я хотел бы переименовать заявку JWT, а в документации по безопасности Spring говорится , что , если я перезаписываю бин JwtDecoder по умолчанию, он должен работать.

@Configuration
@EnableResourceServer
public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter {

...

    @Bean
    public JwtDecoder jwtDecoder() {
        NimbusJwtDecoderJwkSupport jwtDecoder = new NimbusJwtDecoderJwkSupport(keySetUri);
        jwtDecoder.setClaimSetConverter(new JwtClaimAdapter());
        return jwtDecoder;
    }

Это всесвязанные с безопасностью Spring артефакты, которые я включил.

        <dependency>
            <groupId>org.springframework.security.oauth.boot</groupId>
            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
            <version>2.1.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-jwt</artifactId>
            <version>1.0.10.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.3.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-jose</artifactId>
        </dependency>

Метод convert класса JwtClaimAdapter даже не вызывается. Что я делаю не так?

ОБНОВЛЕНИЕ 1: я добавил от JwtDecoder до WebSecurityConfigurerAdapter, который упоминается в документе, но он тоже не работает.

@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Value("${security.oauth2.resource.jwk.key-set-uri}")
    private String keySetUri;

    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .oauth2ResourceServer()
                .jwt()
                .decoder(jwtDecoder());
    }

    @Bean
    @Primary
    public JwtDecoder jwtDecoder() {
        NimbusJwtDecoderJwkSupport jwtDecoder = new NimbusJwtDecoderJwkSupport(keySetUri);
        jwtDecoder.setClaimSetConverter(new JwtClaimAdapter());
        return jwtDecoder;
    }

}

ОБНОВЛЕНИЕ 2: Если я добавлю @Order(2) к классу WebSecurityConfigurerAdapter, то все работает нормально. Но почему не работает как в документах?

...