Spring安全认证 - 有关文档的问题

时间:2011-06-05 15:20:11

标签: java spring spring-mvc spring-security

我在Spring Security JavaDoc中查看此页面:

http://static.springsource.org/spring-security/site/docs/3.1.x/apidocs/org/springframework/security/web/authentication/AbstractAuthenticationProcessingFilter.html#attemptAuthentication(javax.servlet.http.HttpServletRequest,%20javax.servlet.http.HttpServletResponse

这条线是什么意思?

  

返回null,表示   身份验证过程仍在进行中   进展。回来之前,   实施应该执行任何   完成所需的额外工作   这个过程。

我正在处理一个允许用户登录并收集其他数据的表单。我不想使用默认的UsernamePasswordAuthenticationFilter,因为我将丢失表单中填写的所有其他数据。

2 个答案:

答案 0 :(得分:1)

从登录表单中捕获更多数据的常用方法是使用自定义WebAuthenticationDetails。

有关如何执行此操作的信息,请参阅this thread

答案 1 :(得分:0)

  

这条线是什么意思?

这通常意味着如果从覆盖attemptAuthentication()方法返回null,则过滤器链将被破坏,并且在UsernamePasswordAuthenticationFilter之后不会再调用其他过滤器。之后,您负责完成身份验证过程,而不是链中的其他过滤器。

您可以查看AbstractAuthenticationProcessingFilter#doFilter()方法源代码行:201。

换句话说,返回null会花费额外的工作。

如果您只想覆盖attemptAuthentication(),则应该对失败的身份验证抛出AuthenticationException

如果您想从null返回attemptAuthentication(),您还应该覆盖doFilter()并自行处理null结果。