SpringSecurity的常见过滤器介绍

org.springframework.security.context.SecurityContextPersistenceFilter

主要的作用就是使用SecurityContextRepository在session中保存或更新一个SecurityContext(存储单签的用户认证以及授权信息),并将SecurityContext给以后的过滤器使用,来为后续filter建立所需的上下文,如果没有这个过滤器的话后续的过滤器都无法被建立。(最最最核心的)

org.springframework.security.web.context.request.async.WebAsyncManagerInterationFilter

这个过滤器就是集成SecurityContext到Spring异步执行机制中的WebAsyncManager。简答来说就是将SpringSecurity整合到Spring中区

org.springframework.security.web.header.HeaderWriterFilter

向请求的Header中添加相应的信息,可在http标签内部使用security:headers来控制。但是这个标签仅用于jsp页面。

org.springframework.security.web.csrf.CsrfFilter

csrf又称跨域请求伪造,SpringSecurity会对所有post请求验证是否包含系统生成的csrf的token信息,如果没有token的话会被拦截到并且后台发出异常。这个拦截器起到防止csrf攻击的效果。

org.springframework.security.web.authentication.logout.LogoutFilter

匹配 URL为/logout的请求,拦截到这个请求后实现用户退出,并且清除认证信息。

org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

认证操作的过滤器,默认匹配URL为/login而且请求的方式必须为POST请求。

org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter

如果没有在配置文件中指定认证页面,则由该过滤器生成一个默认认证页面。简单来说就是没有指定登录页面的时候这个过滤器就会使用内部自带的登录页面(还挺好看的)。

org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter

和之前的认证操作的过滤器差不多,如果没有指定退出页面的话这个过滤器就会自动生产一个默认的退出登录页面

org.springframework.security.web.authentication.www.BasicAuthenticationFilter

此过滤器会自动解析HTTP请求中头部名字为Authentication,且以Basic开头的头信息。

org.springframework.security.web.savedrequest.RequestCacheAwareFilter

通过HttpSessionRequestCache内部维护了一个RequestCache,用于缓存HttpServletRequest

org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter

针对ServletRequest进行了一次包装,使得request具有更加丰富的API

org.springframework.security.web.authentication.AnonymousAuthenticationFilter

当SecurityContextHolder中认证信息为空,则会创建一个匿名用户存入到SecurityContextHolder中。SpringSecurity为了兼容未登录的访问,也走了一套认证流程,只不过是一个匿名的身份。

org.springframework.security.web.session.SessionManagementFilter

SecurityContextRepository限制同一用户开启多个会话的数量。

org.springframework.security.web.access.ExceptionTranslationFilter

异常转换过滤器位于整个springSecurityFilterChain的后方,用来转换整个链路中出现的异常。

org.springframework.security.web.access.intercept.FilterSecurityInterceptor

获取所配置资源访问的授权信息,根据SecurityContextHolder中存储的用户信息来决定其是否有权限。(最最最重要的)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值