0

I have customised grails.plugin.springsecurity.userLookup.usernamePropertyName = "email" but the default rendering behaviour for the email body will fail with:

No such property: username for class

Therefore I customised emailBody in my 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."

because according to the docs:

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.

However, the params map that contains the properties in my MailStrategy is empty for the user.email and url values:

[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.]

Notice the [:] and [:] for the user.email and url values.

The spring-security plugin is configured with these values in 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'

The Account class is defined as:

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`'
}

How can I have the username and more importantly the URL rendered for me so I can send the forgotten password email?

Alex
  • 8,093
  • 6
  • 49
  • 79

1 Answers1

0

GString should start from " not from '

so instead of grails.plugin.springsecurity.ui.forgotPassword.emailBody = '...'

you should use: grails.plugin.springsecurity.ui.forgotPassword.emailBody = "..."

Michal_Szulc
  • 4,097
  • 6
  • 32
  • 59