2012-07-13 26 views
2

我有兩種模式要應用相同的過濾器。我們可以爲filterChainProxy中的單個過濾器鏈提供多個模式

<security:filter-chain pattern="/home.do*" filters="a,b,c,d" /> 
<security:filter-chain pattern="/login.do*" filters="a,b,c,d" /> 

隨着上述兩個還有許多其他獨特圖案和一個通用的圖案/**/*.do*/**爲好。

我可以指定用逗號分隔的格局多個模式的屬性如下圖所示:

<security:filter-chain pattern="/home.do*, /login.do*" filters="a,b,c,d" />

回答

6

當然可以,但實現依賴於Spring Security的版本所使用。

  • 在3.0可以使用path-type屬性:

    <security:filter-chain-map path-type="regex"> 
        <security:filter-chain pattern="^/(test|home)\.do$" filters="a,b,c,d" /> 
        <!-- other patterns --> 
    <security:filter-chain-map path-type="regex"> 
    
  • 在3.1既可以使用request-matcher屬性(棄用path-type,只是改變路徑型請求在前面的例子中匹配器),或您可以使用多個http元素與request-matcher-ref豆和做到這一點:

    <http pattern="test.do,home.do" security="none" <!-- 'none' as example --> 
        request-matcher-ref="requestMatcher" /> 
    
    <bean id="requestMatcher" class="com.example.CommaSeparatedRequestMatcher" /> 
    

    與您的自定義實現CommaSeparatedRequestMatcher(它根據請求和triest創建的URL匹配任何字符串),例如,基於RegexRequestMatcher

+0

感謝您的詳細回覆:) – Coolblu 2012-07-13 15:28:30

相關問題