有幾種方法,但這似乎是最乾淨的,並且不需要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