My User domain class extends SecUser.
User has a property 'email'.
Spring security uses SecUser's 'username' to login.
I need to use 'email' to login. Is there a way to do this?
Edit (from the accepted answer):
I deleted SecUser's username property and added email property.
Then I added this line to Config.groovy:
grails.plugins.springsecurity.userLookup.usernamePropertyName = 'email'
RTFM my friend :)
userLookup.usernamePropertyName 'username' User class username field
Add to Config.grooy:
grails.plugins.springsecurity.userLookup.usernamePropertyName='email'
newer versions of grails are using a prefix of
grails.plugin.springsecurity
instead of grails.plugins.springsecurity
If you're also using the Spring Security UI plugin be aware that the default text for forgotten password and user registration emails reference the username field.
You can override them like this:
grails.plugins.springsecurity.ui.register.emailBody = 'Hi \$user.firstName...'
grails.plugins.springsecurity.ui.forgotPassword.emailBody = 'Hi \$user.firstName...'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.