首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Spring Security -在应用程序上下文中找不到可见的WebSecurityExpressionHandler实例

Spring Security -在应用程序上下文中找不到可见的WebSecurityExpressionHandler实例
EN

Stack Overflow用户
提问于 2012-07-22 00:56:45
回答 1查看 13.9K关注 0票数 22

仅当用户通过身份验证时,我才在JSP页面中显示注销链接时遇到问题。下面是我在JSP页面的这一行中遇到的异常:

代码语言:javascript
复制
<sec:authorize access="isAuthenticated()">

例外:

代码语言:javascript
复制
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)

下面是我的application-context-Security.xml:

代码语言:javascript
复制
<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代码中使用expression。有解决办法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-22 02:53:44

您可以只向您的应用程序上下文添加一个

代码语言:javascript
复制
<bean id="webexpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler" /> 

但最简单的方法是在<http>配置中启用表达式,系统将为您添加一个表达式。这只意味着您必须在该块中使用表达式,而不是在@Secured方法注释等Java代码中使用表达式。

票数 46
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11594104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档