0

我正在尝试在自动配置中为以下过滤器创建加载顺序:

@Bean
public FilterRegistrationBean<RequestParamsFilter> requestParamsFilter(){
    FilterRegistrationBean<RequestParamsFilter> registrationBean = new FilterRegistrationBean<>();
    registrationBean.setFilter(new RequestParamsFilter(principle, apiCacheService));
    registrationBean.setOrder(1)
    registrationBean.addUrlPatterns("/*");
    return registrationBean;
}


@Bean
public FilterRegistrationBean<ParamsMarshallerFilter> paramsMarshallerFilter(){
    FilterRegistrationBean<ParamsMarshallerFilter> registrationBean = new FilterRegistrationBean<>();
    registrationBean.setFilter(new ParamsMarshallerFilter(buildProperties, ctx, apiProperties));
    registrationBean.setOrder(2)
    registrationBean.addUrlPatterns("/*");
    return registrationBean;
}

不幸的是,在演示项目中,一旦 SecurityConfig 创建了 SpringSecurityFilterChain,我必须在那里创建加载顺序(像这样):

    httpSecurity.addFilterBefore(paramsMarshallerFilter, UsernamePasswordAuthenticationFilter.class);
    httpSecurity.addFilterAfter(requestParamsFilter, ParamsMarshallerFilter.class);

有没有办法在加载到项目之前在自动配置中设置 SpringSecurityFilterChain 的加载顺序?

注意:我已经尝试过 setOrder 和 @Order 注释(无效);我唯一的其他解决方案是将所有功能都塞进一个过滤器中,以避免排序错误。但我确信 Spring 永远不会破坏 OOP 并强迫我这样做......对吗???:/手指交叉

4

0 回答 0