getAuthentication() when error-page 404 is shown in the Spring.
in web.xml. < error-page > < error-code > 404 </ error-code > < location > /WEB-INF/pages/errors/error404.jsp </ location > </ error-page > In error404.jsp, don't get user message by using SecurityContextHolder.getContext().getAuthentication(). Solution: <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> <...