我正在开发一个Spring MVC Web应用程序,并配置了Spring Security来拦截所有URL并对其进行身份验证。如果用户勾选"记住我",则自动登录用户而不重定向到登录页面。
比如说,我的登录网址是
example.com/signin
主页是
example.com/home
当用户输入任何指向需要身份验证的有效网页(例如 example.com/home)的 URL 时,如果启用了"记住我",他将被定向到该特定网页,而无需再次进行身份验证。
但是当用户输入 example.com/signin 时,它只会显示登录表单,即使他已经过身份验证并记住。
如果他是经过身份验证且启用了 remmeber-me 的用户而不显示登录页面,我如何将他重定向到主页(example.com/home?
这些链接可能会帮助您使用 Spring 安全性实现"记住我"。
http://docs.spring.io/spring-security/site/docs/3.0.x/reference/remember-me.htmlhttp://www.mkyong.com/spring-security/spring-security-remember-me-example/
我添加了对控制器的重定向。请让我知道这是否是正确的方法。
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
//if the user is already authenticated redirect him to the dashboard
if(!(auth instanceof AnonymousAuthenticationToken)){
return "redirect:dashboard";
}
return "signin";