Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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
Java 在Spring Security中检查现有的HttpSession_Java_Spring_Spring Mvc_Spring Security - Fatal编程技术网

Java 在Spring Security中检查现有的HttpSession

Java 在Spring Security中检查现有的HttpSession,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,是否可以通过检查Spring Security中现有的HttpSession对用户进行身份验证?我希望用户在一个URL上通过CAS进行身份验证(http://example.com/auth),但不是其他URL。例如,如果他们直接转到,那么我想检查HttpSession,如果他们还没有登录CAS,则返回401未经授权的代码。如果他们已经转到/auth页面并登录,则转到/content将返回内容。这样做的主要原因是为了避免CAS在身份验证期间引起的任何重定向 我是Spring Security的新

是否可以通过检查Spring Security中现有的HttpSession对用户进行身份验证?我希望用户在一个URL上通过CAS进行身份验证(http://example.com/auth),但不是其他URL。例如,如果他们直接转到,那么我想检查HttpSession,如果他们还没有登录CAS,则返回401未经授权的代码。如果他们已经转到/auth页面并登录,则转到/content将返回内容。这样做的主要原因是为了避免CAS在身份验证期间引起的任何重定向

我是Spring Security的新手,不知道我是否需要自定义AuthenticationManager、AuthenticationEntryPoint,两者都需要,还是其他什么。AuthenticationManager无法让我访问HttpSession,AuthenticationEntryPoint似乎不是实现此功能的正确位置


有什么想法吗?

Spring安全性没有使用HTTP会话。 相反,您可以轻松调用此静态方法:

SecurityContextHolder.getContext().getAuthentication();

坦率地说,我认为您需要正确配置Spring安全性,以避免检查身份验证并手动重定向到其他页面

是的,我通常会“正确”配置Spring安全性,但我遇到这样一种情况:当会话不存在时,我需要阻止某些页面上的CAS重定向。我应该在哪里检查getAuthentication()方法?我会在Spring Security中使用某种过滤器吗?