Grails Spring Security记得我

时间:2011-12-15 18:02:09

标签: grails spring-security

我有一个针对REST API的自定义身份验证提供程序,现在想要实现记住我功能。

以下是我在Config.groovy中的内容:

grails.plugins.springsecurity.providerNames = [
   'zubAuthenticationProvider',
   'rememberMeAuthenticationProvider'
]
grails.plugins.springsecurity.auth.loginFormUrl="/login"
grails.plugins.springsecurity.rememberMe.cookieName="example1"
grails.plugins.springsecurity.rememberMe.key="example1"

我无法在成功登录时看到实际设置的cookie。我在配置中遗漏了什么吗?

**更新** 如果我添加:

,我可以创建一个cookie
grails.plugins.springsecurity.rememberMe.persistent = true

但是,这只会导致另一个不使用数据库进行登录存储的问题。

提前致谢, 托德

1 个答案:

答案 0 :(得分:3)

为了后人,我将使用以下内容 -

<强> Config.groovy中

grails.plugins.springsecurity.providerNames = [
   'zubAuthenticationProvider',
   'rememberMeAuthenticationProvider'
]

grails.plugins.springsecurity.rememberMe.cookieName="stackoverflow"
grails.plugins.springsecurity.rememberMe.key="_grails_"
grails.plugins.springsecurity.rememberMe.rememberMe.persistent = true

<强> CONF /弹簧/ resources.groovy

userDetailsService(com.zub.security.EgUserDetailsService) {
   grailsApplication = ref('grailsApplication')
}
tokenRepository(com.zub.security.EgPersistentTokenRepository) {
    grailsApplication = ref('grailsApplication')
}

def conf = SpringSecurityUtils.securityConfig
rememberMeServices(PersistentTokenBasedRememberMeServices) {
    userDetailsService = ref("userDetailsService")
    key = conf.rememberMe.key
    cookieName = conf.rememberMe.cookieName
    alwaysRemember = conf.rememberMe.alwaysRemember
    tokenValiditySeconds = conf.rememberMe.tokenValiditySeconds
    parameter = conf.rememberMe.parameter
    useSecureCookie = conf.rememberMe.useSecureCookie // false

    tokenRepository = ref('tokenRepository')
    seriesLength = conf.rememberMe.persistentToken.seriesLength // 16
    tokenLength = conf.rememberMe.persistentToken.tokenLength // 16
}

EgPersistentTokenRepository基于GormPersistentTokenRepository,但已更新为对CRUD功能而不是GORM进行REST调用。