SpringSecurity登录逻辑执行流程概览

46 阅读1分钟

1.[用户发送 POST 请求到 /login]

2.[触发 UsernamePasswordAuthenticationFilter]

3.[构建 UsernamePasswordAuthenticationToken](Authentication的实现类)

4.[调用 AuthenticationManager.authenticate()]

5.[遍历 AuthenticationProvider(如 DaoAuthenticationProvider)]

6.[通过 UserDetailsService 加载用户信息]

7.[使用 PasswordEncoder 验证密码]

8.[认证成功 → 返回 Authentication 对象]

9.[存入 SecurityContextHolder]

10.[触发 SuccessHandler(重定向或返回 JSON)]