一、认证处理流程说明
1、认证过程中涉及到的类
2、处理流程
1 、用户密码登录请求 -》 UsernamePasswordAuthenticationFilter 的 attemptAuthentication() 然后组装成一个
(1)Ctrl加鼠标左键点 UsernamePasswordAuthenticationToken 看到该类继承自 AbstractAuthenticationToken
(2)在点AbstractAuthenticationToken能看到实现了Authentication 接口
而 Authentication 是 封装了登录时的认证信息。
(3)UsernamePasswordAuthenticationToken的构造方法,super((Collection)null); 传到父类的权限集合是null,所以this.setAuthenticated(false); 即没有通过身份认证。
(4)其中super((Collection)null); 点进去,可以看到是AbstractAuthenticationToken的构造方法,参数authorities是权限的集合,由于调用的时候不知道权限信息,所以传入的authorities是空的。
2、UsernamePasswordAuthenticationFilter类的 attemptAuthentication()的方法走到最后就进入了AuthenticationManager
①AuthenticationManager的作用是管理AuthenticationProvider,找到AuthenticationManager的实现类ProviderManager的authenticate()方法
可以看到里面的AuthenticationProvider类型的,while()循环的原因是认证登录的方式多种多样,通过循环判断AuthenticationProvider的对象是否支持当前的验证类型。因此AuthenticationManager就需要把所有的AuthenticationProvider类型的对象收集起来。