I want to disable CORS completely in spring boot security but all what I have tried doesn't seems to work
I have tried to add custom Filters and injecting it as a bean, also I have tried to disable cors in WebSecurityConfigurerAdapter I have also tried to add the filter in configure HttpSecurity method.
these some links I have already tried:
1: CORS problems with spring boot security.
2: Spring security CORS Filter
my current Code state as such:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private final CustomUserDetailsService customUserDetailsService;
private final AuthConfigProperties authConfigProperties;
public WebSecurityConfig(@Lazy CustomUserDetailsService customUserDetailsService, AuthConfigProperties authConfigProperties) {
this.customUserDetailsService = customUserDetailsService;
this.authConfigProperties = authConfigProperties;
}
@Bean
@Override
public AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManager();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(authConfigProperties.getBcryptRounds());
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.requestMatchers()
.antMatchers("/login", "/logout", "/oauth/authorize")
.and()
.logout()
.deleteCookies("JSESSIONID")
.permitAll()
.and()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.csrf()
.disable();
http.cors().disable();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(customUserDetailsService).passwordEncoder(passwordEncoder());
}
}
when I try to access the authentication server in front-end I get this error message:
Access to fetch at 'http://localhost:8089/oauth/token' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.