【问题标题】:Spring Security Remember MeSpring Security 记住我
【发布时间】:2015-05-10 15:40:58
【问题描述】:

我正在开发一个 Spring MVC Web 应用程序,并已将 Spring Security 配置为拦截所有 URL 并对其进行身份验证。如果用户勾选了“记住我”,则用户自动登录,无需重定向到登录页面。

说,我的登录网址是

example.com/signin

首页是

example.com/home

当用户输入任何需要身份验证的有效网页(例如 example.com/home)的 URL 时,如果启用了记住我,他将被定向到该特定网页而无需进行身份验证再次。

但是当用户进入 example.com/signin 时,即使他已经通过身份验证并被记住,它也只会显示登录表单。

如果他是已通过身份验证并启用 remmeber-me 的用户,我如何将他重定向到主页(example.com/home)而不显示登录页面?

【问题讨论】:

    标签: java spring spring-mvc authentication spring-security


    【解决方案1】:

    【讨论】:

    • 我已经实现了remember-me。我已经在问题中提到了确切的用例。请看一看。
    • 您在使用 http 安全性和表达式吗?您在拦截 url 时查看过配置 isFullyAuthenticated() 吗?
    【解决方案2】:

    我向控制器添加了重定向。请让我知道这是否是正确的方法。

    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";
    

    【讨论】:

      猜你喜欢
      • 2012-01-21
      • 2014-09-04
      • 2018-12-02
      • 2017-11-15
      • 2012-03-13
      • 2016-01-31
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      相关资源
      最近更新 更多