Skip to content

Instantly share code, notes, and snippets.

@PRASANTHRAJENDRAN
Last active September 30, 2022 09:08
Show Gist options
  • Select an option

  • Save PRASANTHRAJENDRAN/aec33b3ed9381ac1290289c74d2052e0 to your computer and use it in GitHub Desktop.

Select an option

Save PRASANTHRAJENDRAN/aec33b3ed9381ac1290289c74d2052e0 to your computer and use it in GitHub Desktop.
Cors issue after upgrading to use Spring Boot 2.4.0 -> java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*"since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOrigin…
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Component
@EnableWebSecurity
public class AppSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//sample configuration
http.antMatcher("/**").authorizeRequests().antMatchers("/**").permitAll().anyRequest().authenticated();
http.cors().and().csrf().disable();
}
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
// This wildcard pattern matches any host from domain.com and url patterns like "https:microservice.division.domain.com/version1/some_endpoint"
registry.addMapping("/**").allowedMethods("*").allowedOriginPatterns("https://*.domain.com");
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment