如何在现有过滤器链之前添加自定义Spring过滤器?

问题描述

我有一个WebSecurityConfigurerAdapter实现类,该类已经具有两个spring安全过滤器

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
    httpSecurity.csrf().disable().authorizeRequests().anyRequest().authenticated().and().
            exceptionHandling().and().sessionManagement().maximumSessions(1);

    httpSecurity.addFilterafter(customAuthenticationFilter,BasicAuthenticationFilter.class);
    httpSecurity.addFilterafter(customAuthorizationFilter,CustomAuthenticationFilter.class);
}

现在,我想在 customAuthorizationFilter 之前(即在现有Spring过滤器链之间)添加一个名为 customEntryFilter 的新自定义过滤器,而无需修改现有的 WebSecurityConfigurerAdapter 实现类。 在Spring Security中如何做到这一点?

预期的过滤器订单

customAuthenticationFilter
customEntryFilter
customAuthorizationFilter

我尝试通过扩展 OncePerRequestFilter 来创建 customEntryFilter ,但该过滤器最后在过滤器链中执行了

@Component
public class CustomEntryFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request,HttpServletResponse response,FilterChain filterChain) throws servletexception,IOException {
        System.out.println("Going via " + CustomEntryFilter.class.getName());
        filterChain.doFilter(request,response);
    }
}

如何在不更改WebSecurityConfigurerAdapterConfiguration类的情况下使此筛选器在开始时执行? 请帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...