【问题标题】:Grails "remember me" not workingGrails“记住我”不起作用
【发布时间】:2014-01-22 08:53:57
【问题描述】:

我正在使用Grails Spring Security Plugin 2.0 RC2

当我通过在登录表单中添加复选框来启用(开箱即用的)功能时。

cookie 已正确创建(时间提前 2 周),但记住我的机制在两种情况下不起作用:

  • 当我关闭浏览器时,记住我的 cookie 消失。为什么?
  • 当我删除 JSESSIONID cookie 时,会话不会重新生成。

另外:我不想使用需要在数据库中存储令牌的持久记住我。我想依靠基于 cookie 的记住我的策略。

【问题讨论】:

  • 我在询问之前看到了这篇文章,但正如我所提到的:我不想使用需要在数据库中存储令牌的持久记住我。我想依靠基于 cookie 的记住我的策略。在这篇文章中使用了令牌存储库。

标签: spring grails spring-security


【解决方案1】:

这困扰了我一整天,但我使用的是 Spring Security Plugin 1.2.7.3。

对我来说,配置中缺少身份验证提供程序。例如:

grails.plugins.springsecurity.providerNames = [
      'rememberMeAuthenticationProvider',
      'daoAuthenticationProvider',
      'ldapAuthProvider',
      'anonymousAuthenticationProvider']

'rememberMeAuthenticationProvider' 是缺少的链接。我在设置日志级别以跟踪与我正在做的事情相关的所有事情时发现了这一点:

trace 'org.springframework.security.web.authentication.rememberme',
      'org.springframework.security.web.authentication',
      'org.springframework.security.web',
      'org.springframework.security'

我在输出中看到了这个(注意粗体):

2014-01-21 13:10:59,490 [http-bio-8080-exec-3] 调试 rememberme.TokenBasedRememberMeServices - 检测到记住我的 cookie

2014-01-21 13:10:59,545 [http-bio-8080-exec-3] 调试 rememberme.TokenBasedRememberMeServices - 接受记住我的 cookie

2014-01-21 13:10:59,582 [http-bio-8080-exec-3] 调试 rememberme.RememberMeAuthenticationFilter - SecurityContextHolder 不是 填充了记住我的令牌,因为 AuthenticationManager 被拒绝 RememberMeServices 返回的身份验证: 'org.springframework.security.authentication.RememberMeAuthenticationToken@7651888e: 主要的: org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser@d008d6e3: 使记住我的令牌无效

消息:找不到 org.springframework.security.authentication.RememberMeAuthenticationToken 的 AuthenticationProvider

2014-01-21 13:10:59,638 [http-bio-8080-exec-3] 调试 rememberme.TokenBasedRememberMeServices - 交互式登录尝试 失败了。

2014-01-21 13:10:59,638 [http-bio-8080-exec-3] 调试 rememberme.TokenBasedRememberMeServices - 取消 cookie

作为参考,删除 JSESSIONID cookie 本质上与关闭浏览器相同:http://muras.eu/index.html%3Fp=673.html

希望有帮助!

【讨论】:

  • "删除 JSESSIONID cookie 本质上与关闭浏览器相同" 这为我节省了很多费用,因为现在我有一个快速的方法来测试记住我的功能(无需等待小时)
【解决方案2】:

让我印象深刻的是,我还为某些登录安装了 Spring Security Open ID 插件。这会将记住我的功能更改为SpringSecurityOpenidGrailsPlugin 文件中的无操作,除非您使用持久性rememberMe

if (!conf.rememberMe.persistent) {
    // auth is external, so no password, so regular cookie isn't possible
    rememberMeServices(NullLogoutHandlerRememberMeServices)
}

如果您在GrailsRememberMeAuthenticationFilter 中调试并看到注入的rememberMeServices 对象是NullLogoutHanderlRememberMeServices 对象,您就知道发生了什么。该版本的所有操作都是无操作的。

您希望内存中的TokenBasedRememberMeServices 或持久的PersistentTokenBasedRememberMeServices 能够实际工作。

【讨论】:

    猜你喜欢
    • 2023-03-11
    • 1970-01-01
    • 2022-12-15
    • 2014-03-13
    • 2012-01-21
    • 2019-09-07
    • 1970-01-01
    • 2015-01-24
    • 2015-10-10
    相关资源
    最近更新 更多