SpringSecurity的基本原理(一)

SpringSecurity基本原理
SpringSecurity 最核心的东西 其实是一个过滤器链,一组Filter
所有发送的请求都会经过Filter链,同样响应也会经过Filter链,在系统启动的时候springboot会自动的把他们配置进去(Springboot只是一种框架,只是方便了使用,其核心还是一样的)

这里写图片描述

UsernamePasswordAuthticationFilter 表单登陆
BasicAuthenticationFilter Http登陆
–》
FilterSecurityInterceptor这个过滤器是整个SpringSecurity过滤器链的最后一环
然后进入到ExceptionTranslatonFilter中根据抛出的异常做出决定

断点跟进
1.FilterSecurityInterceptor

    // L124
    InterceptorStatusToken token = super.beforeInvocation(fi);

2.ExceptionTranslationFilter

    // L66
   Throwable[] causeChain = this.throwableAnalyzer.determineCauseChain(var10);

3.UsernamePasswordAuthenticationFilter

    // L75
    String username = obtainUsername(request);

只会处理/login post的请求

   // L61
    public UsernamePasswordAuthenticationFilter() {
        super(new AntPathRequestMatcher("/login", "POST"));
     }

4.Controller层执行方法的断点

/**
 * security配置
 * Created by ZhuPengWei on 2017/11/27.
 */
@Configuration
public class BrowserSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.formLogin() //表单登陆
                .and()
                .authorizeRequests() // 请求授权
                .anyRequest()  // 任何请求
                .authenticated();  // 都需要认证
    }

}
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值