將異常映射到404頁面時,Spring Security標記無法從安全上下文中找到認證信息。使用「真實」404,可以找到認證。在使用Spring Security標記庫時將異常映射到404頁面
我的web.xml:
<error-page>
<exception-type>com.example.NotFoundException</exception-type>
<location>/app/404</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/app/404</location>
</error-page>
在JSP我:
<sec:authorize access="hasRole('ROLE_USER')">
<%-- Show navigation links --%>
</sec:authorize>
<sec:authorize access="isAnonymous()">
<%-- Show login form --%>
</sec:authorize>
的/app/404
路徑映射到控制器剛剛返回的視圖。當我瀏覽到/foo/some_invalid_id
時,NotFoundException
被從控制器拋出,最後當它進入JSP時,它無法在SecurityContext
中找到身份驗證並呈現這兩個選項。相反,當我瀏覽到/something_that_really_doesnt_exist
時,它能夠確定我是否登錄並呈現正確的HTML。
這可能會幫助http://stackoverflow.com/questions/4153438/spring-security-issue-with-404-error – 2011-01-24 10:24:28
謝謝,但它沒有幫助我。 – hleinone 2011-01-24 10:41:05