我在Grails應用中使用Spring安全核心插件。我設法安裝插件,並在bootstrap中提供了一個默認的用戶,它工作正常。不過,我想提供在應用程序中創建新用戶(註冊)的選項。什麼是完成這個最好的方法?我試圖在UserController中下面的代碼:用Grails的彈簧安全插件創建用戶
def save = {
def userRole = SecRole.findByAuthority("ROLE_USER")?: new SecRole(authority:"ROLE_USER").save(failOnError:true)
def adminRole = SecRole.findByAuthority("ROLE_ADMIN") ?: new SecRole(authority:"ROLE_ADMIN").save(failOnError:true)
def newUser = new User(
username: params.username,
password: springSecurityService.encodePassword(params.password),
enabled: true)
SecUserSecRole.create newUser, userRole
}
,但它不工作,並拋出了顯示java.lang.NullPointerException。 有什麼建議嗎? 在此先感謝。
謝謝!我完全忘了save() –