有几种方法,但这似乎是最干净的,并且不需要Config.groovy更改。
更改持久密码属性为另一个名字像你这样(userPasswd),但放在一个getter方法getPassword来(),该插件将使用和字节数组转换为字符串有:
class User {
String username
byte[] userPasswd
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static constraints = {
username blank: false, unique: true
password blank: false
}
static transients = ['password']
String getPassword() {
userPasswd ? new String(userPasswd) : null
}
Set<Role> getAuthorities() {
UserRole.findAllByUser(this).collect { it.role } as Set
}
}
将“密码”添加到瞬态列表非常重要,因为真正的持久字段是userPasswd。
这会影响您创建用户的方式,例如
def user = new User(username: 'me', enabled: true,
passwd: springSecurityService.encodePassword('password').bytes).save()
有意义。谢谢Burt。感谢您花时间。 – sul 2011-02-26 09:34:23