2012-12-21 2 views
1

이 Grails 프로젝트에서 Spring Security 코어를 사용하고 있습니다. 나는 "비밀 번호"는 BootStrap 클래스에서 해결할 수없는 오류가 발생합니다.Grails 프로젝트에서 심볼을 확인할 수 없습니다.

나는이 도메인 클래스가 있습니다

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 
    } 
} 
} 

내가 1.2.7.3

답변

2

부트 스트랩 당신 내에서 Grails는 2.2 스프링 시큐리티 코어를 사용하고 있습니다 정의되지 않은 변수 password을 사용하고 있습니다.

String password  //apparently it missed, but the other 3 are also needed 
boolean accountExpired 
boolean accountLocked 
boolean passwordExpired 

그래서이 같은 userInstance을 저장 : 당신이 사용자 개체를 인스턴스화 할 때

[harry: 'Harry Brock'].each { userName, realName -> 
    // userName and realName are closure parameters, enabled is always true.. but where is password defined? 
    def user = new Person(username: userName, realName: realName, password: password, enabled: true).save() 
    PersonAuthority.create user, userRole, true 
} 
+0

감사합니다. 암호를 암호로 설정하려고했습니다. 나는 이렇게했다 : password : "password" –

0

이러한 모든 특성이 null 일 수 없습니다 :

가 나는 문제가있는 라인 위의 코멘트를 추가 :

def user = new Person(username: userName, realName: realName, password: password, enabled: true, accountExpired:false, accountLocked:false, passwordExpired:false).save() 

또는 beforeInsert()에 부울 속성을 넣어 간단하게 할 수 있습니다. 코드 :

def beforeInsert() { 
    enabled=true 
    accountExpired=false 
    accountLocked=false 
    passwordExpired=false 
    encodePassword() 
} 
관련 문제