Skip to content

Instantly share code, notes, and snippets.

@luismoramedina
Last active January 22, 2023 14:22
Show Gist options
  • Select an option

  • Save luismoramedina/27f5647fc2067284d3fa9c09f22438fe to your computer and use it in GitHub Desktop.

Select an option

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);
}
}
@niket-lekaria-polestar
Copy link
Copy Markdown

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