日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

springSecurity源码分析-springSecurityFilterChain

發(fā)布時(shí)間:2024/4/13 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springSecurity源码分析-springSecurityFilterChain 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在web.xml文件中配置

問題:為什么DelegatingFilterProxy的filter-name必須是springSecurityFilterChain?

DelegatingFilterProxy并不是真正的Filter,在其initFilterBean方法中會(huì)從WebApplicationContext根據(jù)delegate來(lái)獲取到?

protected void initFilterBean() throws ServletException {synchronized (this.delegateMonitor) {if (this.delegate == null) {// If no target bean name specified, use filter name.if (this.targetBeanName == null) {this.targetBeanName = getFilterName();}// Fetch Spring root application context and initialize the delegate early,// if possible. If the root application context will be started after this// filter proxy, we'll have to resort to lazy initialization.WebApplicationContext wac = findWebApplicationContext();if (wac != null) {this.delegate = initDelegate(wac);}}} }

在上這代碼中this.targetBeanName=getFilterName()就是獲取名稱叫做springSecurityFilterChain

通過在doFilter就去中我們會(huì)發(fā)現(xiàn)真正干活的其實(shí)是delegate這個(gè)Filter,而delegate其實(shí)就是FilterChainProxy

public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)throws ServletException, IOException {// Lazily initialize the delegate if necessary.Filter delegateToUse = this.delegate;if (delegateToUse == null) {synchronized (this.delegateMonitor) {delegateToUse = this.delegate;if (delegateToUse == null) {WebApplicationContext wac = findWebApplicationContext();if (wac == null) {throw new IllegalStateException("No WebApplicationContext found: " +"no ContextLoaderListener or DispatcherServlet registered?");}delegateToUse = initDelegate(wac);}this.delegate = delegateToUse;}}// Let the delegate perform the actual doFilter operation.invokeDelegate(delegateToUse, request, response, filterChain);}

FilterChainProxy是spring在解析配置文件時(shí)裝配到上下文中,并且beanName為springSecurityFilterChain,

因此在web.xml中需要配置filter-name為springSecurityFilterChain

總結(jié)

以上是生活随笔為你收集整理的springSecurity源码分析-springSecurityFilterChain的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。