2012-07-21 13 views
18

ユーザーが認証されている場合のみ、JSPページにログアウトリンクを表示できません。ここで私はJSPページのこの行に持っている例外は次のとおりです。Spring Security - アプリケーションコンテキストで可視のWebSecurityExpressionHandlerインスタンスが見つかりませんでした。

<sec:authorize access="isAuthenticated()"> 

例外:

Stacktrace: 
.... 

root cause 

javax.servlet.jsp.JspException: No visible WebSecurityExpressionHandler instance could be found in the application context. There must be at least one in order to support expressions in JSP 'authorize' tags. 
    org.springframework.security.taglibs.authz.AuthorizeTag.getExpressionHandler(AuthorizeTag.java:100) 
    org.springframework.security.taglibs.authz.AuthorizeTag.authorizeUsingAccessExpression(AuthorizeTag.java:58) 

ここでは、私のアプリケーション・コンテキストのsecurity.xmlです:

<http auto-config='true' > 
    <intercept-url pattern="/user/**" access="ROLE_User" /> 
    <logout logout-success-url="/hello.htm" /> 
</http> 

<beans:bean id="daoAuthenticationProvider" 
    class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"> 
    <beans:property name="userDetailsService" ref="userDetailsService" /> 
</beans:bean> 

<beans:bean id="authenticationManager" 
    class="org.springframework.security.authentication.ProviderManager"> 
    <beans:property name="providers"> 
     <beans:list> 
      <beans:ref local="daoAuthenticationProvider" /> 
     </beans:list> 
    </beans:property> 
</beans:bean> 

<authentication-manager> 
    <authentication-provider user-service-ref="userDetailsService"> 
     <password-encoder hash="plaintext" /> 
    </authentication-provider> 
</authentication-manager> 

私は理解してhttpタグでuse-expression = "true"を使用することができますが、これはintercept-urlタグとjavaコードで式を使用する必要があることを意味します。回避策はありますか?

+0

関連のない観察。あなたの設定の 'daoAuthenticationProvider'と' authenticationManager'は使用されていません。 –

答えて

41

あなたは自分のアプリケーションコンテキスト

<bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" /> 

に1を追加することができますが、最も簡単な方法は、ちょうどあなたの<http>構成の表現を可能にするために、もう1つはあなたのために追加されますです。これは、メソッドブロック@Secured注釈などのJavaコードではなく、そのブロック内で式を使用する必要があることを意味します。

+1

あなたは正しいです、私はちょうどブロック内の表現を使用しなければなりませんでした。問題は解決された。 – dukable

+10

と明示的に指定するには、タグに「use-expressions」属性をtrueに設定する必要があります(例:

関連する問題