grails - Grails 3 Spring Security UI忘记密码空白URL和用户

标签 grails spring-security grails-3.1

我已经自定义了grails.plugin.springsecurity.userLookup.usernamePropertyName = "email",但是电子邮件正文的默认呈现行为将失败,并显示以下内容:
No such property: username for class
因此,我在emailBody中自定义了application.groovy:
grails.plugin.springsecurity.ui.forgotPassword.emailBody = "Dear ${user.email} , Please follow <a href='${url}'>this link</a> to reset your password. This link will expire shortly."
因为根据文档:

The emailBody property should be a GString and will have the User domain class instance in scope in the user variable, and the generated url to click to reset the password in the url variable.



但是,对于MailStrategyuser.email值,包含在url中的属性的参数映射为空:
[to:blah@blah.com, 
 from:no-reply@blah.com, subject:Reset your password for your account,
 html:Dear [:], Please follow <a href='[:']>this link</a> to reset your password. This link will expire shortly.]

请注意[:][:]值的user.emailurl

spring-security插件在application.groovy中配置了以下值:
grails.plugin.springsecurity.userLookup.userDomainClassName = 'blah.Account' 
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'blah.AccountRole' 
grails.plugin.springsecurity.authority.className = 'blah.Role' 
grails.plugin.springsecurity.requestMap.className = 'blah.Requestmap'     
grails.plugin.springsecurity.securityConfigType   = 'Annotation'
Account类定义为:
String email
String password
Date emailVerified = null
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired

Set<Role> getAuthorities() {
    AccountRole.findAllByAccount(this)*.role
}

def beforeInsert() {
    encodePassword()
}

def beforeUpdate() {
    if (isDirty('password')) {
        encodePassword()
    }
}

protected void encodePassword() {
    password = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
}

static transients = ['springSecurityService']

static constraints = {
    password blank: false, password: true
    email blank: false, unique: true
    emailVerified nullable: true
}

static mapping = {
    password column: '`password`'
}

如何获得用户名以及更重要的是为我呈现的URL,以便可以发送被忘记的密码电子邮件?

最佳答案

GString应该从开始“” 而不是'

因此,而不是grails.plugin.springsecurity.ui.forgotPassword.emailBody = '...'
您应该使用:grails.plugin.springsecurity.ui.forgotPassword.emailBody = "..."

关于grails - Grails 3 Spring Security UI忘记密码空白URL和用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38904123/

相关文章:

grails - 为什么 Gradle 会降级 Grails 3.1 应用程序中的传递依赖项?

java - 为什么 Spring SAML 阻止 Spring OAuth2 工作?

maven - Grails 3.2.9自定义插件依赖项

grails - 如何在 Grails websocket 插件中启用跨源请求

unit-testing - 单元测试和重构现有 Grails 应用程序的策略

java - Spring 通过自定义身份验证提供程序记住我

spring-security - 带有 EhCache 3 的 Spring Security ACL

grails 错误 : grails. 验证。Validateable 不是 @grails.validation.Validateable 中的注释

rest - grails 3 Rest-api 配置文件 GET

Grails 与 joinTable 的一对多映射