CORS Origin Spring Boot Jhipster - pre-flight fails

穿精又带淫゛_ 提交于 2019-12-04 10:53:47
hunger

Looks like in the default SecurityConfiguration, its not skipping security check for OPTIONS.

Try adding the following antMatcher to the protected void configure(HttpSecurity http) method in SecurityConfiguration.java

.antMatchers(org.springframework.http.HttpMethod.OPTIONS, "/api/**").permitAll()

sometimes this issue will come if you forget to register cors on specified URLs.In WebConfigurer look for corsFilter and and add these line

 log.debug("Registering CORS filter");
        source.registerCorsConfiguration("/api/**", config);

Another option in the SecurityConfiguration.java. Instead of using antMatcher within the configure(HttpSecurity) override, is to add it within the configure(WebSecurity) override...

public void configure(WebSecurity web) throws Exception {
    web.ignoring()
        .antMatchers(HttpMethod.OPTIONS, "/**")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!