2012-07-23 9 views
6

私は春のセキュリティを使用しているので、フィルタチェーンと名前空間の両方を使用する必要があります。名前空間は正常に動作しますが、フィルタチェーンはそうではありません。
これは私の設定です。まず、名前空間:
Springセキュリティ - 名前空間とフィルタチェーンの両方を使用できますか?

<sec:global-method-security secured-annotations="enabled" /> 

<sec:http pattern="/app/login.jsp*" security="none" /> 
<sec:http pattern="/admin/login.jsp*" security="none" /> 
<sec:http pattern="/app/*.png" security="none" /> 
<sec:http pattern="/admin/*.png" security="none" /> 
<sec:http pattern="/app/**" authentication-manager-ref="authenticationManager" 
    access-decision-manager-ref="accessDecisionManager"> 
    <sec:intercept-url pattern="/app/**" access="ROLE_USER" /> 
    <sec:access-denied-handler error-page="/app/login.jsp?aer=" /> 
    <sec:form-login login-processing-url="/app/j_spring_security_check" 
     always-use-default-target="true" default-target-url="/app/index.html" 
     login-page='/app/login.jsp' authentication-failure-url='/app/login.jsp?login_error' /> 
    <sec:logout logout-url="/app/j_spring_security_logout" 
     invalidate-session="true" logout-success-url="/app/login.jsp" /> 
</sec:http> 
<sec:http pattern="/admin/**" authentication-manager-ref="authenticationManager" 
    access-decision-manager-ref="accessDecisionManager"> 
    <sec:intercept-url pattern="/admin/**" access="ROLE_ADMIN" /> 
    <sec:access-denied-handler error-page="/admin/login.jsp?aer=" /> 
    <sec:form-login login-processing-url="/admin/j_spring_security_check" 
     always-use-default-target="true" default-target-url="/admin/index.html" 
     login-page='/admin/login.jsp' authentication-failure-url='/admin/login.jsp?login_error' /> 
    <sec:logout logout-url="/admin/j_spring_security_logout" 
     invalidate-session="true" logout-success-url="/admin/login.jsp" /> 
</sec:http> 


これが正常に動作します。しかし、私はまた、他の要求をチェックするためにフィルターチェーンを持つ必要があります。 (これらの要求は、動的に作成されていると我々は彼らをこのように制御する必要が)
これは私のフィルタチェーンです:

<bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy"> 
    <security:filter-chain-map path-type="ant"> 

    <sec:filter-chain pattern="/css/**" filters="none" /> 
    <sec:filter-chain pattern="/common/**" filters="none" /> 
    <sec:filter-chain pattern="/images/**" filters="none" /> 
    <sec:filter-chain pattern="/login.jsp*" filters="none" /> 
    <sec:filter-chain pattern="/rest/**" 
     filters=" 
     ConcurrentSessionFilter, 
     securityContextPersistenceFilter, 
     logoutFilter, 
     authenticationProcessingFilter, 
     sessionManagementFilter, 
     exceptionTranslationFilter, 
     filterSecurityInterceptor" /> 

    </security:filter-chain-map> 
</bean> 


問題は、あるフィルタチェーンは何を制御しません。名前空間が使用されていないときに、フィルタチェーンがうまく動作していると確信しています。しかし、名前空間を追加すると、問題が始まります。
なぜですか?私はそれを使用することはできませんか?または私は何かを変えなければならない?

更新日:

この私のデバッグログをこのリソースを呼び出すとき:/rest/asrv/gtallmmbrsofusrgrp

DEBUG AntPathRequestMatcher   - Checking match of request : '/rest/asrv/gtallmmbrsofusrgrp'; against '/app/login.jsp*' 
DEBUG AntPathRequestMatcher   - Checking match of request : '/rest/asrv/gtallmmbrsofusrgrp'; against '/admin/login.jsp*' 
DEBUG AntPathRequestMatcher   - Checking match of request : '/rest/asrv/gtallmmbrsofusrgrp'; against '/app/*.png' 
DEBUG AntPathRequestMatcher   - Checking match of request : '/rest/asrv/gtallmmbrsofusrgrp'; against '/admin/*.png' 
DEBUG AntPathRequestMatcher   - Checking match of request : '/rest/asrv/gtallmmbrsofusrgrp'; against '/app/**' 
DEBUG AntPathRequestMatcher   - Checking match of request : '/rest/asrv/gtallmmbrsofusrgrp'; against '/admin/**' 
DEBUG FilterChainProxy    - /rest/asrv/gtallmmbrsofusrgrp has no matching filters 
+0

名前空間の設定方法から、私はあなたがSS 3.1を使用していると仮定していますか?あなたの質問の特異性に基づいて、設定に関して何をしているのか分かっているようです - 名前空間宣言の代わりにこのフィルタチェーン*を適用しようとしていますか? –

+0

これらのフィルタを名前空間に追加しようとしています。 –

+0

私の質問は@PeterMularienに更新されました。これで、filter-chain-proxyが機能しないことがわかります。この問題の原因は私の構成ですか?注文を変更する必要がありますか? –

答えて

5

私はあなたがあなたのweb.xmlでDelegatingFilterProxyエントリが欠落していると思います。しかし、とにかく

Spring 3.1以降、FilterChainProxyはSecurityFilterChainインスタンスのリストを使用して設定され、FilterChainMapは推奨されなくなりました。

<bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy"> 
    <constructor-arg> 
     <list> 
      <sec:filter-chain pattern="/css/**" filters="none" /> 
      <sec:filter-chain pattern="/common/**" filters="none" /> 
      <sec:filter-chain pattern="/images/**" filters="none" /> 
      <sec:filter-chain pattern="/login.jsp*" filters="none" /> 
      <sec:filter-chain pattern="/rest/**" 
       filters=" 
       ConcurrentSessionFilter, 
       securityContextPersistenceFilter, 
       logoutFilter, 
       authenticationProcessingFilter, 
       sessionManagementFilter, 
       exceptionTranslationFilter, 
       filterSecurityInterceptor" /> 
     </list> 
    </constructor-arg> 
</bean> 

そして、このようなあなたのweb.xmlにフィルタを追加します:だからそれをこのように設定してみてください

<filter> 
    <filter-name>filterChainProxy</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>filterChainProxy</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

API Documentation

UPDATE 1

ロギングを追加するにはアプリケーションにlog4j jarをパスに追加し、クラスパスの下にlog4j.propertiesファイルを追加します。

Log4j.properties:

log4j.rootCategory=INFO, stdout 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p %c %M - %m\n 

log4j.category.org.springframework.security=DEBUG 

logging using Log4j

UPDATE 2参照してください:私のために働くようだ、私は残りのディレクトリにテストページwelcome.xhtmlを配置しています。デバッグログは次のとおりです。

2012-07-30 00:26:05,917 DEBUG org.springframework.security.web.util.AntPathRequestMatcher matches - Checking match of request : '/rest/welcome.xhtml'; against '/javax.faces.resource/**' 
2012-07-30 00:26:05,923 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 1 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' 
2012-07-30 00:26:05,923 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository readSecurityContextFromSession - No HttpSession currently exists 
2012-07-30 00:26:05,923 DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository loadContext - No SecurityContext was available from the HttpSession: null. A new one will be created. 
2012-07-30 00:26:05,925 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 2 of 11 in additional filter chain; firing Filter: 'LogoutFilter' 
2012-07-30 00:26:05,925 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 3 of 11 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter' 
2012-07-30 00:26:05,925 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 4 of 11 in additional filter chain; firing Filter: 'BasicAuthenticationFilter' 
2012-07-30 00:26:05,925 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 5 of 11 in additional filter chain; firing Filter: 'RequestCacheAwareFilter' 
2012-07-30 00:26:05,925 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 6 of 11 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter' 
2012-07-30 00:26:05,926 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 7 of 11 in additional filter chain; firing Filter: 'RememberMeAuthenticationFilter' 
2012-07-30 00:26:05,926 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 8 of 11 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter' 
2012-07-30 00:26:05,928 DEBUG org.springframework.security.web.authentication.AnonymousAuthenticationFilter doFilter - Populated SecurityContextHolder with anonymous token: 'org.sprin[email protected]9055c2bc: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS' 
2012-07-30 00:26:05,928 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 9 of 11 in additional filter chain; firing Filter: 'SessionManagementFilter' 
2012-07-30 00:26:05,929 DEBUG org.springframework.security.web.session.SessionManagementFilter doFilter - Requested session IDD44EAA53A767F3DC9C7338D3CD335198 is invalid. 
2012-07-30 00:26:05,929 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 10 of 11 in additional filter chain; firing Filter: 'ExceptionTranslationFilter' 
2012-07-30 00:26:05,929 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' 
2012-07-30 00:26:05,929 DEBUG org.springframework.security.web.util.AntPathRequestMatcher matches - Checking match of request : '/rest/welcome.xhtml'; against '/login.xhtml' 
2012-07-30 00:26:05,929 DEBUG org.springframework.security.web.util.AntPathRequestMatcher matches - Checking match of request : '/rest/welcome.xhtml'; against '/*' 
2012-07-30 00:26:05,929 DEBUG org.springframework.security.web.util.AntPathRequestMatcher matches - Checking match of request : '/rest/welcome.xhtml'; against '/admin/**' 
2012-07-30 00:26:05,930 DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor beforeInvocation - Public object - authentication not attempted 
2012-07-30 00:26:05,932 DEBUG org.springframework.security.web.FilterChainProxy doFilter - /rest/welcome.xhtml reached end of additional filter chain; proceeding with original chain 
2012-07-30 00:26:06,229 DEBUG org.springframework.security.web.access.ExceptionTranslationFilter doFilter - Chain processed normally 

問題が発生している2つの形式のログインと思われます。 1つのログインフォームしか持たず、ロールに基づいてナビゲーションを制御してください。たとえば、この質問を参照してください。Can i use one Login page to redirect different page with Spring 3.0 Security..?

+0

私はこれを数時間後に確認し、その結果をお知らせします。しかし、それはこれを忘れることではありません。 –

+0

、およびデバッグレベルのログも確認してください。 – Ravi

+0

設定を確認しましたが、残念ながらこれは動作しません。問題が発生していないのでログはありません。これ以上の情報が必要な場合はお知らせください。 –

関連する問題