1. 前言
我们介绍了UsernamePasswordAuthenticationFilter
的工作流程,留下了一个小小的伏笔,作为一个Servlet Filter应该存在一个doFilter
实现方法,而它却没有,其实它的父类AbstractAuthenticationProcessingFilter
提供了具体的实现。稍后我们会根据这个实现引出今天的主角AuthenticationManager
,来继续介绍用户的认证过程。
2. AbstractAuthenticationProcessingFilter
我们来看看AbstractAuthenticationProcessingFilter
的核心方法doFilter
的实现:
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
// 先通过请求的uri来判断是否需要认证,比如默认的/login
if (!requiresAuthentication(request, response)) {
chain.doFilter(request, response);
return;
}
if (logger.isDe