Skip to content

Instantly share code, notes, and snippets.

@luismoramedina
Last active January 22, 2023 14:22
Show Gist options
  • Save luismoramedina/27f5647fc2067284d3fa9c09f22438fe to your computer and use it in GitHub Desktop.
Save luismoramedina/27f5647fc2067284d3fa9c09f22438fe to your computer and use it in GitHub Desktop.
Spring security - Disable security for OPTIONS (CORS)
@Configuration
public class WebSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "**").permitAll()//allow CORS option calls
.anyRequest().authenticated();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
}
@saenai255
Copy link

THANK YOU

@mcbraga72
Copy link

Thank you very much!

@niket-lekaria-polestar
Copy link

Still its not working..(antMatchers deprecated ...so used requestMatchers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment