Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 为什么Spring安全认证会给出null_Spring Mvc_Spring Security - Fatal编程技术网

Spring mvc 为什么Spring安全认证会给出null

Spring mvc 为什么Spring安全认证会给出null,spring-mvc,spring-security,Spring Mvc,Spring Security,我的Tomcat下有以下网站(都使用SpringMVC) 以及我的HTTPErrorController中的方法 @RequestMapping(value = "/errors/404.html") public String handle404(HttpServletRequest request, Exception e) { logger.error(e.getMessage()); Authentication authentication =

我的Tomcat下有以下网站(都使用SpringMVC)

以及我的HTTPErrorController中的方法

@RequestMapping(value = "/errors/404.html")
    public String handle404(HttpServletRequest request, Exception e) {
        logger.error(e.getMessage());
        Authentication authentication = SecurityContextHolder.getContext()
                .getAuthentication();
        return authentication == null ? defaultPage : defaultAuthorizedPage;
        // return defaultAuthorizedPage;
    }
春季安全

<intercept-url pattern="/*" access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN','ROLE_ANONYMOUS')"
            requires-channel="https" />
<intercept-url pattern="/member/**" access="isFullyAuthenticated()"
            requires-channel="https" />

现在,如果用户已登录并尝试访问不存在的页面,则应将其重定向到
www.example.com/member/home
(默认授权页面),而普通用户/来宾应重定向到主页
www.example.com/home
(默认页面)


问题是身份验证始终为空,因此我无法确定用户是否已登录。对此我应该怎么做?

如果您希望保护容器管理的错误页面/包括Spring Security的SecurityContext,则需要确保包括springSecurityFilterChain的错误请求调度程序。例如,web.xml中的以下内容

<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>ERROR</dispatcher>
</filter-mapping>

springSecurityFilterChain
/*
要求
错误

它可以工作,谢谢。我在哪里可以找到有关此调度器的信息?这是Servlet2.4规范的一部分。请参阅SRV.6.2.5筛选器和PS的RequestDispatcher:我不建议在包含或转发上进行筛选,因为这将使您的生活变得不必要的复杂化—良好的查找!!只是想知道在这里添加请求的目的是什么。
<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>ERROR</dispatcher>
</filter-mapping>