最新的spring-security-core与spring-security-ui 0.1.2是不兼容的。特别是,spring-security-core将密码编码移入User
类中的事件处理程序中的beforeInsert
/beforeUpdate
。 RegisterController.register
spring-security-ui中的控制器还不知道,并尝试再次对其进行编码,从而产生双重编码的密码。要修复,覆盖RegisterController
,改变register
行动:
def register = { RegisterCommand command ->
if (command.hasErrors()) {
render view: 'index', model: [command: command]
return
}
def user = lookupUserClass().newInstance(email: command.email, username: command.username,
password: command.password, accountLocked: true, enabled: true)
if (!user.validate() || !user.save()) {
// TODO
}
def registrationCode = new RegistrationCode(username: user.username).save()
String url = generateLink('verifyRegistration', [t: registrationCode.token])
def conf = SpringSecurityUtils.securityConfig
def body = conf.ui.register.emailBody
if (body.contains('$')) {
body = evaluate(body, [user: user, url: url])
}
mailService.sendMail {
to command.email
from conf.ui.register.emailFrom
subject conf.ui.register.emailSubject
html body.toString()
}
render view: 'index', model: [emailSent: true]
}
这个问题正在跟踪的http://jira.grails.org/browse/GPSPRINGSECURITYUI-27。
关于你的第二个问题,你可以像对待任何其他域对象一样对待你的User类。
非常感谢!解决了这个问题 – drago
只需将行grails.plugins.springsecurity.ui.encodePassword = false添加到Config.groovy即可防止双重编码 –