Spring OAuth2 will intercept the entire url with the header: xxx identity.
To avoid Spring OAuth2 from intercepting URLs. I created a SecurityConfiguration that has a higher order than Spring OAuth2 Configuration.
@Configuration
@EnableWebSecurity
@Order(1)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
List<RequestMatcher> requestMatchers = new ArrayList<RequestMatcher>();
requestMatchers.add(new AntPathRequestMatcher("/api/public/product/**"));
requestMatchers.add(new AntPathRequestMatcher("/api/public/content/**"));
http
.requestMatcher(new OrRequestMatcher(requestMatchers))
.authorizeRequests()
.antMatchers("/api/public/product/**", "/api/public/content/**").permitAll()
}
}
The above configuration allows us to handle this configuration / api / public / product / ** and / api / public / content / **, rather than Spring OAuth2, because this configuration has a higher @Order.
Therefore, even setting an invalid token for a call above api will not result in an invalid access token.
source
share