我将我的grails 1.0.4 + acegi 0.4.1项目升级为grails 1.1,使用acegi 0.5.1。
我能够毫无错误地启动我的应用程序,但是当我想要登录时,我收到“错误的用户名或密码”消息。 Grails-shell输出是:
2009-04-26 12:38:46,997 [403984690 @ qtp0-0]错误 springsecurity.GrailsDaoImpl - 用户
[admin]没有GrantedAuthority
也许有人知道为什么我无法登录?用户“admin”在Bootstrap中创建。
我希望你能帮助我! 感谢德国, whitenexx
答案 0 :(得分:1)
我遇到了完全相同的问题。检查以确保在BootStrap.groovy中创建用户时,首先使用密码和所有字段创建用户,即使它们是可选的(不确定原因)。然后创建新角色,然后将该人员添加到角色。
检查用户是否被分配到角色的一种方法是查看将用户映射到角色的role_people表。
这是我的BootStrap.groovy文件:
class BootStrap {
// include this line to encode password for ACEGI
def authenticateService
def init = { servletContext ->
//create admin user
def password = authenticateService.passwordEncoder("password")
def superadmin = new User(username:"admin",userRealName:"Administrator",passwd:password,enabled:true,emailShow:true,description:"admin user",email:"put email here").save()
//create admin role
def sudo = new Role(authority:"ROLE_ADMIN",description:"Site Administrator")
// now add the User to the role
sudo.addToPeople(superadmin)
sudo.save()
new Role(authority:"ROLE_USER",description:"User").save()
}
def destroy = {
}
}
答案 1 :(得分:0)
我发现了自己的问题。我必须自己编辑/编码passwordEncoder()或encodePassword()方法(使用我的算法等)。不推荐使用passwordEncoder(),请使用encodePassword()!
答案 2 :(得分:0)
我曾使用acegi并遇到过类似的问题。如果您使用acegi的编码默认值,请致电passwordEncoder()
。否则,您应该致电encodePassword()
。