В моем загрузочном проекте Spring у меня есть некоторые конечные точки, которые требуют аутентификации, а другие нет. Я использую spring-security-oauth2-autoconfigure
зависимость. Проблема в том, что когда я хочу получить доступ к ресурсу, который не требует аутентификации с недействительным access_token, я получаю ошибку "error": "invalid_token"
. Как я могу предотвратить проверку маркера доступа, если мой метод не защищен?
ResourceServerConfiguration. java
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.headers().frameOptions().disable().and().authorizeRequests().antMatchers("/graphql/**")
.permitAll();
}
}
WebSecurityConfiguration. java
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers(HttpMethod.OPTIONS, "/oauth/token").permitAll()
.anyRequest().authenticated().and().httpBasic().and().csrf().disable();
}
}