在完成身份验证之前获取 j_username

Get j_username before having authentication completed

我构建了一个在 "springSecurityFilterChain" 之前运行的过滤器,并且此过滤器需要 j_username doFilter 方法。 不幸的是,在成功的身份验证结束之前,不可能使用 Principal 对象并通过 getName() 获取用户名。
有没有其他方法可以在第一个过滤器中获取 j_username

覆盖

 public class ExUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {

 @Override
 public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
          final String username = request.getParameter("j_username");

          // delegate your logic
          return super.attemptAuthentication(request, response); 
  } 
}

在安全配置

<bean id="exUsernamePasswordAuthFilter" class="..." />

<custom-filter ref="exUsernamePasswordAuthFilter" position="FORM_LOGIN_FILTER"/>

http://docs.spring.io/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ns-custom-filters