Как отлаживать класс OAuth2 в Spring Boot? - PullRequest
0 голосов
/ 06 августа 2020

Я тестирую endpoint, разработанный с помощью Spring Boot, который выдает следующую ошибку:

{
  "error": "unauthorized",
  "error_description": "Full authentication is required to access this resource"
}
www-authenticate: Bearer realm="oauth2-resource", error="unauthorized", error_description="Full authentication is required to access this resource" 

Посмотрев здесь , я понял, что это связано с Библиотека OAuth2, я просто не уверен, как ее отлаживать, потому что, когда я добавляю точки останова на OAuth2ResourceServerConfigJwt, код не работает достаточно далеко, чтобы настроить сервер и позволить мне отлаживать с точки, где я отправляю I request через свой конечная точка. Есть идеи, как я могу отладить эту вещь или где проблема может l ie? Вот мой OAuth2ResourceServerConfigJwt класс:

@RequiredArgsConstructor
@Configuration
@EnableResourceServer
public class OAuth2ResourceServerConfigJwt extends ResourceServerConfigurerAdapter {

    private static final String ALGORITHM = "HMACSHA512";

    private final CustomAccessTokenConverter customAccessTokenConverter;

    @Value("${auth.secret}")
    private String secret;

    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setAccessTokenConverter(customAccessTokenConverter);

        SecretKeySpec hs512 = new SecretKeySpec(secret.getBytes(), ALGORITHM);
        converter.setVerifier(new MacSigner(ALGORITHM, hs512));

        converter.setSigningKey(secret);
        return converter;
    }

    @Override
    public void configure(final ResourceServerSecurityConfigurer config) {
        config.tokenServices(tokenServices());
    }

    @Override
    public void configure(final HttpSecurity http) throws Exception {
    // @formatter:off
        http.authorizeRequests()
                .antMatchers(HttpMethod.OPTIONS).permitAll()
                .antMatchers("/testEndpoint/**").authenticated()
                .antMatchers("/**").permitAll().and()
                .authorizeRequests().anyRequest().authenticated();
    // @formatter:on
    }

    @Bean
    @Primary
    public DefaultTokenServices tokenServices() {
        final DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
        defaultTokenServices.setTokenStore(tokenStore());
        return defaultTokenServices;
    }

    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(accessTokenConverter());
    }
...