Last active
February 10, 2021 09:47
-
-
Save ozgursoy/17b12819735080b007b011115c7cf306 to your computer and use it in GitHub Desktop.
Keycloak & Spring Boot Disable CORS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@KeycloakConfiguration | |
class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter { | |
@Bean | |
public FilterRegistrationBean corsFilter() { | |
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | |
CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues(); | |
source.registerCorsConfiguration("/**", config); | |
FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); | |
bean.setOrder(Ordered.HIGHEST_PRECEDENCE); | |
return bean; | |
} | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
super.configure(http); | |
http.addFilter(corsFilter().getFilter())...anyRequest().authenticated() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment