Skip to content

Instantly share code, notes, and snippets.

@tombasche
Last active August 11, 2021 15:36
Show Gist options
  • Save tombasche/329a2274d03f08c7515771a9c01250bf to your computer and use it in GitHub Desktop.
Save tombasche/329a2274d03f08c7515771a9c01250bf to your computer and use it in GitHub Desktop.
Spring boot security config to allow preflight requests
import org.springframework.web.cors.CorsUtils
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
@Configuration
class SecurityConfig : WebSecurityConfigurerAdapter() {
override fun configure(http: HttpSecurity) {
http
.authorizeRequests()
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
.anyRequest().authenticated()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment