SpringSeacurity源码分析(用户名和密码认证-webFlux)

过滤链调用

springSeacurity 用户身份认证调用如下图
在这里插入图片描述
很多细节没有画,请自行查看源码。

AuthenticationWebFilter过滤器分析

AuthenticationWebFilter实现了webFilter,拦截用户请求,对用户提交的账号和密码进行验证,

在这里插入图片描述
通过 以下代码生成将用户输入的用户名和密码生成Authentication对象

this.authenticationConverter.convert(exchange)

调用authenticate(ServerWebExchange exchange, WebFilterChain chain, Authentication token)验证用户,通过 authenticationManager.authenticate(token)调用
在这里插入图片描述
通过retrieveUser(String username)获取到当前用户 接着跟进去我们可以看到

在这里插入图片描述
终于我们看到了this.userDetailsService.findByUsername(username);好熟悉的类,我们在自定义的时候每次都需要实现这个接口重写这个方法为什么这一次终于知道了。
通过this.passwordEncoder.matches(presentedPassword, userDetails.getPassword())比对密码校验成功后通过createUsernamePasswordAuthenticationToken(UserDetails userDetails)完成认证成功的UsernamePasswordAuthenticationToken生成。
在这里插入图片描述

执行this.authenticationSuccessHandler. onAuthenticationSuccess(webFilterExchange, authentication)完成身份认证成功的回调。至此身份认证源码分析完毕。


版权声明:本文为qq_38041439原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。