最近刚开始在 Groovy 中编程并且已经卡住了。我正在尝试创建可用于在我的引导程序中登录的用户,我已经看过许多教程,尽管复制和粘贴代码,我还是遇到了许多错误。我现在已经开始编写似乎可以运行但用户根本不存在的代码。
我究竟做错了什么?
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 = {}
}
能帮上忙的都是传奇!