Mapping an exception to 404 page while using Spring Security taglibs

吃可爱长大的小学妹 提交于 2019-12-03 13:15:45

Add the following two dispatcher elements to your spring security filter-mapping:

<filter-mapping>
    ...
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

By default only ordinary requests go through a defined filter-mapping.

"INCLUDE" and "FORWARD" are the two other valid dispatcher element values.

The most probable case is that some component in your code is calling HttpSession.invalidate() while exception handling. You can easily find this out by a simple debugging.

But actually it is not necessary to check for isAnonymous() - it is enough to check for user not having ROLE_USER authority:

  • In Spring Security 2: you can use areNotGranted attribute of <sec:authorize> tag (see Spring Security 2 documentation
  • In Spring Security 3: you can use Spring EL for evaluation of negative condition: access="!hasRole('ROLE_USER')"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!