My goal is to configure Spring Security in the following manner:
- Any routes starting with private should be authenticated via Spring Boot oauth2ResourceServer
- All other routes should be freely accessible
I have tried the code below, but this gives me the issue that it also tries to validate other routes than private.
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and()
.authorizeRequests()
.antMatchers("/private/**").authenticated()
.antMatchers("/**").permitAll()
.and()
.oauth2ResourceServer().jwt();
}
}
My dependencies are:
- org.springframework.boot:spring-boot-starter-oauth2-resource-server:2.6.2
- org.springframework.boot:spring-boot-starter-security:2.6.2
- org.springframework.boot:spring-boot-starter-web:2.6.2
Any ideas?