剛剛在Groovy中開始編程並已停滯不前。我正在嘗試創建可在我的引導程序中登錄的用戶,我已經看到了大量的教程,儘管複製和粘貼代碼讓我受到無數次錯誤的迎接。我現在已經開始關注似乎運行的代碼,但用戶根本就不在那裏。使用SpringSecurityCore引導程序
我在做什麼錯?
import grails.timesecurity.*
import timetracker2.*
class BootStrap {
def springSecurityService
def init = { servletContext ->
def examples = [
'rob' : [username: 'rob', password: 'password']
]
def userRole = Authority.findByAuthority("ROLE_USER") ?: new Authority(authority: "ROLE_USER").save()
def adminRole = Authority.findByAuthority("ROLE_ADMIN") ?: new Authority(authority: "ROLE_ADMIN").save()
if(!Person.count())
{
userRole = new Authority(authority: 'ROLE_USER').save()
//String password = springSecurityService.encodePassword('password')
def user = new Person(
username: "Rob",
password: springSecurityService.encodePassword("Password"),
enabled: true
)
PersonAuthority.create user, userRole
//def user = new Person['Rob', password, enabled: true].save()
}
}
def destroy = {}
}
任何人都可以幫忙的是一個傳奇!
你真棒,謝謝 – user1854751