【Spring Security】4.DefaultSecurityFilterChain

首先在源代码中找到这个类,shift + shift 可进行全局搜索

image-20240306113159465

可以发现这个类实现了SecurityFilterChain

image-20240306113239432

默认情况下,SpringSecurity程序有一个默认的过滤器链,这一个默认的过滤器链里,有一系列默认的过滤器的集合

应用程序启动后,日志中有一行是和DefaultSecurityFilterChain相关的

image-20240306113456861

然后把这一行完整的复制下来,放到一个记事本中

这就是spring应用程序默认加载的16个过滤器

o.s.s.web.DefaultSecurityFilterChain     : Will secure any request with [
org.springframework.security.web.session.DisableEncodeUrlFilter@5d152bcd, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@43cb5f38, 
org.springframework.security.web.context.SecurityContextHolderFilter@4684240f, 
org.springframework.security.web.header.HeaderWriterFilter@115ca7de, 
org.springframework.web.filter.CorsFilter@6435fa1c, 
org.springframework.security.web.csrf.CsrfFilter@31f295b6, 
org.springframework.security.web.authentication.logout.LogoutFilter@478b0739, 
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@72bd2871, 
org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@2e4389ed, 
org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@7944b8b4, 
org.springframework.security.web.authentication.www.BasicAuthenticationFilter@413bef78, 
org.springframework.security.web.savedrequest.RequestCacheAwareFilter@6975fb1c, 
org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@553da911, 
org.springframework.security.web.authentication.AnonymousAuthenticationFilter@d7bbf12, 
org.springframework.security.web.access.ExceptionTranslationFilter@63f6bed1, 
org.springframework.security.web.access.intercept.AuthorizationFilter@25f61c2c
]

另一个方法:打开DefaultSecurityFilterChain这个类,然后在这个类中设置一个断点

这里有一个构造方法,构造方法里有一个filters(过滤器列表),这个过滤器列表是当前这个类的一个成员,这一行过滤器列表会被赋值。

image-20240306113926637

向下执行一步,可以看见filters被赋值了。SecurityFilterChain接口的实现,加载了默认的16个Filter。

其中这些过滤器就有实现用户认证功能的,有实现授权功能的,还有实现系统的攻击防御功能的。

image-20240306114053807

帮助我们校验用户名和密码是否正确的方式来决定是否给这个用户进行一个验证,从而让他登录到系统的主页面中

image-20240306114146340

给我们展示一个Login配置登录页的过滤器

image-20240306114309425

帮助我们展示一个登出页面的过滤器

image-20240306114331421

帮助我们实现默认登出流程

image-20240306114355685

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值