When mapping an Exception to 404 page, the Spring Security tags can\'t find the authentication information from the security context. With a \"real\" 404 the authentication is f
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:
areNotGranted
attribute of <sec:authorize>
tag (see Spring Security 2 documentationaccess="!hasRole('ROLE_USER')"