spring - Grails "remember me"不工作

标签 spring grails spring-security

我正在使用Grails Spring Security Plugin 2.0 RC2 .

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

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

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

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

最佳答案

这困扰了我一整天,但我使用的是 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] DEBUG rememberme.TokenBasedRememberMeServices - Remember-me cookie detected

2014-01-21 13:10:59,545 [http-bio-8080-exec-3] DEBUG rememberme.TokenBasedRememberMeServices - Remember-me cookie accepted

2014-01-21 13:10:59,582 [http-bio-8080-exec-3] DEBUG rememberme.RememberMeAuthenticationFilter - SecurityContextHolder not populated with remember-me token, as AuthenticationManager rejected Authentication returned by RememberMeServices: 'org.springframework.security.authentication.RememberMeAuthenticationToken@7651888e: Principal: org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser@d008d6e3: invalidating remember-me token

Message: No AuthenticationProvider found for org.springframework.security.authentication.RememberMeAuthenticationToken

2014-01-21 13:10:59,638 [http-bio-8080-exec-3] DEBUG rememberme.TokenBasedRememberMeServices - Interactive login attempt was unsuccessful.

2014-01-21 13:10:59,638 [http-bio-8080-exec-3] DEBUG rememberme.TokenBasedRememberMeServices - Cancelling cookie

仅供引用,删除 JSESSIONID cookie 本质上与关闭浏览器相同:http://muras.eu/index.html%3Fp=673.html

希望有帮助!

关于spring - Grails "remember me"不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20924790/

相关文章:

java - Spring 多属性占位符和 SPEL 顺序无关

spring - Grails:错误org.springframework.boot.SpringApplication-应用启动失败

grails - Sendgrid将电子邮件添加到列表,grails中收到错误的请求

java - Spring Security - antMatcher 的 POST 方法(不是 antMatchers)

java - spring中如何在html和jsp页面之间导航

Spring Data REST 的 QueryDSL 集成,用于查询实体中集合映射的子属性

spring-mvc - SecurityContextHolder.getContext().getAuthentication().getPrincipal() 在 Controller 上为 null

spring-boot - 使用 spring-boot-starter-oauth2-client 检索 OAuth2 3 足身份验证的访问 token

spring - FileSystemPersistentAcceptOnceFileListFilter 与 CompositeFileListFilter 不兼容

json - Grails 无法将 JSON 数组转换为 HashMap