没有合适的资源?快使用搜索试试~ 我知道了~
首页springsecurity原理流程图.pdf
springsecurity原理流程图.pdf
需积分: 42 4.9k 浏览量
更新于2023-05-26
评论 3
收藏 50KB PDF 举报
SpringSecurity框架的权限认证流程原理,请求到来时SpringSecurity如果调用层层过滤器来完成认证;
资源详情
资源评论
资源推荐

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)


















wesen12
- 粉丝: 1281
- 资源: 3
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
最新资源
- Xilinx SRIO详解.pptx
- Informatica PowerCenter 10.2 for Centos7.6安装配置说明.pdf
- 现代无线系统射频电路实用设计卷II 英文版.pdf
- 电子产品可靠性设计 自己讲课用的PPT,包括设计方案的可靠性选择,元器件的选择与使用,降额设计,热设计,余度设计,参数优化设计 和 失效分析等
- MPC5744P-DEV-KIT-REVE-QSG.pdf
- 通信原理课程设计报告(ASK FSK PSK Matlab仿真--数字调制技术的仿真实现及性能研究)
- ORIGIN7.0使用说明
- 在VMware Player 3.1.3下安装Redhat Linux详尽步骤
- python学生信息管理系统实现代码
- 西门子MES手册 13 OpcenterEXCR_PortalStudio1_81RB1.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论0