问题描述
我有一个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 (将#修改为@)