2017-09-14 72 views
0

我的過濾器具有以下配置。在向CORBA請求localhost:8080/oauth/token發出請求時,請求似乎無法完成。CORS過濾器不適用於彈簧oauth /令牌

@Bean 
    public FilterRegistrationBean corsFilter() { 
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 
    CorsConfiguration config = new CorsConfiguration(); 
    config.setAllowCredentials(true); 
    config.addAllowedOrigin("*"); // @Value: http://localhost:8080 
    config.addAllowedHeader("*"); 
    config.addAllowedMethod("*"); 
    source.registerCorsConfiguration("/**", config); 
    FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); 
    bean.setOrder(-1); 
    return bean; 
    } 

@Override 
protected void configure(HttpSecurity http) throws Exception{ 
    http.csrf().disable().authorizeRequests().antMatchers(HttpMethod.OPTIONS, "/oauth/token").permitAll().antMatchers(HttpMethod.OPTIONS, "/**").permitAll(); 
} 

我錯過了我的配置中的東西嗎?

回答

1

問題是與過濾器的順序應該是setlike這樣的:

bean.setOrder(Ordered.HIGHEST_PRECEDENCE);