登录流程


从这两张图可以看出请求UsernamePasswordAuthenticationFilter之后会调用ProviderManager里的DaoAuthenticationProvider进行验证。
有两种方式可以实现给接口添加验证码校验的功能。
1. 继承DaoAuthenticationProvider并重写authenticate方法,方法内添加具体的校验逻辑,在方法最后调用父类的authenticate实现。
文档中有提到DaoAuthenticationProvider会使用UserDetailsService和PasswordEncoder去校验用户提交的账号密码,所以在其逻辑执行之前添加校验验证码的逻辑即可。
2. 编写一个过滤器,在过滤器中添加校验,然后在配置中将过滤器添加至过滤器链中,位置在UsernamePasswordAuthenticationFilter之前。该过滤器的请求拦截和异常处理借鉴了AbstractAuthenticationProcessingFilter,中间添加校验验证码的逻辑。
代码
1. login.html
2. style.css
3. CaptchaAuthenticationProvider
4. CaptchaAuthenticationFilter
5. logo.png
6. AuthorizationController
7. AuthorizationConfig
测试


2053

被折叠的 条评论
为什么被折叠?



