【问题标题】:Spring security : sec:authorize tag gives stream closed exceptionSpring security : sec:authorize 标签给出流关闭异常
【发布时间】:2012-04-18 12:06:10
【问题描述】:

我正在使用 Spring security 3.0.6。以下 JSP sn-p 是罪魁祸首:

<sec:authorize access="hasRole('ROLE_PREVIOUS_ADMINISTRATOR')">
                         <a href="<s:url value='/exitUser' />">
                            Switch back to your own role</a>
</sec:authorize>

抛出以下异常:

    Struts has detected an unhandled exception:
# Messages:     Stream closed
File:   org/apache/jasper/runtime/JspWriterImpl.java
Line number:    210
Stacktraces
java.io.IOException: Stream closed

    org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:210)
    org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
    org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:177)
    org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:915)
    org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:652)
    org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:123)
    org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)

我已成功将用户切换到另一个角色,现在正尝试显示链接以切换回他自己的角色,但前提是他确实已切换。如果用户切换了角色,我推测他有 ROLE_PREVIOUS_ADMINISTRATOR,所以我正在执行上述操作。

我通过以下方式包含了标签库

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

【问题讨论】:

  • 一定有另一个您没有看到的潜在错误。查看 tomcat 日志以找到它。

标签: spring spring-security


【解决方案1】:

我没有指定

<http use-expressions="true">

在我的 Spring Security xml 中。完成此操作并更改 拦截网址 以在其 accepts 值中使用表达式后,错误消失了。但无法在简单的测试应用程序中重现该错误。

Edit :我发现此错误的另一个实例是当我在 authorize 标记中使用自定义 SPEL 表达式时,其中有一个 NullPointerException处理表达式的方法。

基本上,似乎这个错误通常隐藏了评估authorize(或任何)标签中使用的表达式时的潜在错误

【讨论】:

    猜你喜欢
    • 2014-12-12
    • 2021-02-23
    • 2015-11-26
    • 2019-04-14
    • 2021-06-20
    • 2016-03-18
    • 1970-01-01
    • 2016-03-14
    • 2019-02-20
    相关资源
    最近更新 更多