我在这个 Grails 项目中使用 Spring Security 核心。我收到错误“密码”无法在 BootStrap 类中解决。
我有这个域类:
class Person {
transient springSecurityService
String realName
String username
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static constraints = {
username blank: false, unique: true
password blank: false
}
static mapping = {
password column: '`password`'
}
Set<Authority> getAuthorities() {
PersonAuthority.findAllByPerson(this).collect { it.authority } as Set
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}
}
这是我的 BootsStrap 类:
class BootStrap {
def init = { servletContext ->
if (!Person.count()) {
createData()
}
}
def destroy = {
}
private void createData() {
def userRole = new Authority(authority: 'ROLE_USER').save()
[harry: 'Harry Brock'].each { userName, realName ->
def user = new Person(username: userName, realName: realName, password: password, enabled: true).save()
PersonAuthority.create user, userRole, true
}
}
}
我正在使用 Grails 2.2 和 Spring Security Core 1.2.7.3