首页 > 编程语言 >spring-security源码-FilterChainProxy

spring-security源码-FilterChainProxy

时间:2024-03-10 15:23:53浏览次数:29  
标签:FilterChainProxy firewallRequest chain spring request 源码 security logger

FilterChainProxy内部存储了我们各个HttpSecurty生成的SecurityFilterChain。FilterChainProxy实现了ServletFilter接口。只真正的入口

org.springframework.security.web.FilterChainProxy.doFilter

 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        boolean clearContext = request.getAttribute(FILTER_APPLIED) == null;
        if (!clearContext) {
            this.doFilterInternal(request, response, chain);
        } else {
            try {
                request.setAttribute(FILTER_APPLIED, Boolean.TRUE);
                <1>执行
                this.doFilterInternal(request, response, chain);
            } catch (Exception var11) {
                Throwable[] causeChain = this.throwableAnalyzer.determineCauseChain(var11);
                Throwable requestRejectedException = this.throwableAnalyzer.getFirstThrowableOfType(RequestRejectedException.class, causeChain);
                if (!(requestRejectedException instanceof RequestRejectedException)) {
                    throw var11;
                }

                //自定义异常处理器
                this.requestRejectedHandler.handle((HttpServletRequest)request, (HttpServletResponse)response, (RequestRejectedException)requestRejectedException);
            } finally {
                //清理
                SecurityContextHolder.clearContext();
                request.removeAttribute(FILTER_APPLIED);
            }

        }
    }

<1>

org.springframework.security.web.FilterChainProxy#doFilterInternal

 private void doFilterInternal(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        FirewalledRequest firewallRequest = this.firewall.getFirewalledRequest((HttpServletRequest)request);
        HttpServletResponse firewallResponse = this.firewall.getFirewalledResponse((HttpServletResponse)response);
        <2>根据url获取filters 多登录逻辑实现
        List<Filter> filters = this.getFilters((HttpServletRequest)firewallRequest);
        if (filters != null && filters.size() != 0) {
            if (logger.isDebugEnabled()) {
                logger.debug(LogMessage.of(() -> {
                    return "Securing " + requestLine(firewallRequest);
                }));
            }

            VirtualFilterChain virtualFilterChain = new VirtualFilterChain(firewallRequest, chain, filters);
            //执行filter
            virtualFilterChain.doFilter(firewallRequest, firewallResponse);
        } else {
            if (logger.isTraceEnabled()) {
                logger.trace(LogMessage.of(() -> {
                    return "No security for " + requestLine(firewallRequest);
                }));
            }

            firewallRequest.reset();
            chain.doFilter(firewallRequest, firewallResponse);
        }
    }

<2>

org.springframework.security.web.FilterChainProxy#getFilters(javax.servlet.http.HttpServletRequest)

  private List<Filter> getFilters(HttpServletRequest request) {
        int count = 0;
        Iterator var3 = this.filterChains.iterator();

        SecurityFilterChain chain;
        do {
            if (!var3.hasNext()) {
                return null;
            }

            chain = (SecurityFilterChain)var3.next();
            if (logger.isTraceEnabled()) {
                ++count;
                logger.trace(LogMessage.format("Trying to match request against %s (%d/%d)", chain, count, this.filterChains.size()));
            }
        } while(!chain.matches(request));

        return chain.getFilters();
    }

 

标签:FilterChainProxy,firewallRequest,chain,spring,request,源码,security,logger
From: https://www.cnblogs.com/LQBlog/p/18064215

相关文章

  • spring-security源码-如何初始化SecurityFilterChain到Servlet
    1.SecurityFilterChain是由HttpSecurty根据各个config配置生成的FilterSecurityFilterChain是接口,默认实现是由DefaultSecurityFilterChainSecurityFilterChain只充当描述的作用,描述哪些url走这批filterpublicfinalclassDefaultSecurityFilterChainimplementsSecurityF......
  • SpringMVC声明式事务
    事务并发、传播性、隔离级别(重难点)导读:本节重点在于多线程并发环境下的事务处理、和数据库在并发环境下的表锁和行锁。案例:在新增图书的时候,肯定需要先新增作者。SpringMVC声明式事务事务分两种:编程式事务、声明式事务Connectionconnconn.setAutoCommit(false)conn.comm......
  • 通达信空转多反击副图指标公式源码
    {通达信空转多反击副图指标公式源码}ZEROS:0,NODRAW;RSV:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9))*100;K:=SMA(RSV,3,1);D:=SMA(K,3,1);J:=3*K-2*D;VARV:=(2*C+H+L)/4;VARU:=LLV(LOW,30);VARA1:=HHV(HIGH,30);B:=EMA((VARV-VARU)/(VARA1-VARU)*100,8);B1:=EMA......
  • 通达信强烈反转指标,趋势改变上翘有力度源码
    {通达信强烈反转指标,趋势改变上翘有力度源码}N1:=20;N2:=60;VAR1:=(LOW+HIGH+CLOSE)/3;X:MA(VAR1,5);A1:HHV(X,N1)COLORMAGENTA;A2:HHV(X,N2),COLORGREEN;A3:HHV(HIGH,N2)*0.98,COLOR0000FF;B1:LLV(X,N1);B2:LLV(LOW,N2)*1.02;DRAWICON(X>B1ANDREF(X,1)=REF......
  • 通达信龙头起涨指标公式源码
    {通达信龙头起涨指标公式源码}趋势:EMA(100*(C-LLV(LOW,34))/(HHV(H,34)-LLV(LOW,34)),3),COLORRED;强弱:30,COLORWHITE;逃顶:90,COLORWHITE;Jbs:=C/REF(C,1)>1.05ANDC=HANDBETWEEN(FORCAST(V,4),0.2*FORCAST(V,12),2.1*FORCAST(V,12));必升:=FILTER(JBS,28)*100;VAR......
  • 通达信股价飞升指标公式源码副图
    {通达信股价飞升指标公式源码副图}VAR11:=3*SMA((C-LLV(L,480))/(HHV(H,480)-LLV(L,480))*100,5,1)-2*SMA(SMA((C-LLV(L,480))/(HHV(H,480)-LLV(L,480))*100,180,1),15,1);超级主升:=EMA(VAR11,5);主升1:=超级主升-100;D1:=EMA(C,5);D2:=(EMA(C,1)+EMA(C,5)+EMA(C,10)+EM......
  • 通达信跳空缺口完美版主图指标公式源码
    {通达信跳空缺口完美版主图指标公式源码}N:=30;LL:=REF(L,1);HH:=REF(H,1);SQK:=L>HH;XQK:=H<ll;向上跳几元钱:IF(SQK=1,L-HH,DRAWNULL),COLORGREEN,crOSSDOT,LINETHICK3,NODRAW;逃命跳空元:IF(XQK=1,H-LL,DRAWNULL),COLORYELLOW,CROSSDOT,LINETHICK3,NODRAW;DRAWTEXT(......
  • 通达信突破当天买入主图指标公式源码
    {通达信突破当天买入主图指标公式源码}{#跨周期时,可能会引用到未来数据}X_A:=cci#WEEK;X_B:=CCI#MONTH;突破当天买入:=X_B-REF(X_B,1)>90ORX_A-REF(X_A,1)>70;DRAWTEXT(突破当天买入,LLV(L,8),'突破当天买入'); ......
  • 通达信大牛异动指标公式源码
    {通达信大牛异动指标公式源码}N:=10;N1:=5;N2:=3;X_1:=REF(CLOSE,1)<ref(close,2)and=""close="">REF(CLOSE,1);X_2:=REF(CLOSE,1)>REF(CLOSE,2)ANDCLOSE<ref(close,1);<span="">X_3:=CLOSE=REF(CLOSE,1);X_4:=REF(CLOSE,1......
  • 通达信顶底准确指标公式源码
    {通达信顶底准确指标公式源码}VDD6:=MA(CLOSE,1);VDD8:=(LOW+HIGH+CLOSE)/3;VDD7:=MA(VDD8,5);顶底准确率:=LLV(VDD7,10);技术指标:=LLV((VDD6<顶底准确率),5);准确率100:=LLV((VDD6<顶底准确率),10);STICKLINE(准确率100,0,100,3,0),COLORRED;STICKLINE(技术指标,0,5......