<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    無極,無際,無跡

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      3 Posts :: 8 Stories :: 10 Comments :: 0 Trackbacks
    按照SpringSecurity的文檔,我們可以使用namespace的配置方式(前篇中已經說明)。
    但是,我們這里的需求有點蹊蹺,就是通過spring context進行權限配置太不方便,你想想能讓人家客戶通過spring xml來配置權限嗎?不能,堅決不能!所以,我就單步跟蹤獲取里面的東西(這種方法比直接看代碼快點,而且可以知道里面的邏輯結構!)
    那就開始吧:
    1.配置FilterChainProxy:
      SpringSecurity的驗證過程是通過一系列的filter來實現的。
      這種chain的設計模式比較經典,可以說相當經典!
      看看代碼實現:
      上篇中說過,默認的配置要求<filter-name>springSecurityFilterChain</filter-name>,那這個springSecurityFilterChain是怎么來用的呢?
      public class DelegatingFilterProxy extends GenericFilterBean {
      ... ... ...
      protected void initFilterBean() throws ServletException {
            // 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.
            synchronized (this.delegateMonitor) {
                WebApplicationContext wac = findWebApplicationContext();
                if (wac != null) {
                    this.delegate = initDelegate(wac);
                }
            }
        }
      .....
      }
      不用說,你會猜到我們沒有配置過targetBeanName這個屬性,所以,就有了this.targetBeanName = getFilterName();這樣的話就會配置FilterChainProxy了,因為FilterChainProxy在springContext中id是springSecurityFilterChain,所以我們要通過自己的數據庫方式配置的話,就要琢磨這個FilterChainProxy了!
      所以,首先做點這樣的配置吧:
      <beans:bean id="myFilterChain" class="org.springframework.security.web.FilterChainProxy" >
          <filter-chain-map path-type="ant">
              <filter-chain pattern="/login.jsp*" filters="none"/>
              <filter-chain pattern="/**" filters="securityContextPersistenceFilter,
                                                   logoutFilter,
                                                   myUsernamePasswordAuthenticationFilter,
                                                   basicAuthenticationFilter,
                                                   requestCacheAwareFilter,
                                                   securityContextHolderAwareRequestFilter,
                                                   anonymousAuthenticationFilter,
                                                   sessionManagementFilter,
                                                   exceptionTranslationFilter,
                                                   filterSecurityInterceptor"/>
          </filter-chain-map>
      </beans:bean>
    這個里面配置的id為myFilterChain,所以要在web.xml里面做相應配置:
       <filter>
          <filter-name>myFilterChain</filter-name>
          <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      </filter>
      <filter-mapping>
          <filter-name>myFilterChain</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>
    而且,尤為重要的是要配置上這些過濾器:
    filter-chain pattern="/**" filters="securityContextPersistenceFilter,logoutFilter,
                                                   myUsernamePasswordAuthenticationFilter,
                                                   basicAuthenticationFilter,
                                                   requestCacheAwareFilter,
                                                   securityContextHolderAwareRequestFilter,
                                                   anonymousAuthenticationFilter,
                                                   sessionManagementFilter,
                                                   exceptionTranslationFilter,
                                                   filterSecurityInterceptor"
    針對這些過濾器的用途,在spring security的文檔中有詳細描述,這里不多說了,在文檔中的具體位置是7.2 FilterChainProxy,看看這一章就會有感覺了,不過絕知此事要躬行?。?br /> 完成這些配置之后,我們就算是把入口給搭建好了!
    鑒于文檔篇幅,換到下篇接著說。

    posted on 2010-01-25 15:56 taochen 閱讀(1078) 評論(0)  編輯  收藏 所屬分類: java設計模式軟件架構
    主站蜘蛛池模板: 女同免费毛片在线播放| 噜噜综合亚洲AV中文无码| 国产区在线免费观看| 免费大黄网站在线观| 精品亚洲成a人在线观看| 国产极品美女高潮抽搐免费网站| 国产精品亚洲专区在线观看| 国产精品爱啪在线线免费观看| 亚洲高清美女一区二区三区| 最近中文字幕完整免费视频ww | 免费萌白酱国产一区二区三区| 亚洲成a人片在线观看国产| 男男gvh肉在线观看免费| 免费观看a级毛片| 国内成人精品亚洲日本语音| 亚洲va中文字幕无码| 成年网站免费入口在线观看| 亚洲日本一区二区一本一道| 成人毛片100免费观看| 亚洲欧洲成人精品香蕉网| 久久久精品免费视频| 亚洲精品自拍视频| 无码日韩人妻av一区免费| 国产色在线|亚洲| 国产免费私拍一区二区三区| eeuss免费天堂影院| 亚洲国产精品特色大片观看完整版| 日本视频免费高清一本18| 亚洲视频在线一区| 中文字幕无码免费久久99| 亚洲成AV人影片在线观看| 亚洲熟伦熟女新五十路熟妇 | 日韩免费电影网址| 亚洲欧洲精品久久| 免费精品一区二区三区在线观看| 麻豆91免费视频| 亚洲AV福利天堂一区二区三 | 成全动漫视频在线观看免费高清版下载| 亚洲AV永久青草无码精品| 中文字幕免费高清视频| 风间由美在线亚洲一区|