Spring Security 实战内容:理解AuthenticationManager

本文详细探讨了Spring Security中的AuthenticationManager,包括其在AbstractAuthenticationProcessingFilter中的作用、初始化流程和认证过程。AuthenticationManager负责对用户的未授信凭据进行认证,其管理多个Provider,支持多种认证方式并存。理解这一核心组件对于掌握Spring Security的认证机制至关重要。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值