isAnonymous()和isAuthenticated()都在错误页面上返回false [英] Both isAnonymous() and isAuthenticated() return false on error page
问题描述
我有一个错误页面,当返回404响应状态时会显示该页面。
这个页面是由模板机制生成的(我用的是瓷砖);在这个模板中,我有一个包含类似内容的标题:
I have an error page which is displayed when a 404 response status is returned. This page is generated thanks to a template mechanism (I use tiles); In this template, I have a header that contains something like that :
<sec:authorize access="isAnonymous()">
blabla
</sec:authorize>
<sec:authorize access="isAuthenticated()">
blibli
</sec:authorize>
因此,根据用户是否经过身份验证,它会显示blibli或blabla。此代码适用于使用此模板的所有页面,但我的404页面除外!没有显示任何内容!
So, depending on if the user is authenticated, it displays blibli or blabla. This code works for all pages that use this template except for my 404 page! It displays nothing!
任何想法??
推荐答案
我'我敢打赌,问题在于如何在 web.xml
中定义 filter-mapping
。最常见的配置是:
I'll bet that problem lies in how you define filter-mapping
in web.xml
. Most common configuration is:
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这会将过滤器映射到所有URL,但仅当它们通过 REQUEST
方法。所有其他情况(如 INCLUDE
, FORWARD
和 ERROR
)没有被这个过滤器抓住。因此,要将过滤器绑定到 ERROR
请求,请将其定义为
This maps filter to all URLs, but only when they accessed by REQUEST
method. All other cases (like INCLUDE
, FORWARD
and ERROR
) not catched by this filter. So to bind filter to ERROR
requests, define it as
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<!-- apply Spring Security authentication to error-pages -->
<dispatcher>ERROR</dispatcher>
</filter-mapping>
试一试。如果不起作用,则添加< dispatcher> INCLUDE< / dispatcher>
因为Tiles,可能包含这样的页面。
Try it. If not works then add <dispatcher>INCLUDE</dispatcher>
because Tiles, probably includes pages by this way.
另见:
这篇关于isAnonymous()和isAuthenticated()都在错误页面上返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!