web.xml中配置过滤器的顺序

定义在web.xml里的过滤器的顺序是非常重要的。不论你实际使用的是哪个过滤器,的顺序应该像下面这样: 
ChannelProcessingFilter,因为它可能需要重定向到其他协议。 
ConcurrentSessionFilter,因为它不使用SecurityContextHolder功能,但是需要更新SessionRegistry 来从主体中放映正在进行的请求。 
SecurityContextPersistenceFilter,这样 SecurityContext可以在web请求的开始阶段通过SecurityContextHolder建立,然后SecurityContext的任何修改都会在web请求结束的时候(为下一个web请求做准备)复制到HttpSession中。 
验证执行机制 - UsernamePasswordAuthenticationFilter,CasAuthenticationFilter, BasicAuthenticationFilter 等等 - 这样SecurityContextHolder 可以被修改,并包含一个合法的 Authentication请求标志。 
SecurityContextHolderAwareRequestFilter,如果,你使用它,把一个SpringSecurity提醒HttpServletRequestWrapper安装到你的servlet容器里。 
RememberMeAuthenticationFilter,这样如果之前的验证执行机制没有更新SecurityContextHolder,这个请求提供了一个可以使用的remember-me服务的cookie,一个对应的已保存的Authentication对象会被创建出来。 
AnonymousAuthenticationFilter,这样如果之前的验证执行机制没有更新SecurityContextHolder,会创建一个匿名Authentication对象。 
ExceptionTranslationFilter,用来捕捉 SpringSecurity异常,这样,可能返回一个HTTP错误响应,或者执行一个对应的AuthenticationEntryPoint。 
FilterSecurityInterceptor,保护web URI。 
4. 使用其他过滤器 —— 基于框架 
如果你在使用SiteMesh,确认Spring Security过滤器在SiteMesh过滤器之前调用。这可以保证SecurityContextHolder为每个SiteMesh渲染器及时创建。 

你可能感兴趣的:(SpringMvc学习随笔)