没有合适的资源?快使用搜索试试~ 我知道了~
首页springsecurity原理流程图.pdf
springsecurity原理流程图.pdf
![](https://csdnimg.cn/release/wenkucmsfe/public/img/star.98a08eaa.png)
SpringSecurity框架的权限认证流程原理,请求到来时SpringSecurity如果调用层层过滤器来完成认证;
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/11699361/bg1.jpg)
UsernamePasswordAuthenticationFilter
调用
UserDetailsService
Authentication
AuthenticationManager
AuthenticationProvider
调用
调用
调用
public Authentication attemptAuthentication(
HttpServletRequest request,
HttpServletResponse response)
String username = obtainUsername(request);
String password = obtainPassword(request);
UsernamePasswordAuthenticationToken authRequest =
new UsernamePasswordAuthenticationToken(
username, password);
username
password
authRequest
return this.getAuthenticationManager().authenticate(authRequest);
// 拿到全部的provider
Iterator e = this.getProviders().iterator();
// 遍历provider
while(e.hasNext()) {
// 挨着个的校验是否支持当前token
if(provider.supports(toT est))
ProviderManager.authenticate(Authentication
authentication);
交由AuthenticationManager接口的
ProviderManager实现类处理
// 找到后直接break,并由当前provider来进行校验工作
result = provider.authenticate(authentication);
if(result != null) {
this.copyDetails(authentication, result);
break;}
request
authRequest
传入调用
authRequest是一个
authentication
authRequest
authRequest是一个
authentication
这里交由AuthenticationProvider接口的实现类
DaoAuthenticationProvider来处理。
重写该方法
loadedUser = this.getUserDetailsService().
loadUserByUsername(username);
return loadedUser;
继承
protected final UserDetails retrieveUser(String username,
UsernamePasswordAuthenticationToken authentication)
实现
public Authentication authenticate(Authentication
authentication)
Abstract UserDe t ailsAut hent icat ionProvider
public Authentication authenticate(Authentication authentication)
user = this.retrieveUser(username,
(UsernamePasswordAuthenticationToken)authentication);
实际调用(子类实现)
继续执行
//前检查由DefaultPreAuthenticationChecks类实现(主要判断当前用户是否锁定,过期,冻结* User接口)
this.preAuthenticationChecks.check(user);
// 检测用户密码是否过期
this.postAuthenticationChecks.check(user);
return this.createSuccessAuthentication(principalToReturn, authentication,
user);
调用
protected Authentication
createSuccessAuthentication(Object principal,
Authentication authentication, UserDetails user)
return
result;
调用
UsernamePasswordAuthenticationToken result = new
UsernamePasswordAuthenticationToken(principal,
authentication.getCredentials(),
this.authoritiesMapper.mapAuthorities(user.getAuthorities()));
UsernamePasswordAuthe nt icat ionFilt e r
public Authentication attemptAuthentication(
HttpServletRequest request,
HttpServletResponse response)
实现
Abstract Aut hent icat ionProce ssingFilt e r
public void doFilter(ServletRequest req,
ServletResponse res, FilterChain chain)
实现
// 判断当前filter是否可以处理当前请求,
//若不行,则交给下一个filter去处理。
if (!requiresAuthentication(request, response))
authResult =
attemptAuthentication(request,
response);
// 最终认证成功后,会处理一些与session相关的方法
(比如将认证信息存到session等操作)。
sessionStrategy.onAuthentication(authResult,
request, response);
执行由子类重写后的方法
重写该方法
*
* 最终认证成功后的相关回调方法,主要将当前的认证信息放到
SecurityContextHolder中
* 并调用成功处理器做相应的操作。
*/
successfulAuthentication(request, response, chain, authResult);
}
调用AuthenticationManager的
authenticate方法进行验证
result
DaoAuthe nt icat ionProvider
protected final UserDetails
retrieveUser(String username,
UsernamePasswordAuthenticati
onT oken authentication)
request首先进入
的第一个拦截器
public class MyUse rDe t ailsService
implement s Use rDet ailsSe rvice
public UserDetails
loadUserByUsername(String username)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://profile-avatar.csdnimg.cn/3ed4fe15299b44639c2a43f23bf2d4d8_qq_42468130.jpg!1)
wesen12
- 粉丝: 1303
- 资源: 3
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- 基于单片机的瓦斯监控系统硬件设计.doc
- 基于单片机的流量检测系统的设计_机电一体化毕业设计.doc
- 基于单片机的继电器设计.doc
- 基于单片机的湿度计设计.doc
- 基于单片机的流量控制系统设计.doc
- 基于单片机的火灾自动报警系统毕业设计.docx
- 基于单片机的铁路道口报警系统设计毕业设计.doc
- 基于单片机的铁路道口报警研究与设计.doc
- 基于单片机的流水灯设计.doc
- 基于单片机的时钟系统设计.doc
- 基于单片机的录音器的设计.doc
- 基于单片机的万能铣床设计设计.doc
- 基于单片机的简易安防声光报警器设计.doc
- 基于单片机的脉搏测量器设计.doc
- 基于单片机的家用防盗报警系统设计.doc
- 基于单片机的简易电子钟设计.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)