序言
上一篇文章我们做了一个简单的入门程序,我们这一篇就来简单的跟踪源码,来分析一下其中的原理,顺便了解了整个流程后更方便我们扩展去做不同的登陆。
代码请参考 https://github.com/AutismSuperman/springsecurity-example
认证流程
我们就拿上一篇的登陆来做一个分析。
用户在页面上输入 用户名密码后访问响应的登陆方法 会进入到 UsernamePasswordAuthenticationFilter
然后会进入到attemptAuthentication
方法中。在这个方法里呢我们拿到请求中的用户名 和密码 并且构建了一个 UsernamePasswordAuthenticationToken
我们点进去看一下构建的什么
原来在构造方法里 setAuthenticated(false)
就代码这个 AuthenticationToken
没有进行认证。
最后返回值 返回给 AuthenticationManager
进行验证,好我们接着向下走
随后我们进入到了 ProviderManager
里 顾名思义就是各种 Provider 的管理器。