-
Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类

核心验证器
AuthenticationManager
提供了认证方法的入口,接收一个Authentiaton对象作为参数


ProviderManager
AuthenticationManager的一个实现类

提供了基本的认证逻辑和方法
它包含了一个
List<AuthenticationProvider>对象
通过
AuthenticationProvider接口来扩展出不同的认证提供者(当Spring Security默认提供的实现类不能满足需求的时候可以扩展AuthenticationProvider 覆盖supports(Class<?> authentication) 方法)
验证逻辑
AuthenticationManager 接收 Authentication 对象作为参数,并通过 authenticate(Authentication) 方法对其进行验证;AuthenticationProvider实现类用来支撑对 Authentication 对象的验证动作;UsernamePasswordAuthenticationToken实现了 Authentication主要是将用户输入的用户名和密码进行封装,并供给 AuthenticationManager 进行验证;验证完成以后将返回一个认证成功的 Authentication 对象;