2017-09-14 77 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);