SpringBoot集成SpringSecurity(七)简单分析认证流程

本文详细分析了SpringBoot应用中SpringSecurity的认证流程,从UsernamePasswordAuthenticationFilter的attemptAuthentication方法开始,讨论了认证过程、成功和失败的处理。在认证过程中,AuthenticationManager的ProviderManager调用AuthenticationProvider进行用户验证,包括UserDetailsService的loadUserByUsername方法和密码匹配。认证成功后,通过successfulAuthentication方法将Authentication保存到SecurityContext。认证失败时,unsuccessfulAuthentication方法将异常存储在session中,以便后续处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

认证流程

用户提交后,默认走用户密码认证过滤器UsernamePasswordAuthenticationFilter,其继承了一个抽象的认证过滤器AbstractAuthenticationProcessingFilter。

AbstractAuthenticationProcessingFilter的doFilter方法负责认证流程,其关键过程包括:

  1. UsernamePasswordAuthenticationFilter.attemptAuthentication方法,认证过程。
  2. successfulAuthentication方法,认证成功写入上下文。
  3. unsuccessfulAuthentication方法,认证失败异常处理。

UsernamePasswordAuthenticationFilter.attemptAuthentication方法

一、UsernamePasswordAuthenticationFilter中通过方法attemptAuthentication返回一个Authentication,Authentication的默认实现类是UsernamePasswordAuthenticationToken,此时其isAuthenticated=false表示尚未认证。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值