I am using Spring Security core on this Grails project. I get the error “password” cannot be resolve in the BootStrap class.
I have this domain class:
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)
}
}
and this is my BootsStrap class:
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
}
}
}
I am using Grails 2.2 and Spring Security Core 1.2.7.3
Within BootStrap you are using a undefined variable named
password.I added a comment above the line with the problem: