Skip to content

Instantly share code, notes, and snippets.

@RICH0423
Created January 31, 2018 09:31
Show Gist options
  • Save RICH0423/d027d3e29d03565c87cb8e243c41fa86 to your computer and use it in GitHub Desktop.
Save RICH0423/d027d3e29d03565c87cb8e243c41fa86 to your computer and use it in GitHub Desktop.
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// by default uses a Bean by the name of corsConfigurationSource
.cors().and()
...
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(ImmutableList.of("*"));
configuration.setAllowedMethods(Arrays.asList("HEAD", "GET", "POST", "PUT", "DELETE", "PATCH"));
configuration.setAllowCredentials(true);
configuration.setAllowedHeaders(ImmutableList.of("Authorization", "Cache-Control", "Content-Type"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment