<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,看看這一章就會有感覺了,不過絕知此事要躬行啊!
    完成這些配置之后,我們就算是把入口給搭建好了!
    鑒于文檔篇幅,換到下篇接著說。

    posted on 2010-01-25 15:56 taochen 閱讀(1078) 評論(0)  編輯  收藏 所屬分類: java設計模式軟件架構
    主站蜘蛛池模板: 亚洲一级特黄无码片| 全亚洲最新黄色特级网站 | 亚洲人成在线影院| 国产在线观看免费av站| 免费**毛片在线播放直播| 亚洲丁香婷婷综合久久| 日韩在线免费看网站| 久久亚洲欧美国产精品| 成av免费大片黄在线观看| 久久久亚洲精品蜜桃臀| 三级毛片在线免费观看| 国产亚洲精品精华液| 5g影院5g天天爽永久免费影院 | 日韩在线看片免费人成视频播放| 亚洲熟女综合色一区二区三区| 成人午夜视频免费| 看Aⅴ免费毛片手机播放| 亚洲av无码乱码在线观看野外 | 国内成人精品亚洲日本语音| 亚洲精品成人区在线观看| 国产精品极品美女自在线观看免费 | 中文字幕一精品亚洲无线一区| 青青操免费在线观看| 亚洲大片在线观看| 成年网站免费视频A在线双飞| 亚洲a∨无码一区二区| 国产成人A亚洲精V品无码| 亚洲AV无码专区电影在线观看| 啦啦啦完整版免费视频在线观看| 97久久国产亚洲精品超碰热| 国产免费观看a大片的网站| 91视频免费观看高清观看完整| 97亚洲熟妇自偷自拍另类图片 | 亚洲性无码AV中文字幕| 亚洲片一区二区三区| 外国成人网在线观看免费视频| 亚洲一区二区三区深夜天堂 | 亚洲国产香蕉碰碰人人| 两个人的视频高清在线观看免费 | 亚洲毛片在线免费观看| 国产一区视频在线免费观看|