《SpringSecurity过滤器链》章节一

1、SpringSecurity过滤器链总概

如下图

2、自我理解

此处理解皆为自己的观点,若有错误,还请路过的大佬批评与指正:

2.1、http请求在到达RESTful服务器之前,会经过SpringSecurity的一系列过滤器(当然项目要使用该鉴权框架)鉴权认证,该请求是否有资格访问到服务器。

2.2、过滤器链中最后一个就是来判断该请求是否有资格访问到服务的,其内部维护着投票器来决定的。

以下通过伪代码说明:

FilterSecurityInterceptor.doFilter->
invoke->
AbstractSecurityInterceptor.beforeInvocation->
DefaultFilterInvocationSecurityMetadataSource.getAttributes->
accessDecisionManager(spring默认采用的实现类AffirmativeBased).decide(投票器不通过抛出AccessDeniedException异常给AbstractSecurityInterceptor)->
if (鉴权不通过) {
    AbstractSecurityIntercepto捕获AccessDeniedException异常并调用AbstractSecurityInterceptor.publishEvent发布事件,且向上抛出该异常给ExceptionTranslationFilter->
    throwableAnalyzer.getFirstThrowableOfType(检查此异常的根是否为AuthenticationException\AccessDeniedException->
    ExceptionTranslationFilter.handleSpringSecurityException(处理异常))->
    if (authenticationTrustResolver.isAnonymous(authentication)) {
        sendStartAuthentication
    } else {
        (accessDeniedHandler.handle(request, response,(AccessDeniedException) exception))
    }
} else {
    鉴权通过直接访问服务
}

2.3、第一个过滤器SecurityContextPersistenceFilter

作用一:

当请求进来时,检查session中是否有SecurityContext,若有,将其取出放入线程(ThreadLocal)中,没有进入下一个过滤器

作用二:

当请求结束返回时,检查线程(ThreadLocal)中是否有SecirityContext,如果有,将其取出放入session中

2.4、在概括图中绿色的过滤器皆为进行身份认证的过滤器。

3、后续继续更新......

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值