当将异常映射到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>@H_404_5@在JSP上有:
<sec:authorize access="hasRole('ROLE_USER')"> <%-- Show navigation links --%> </sec:authorize> <sec:authorize access="isAnonymous()"> <%-- Show login form --%> </sec:authorize>@H_404_5@/ app / 404路径映射到只返回视图的控制器.当我浏览到/ foo / some_invalid_id时,NotFoundException从控制器中抛出,最后当它进入JSP时,它在SecurityContext中找不到验证,并且不显示两个选项.相反,当我浏览/ something_that_really_doesnt_exist时,可以弄清楚我是否登录,并呈现适当的HTML.