我无法通过Spring Security Plugin登录

时间:2012-01-01 14:50:46

标签: grails

我安装了Spring Security Plugin(from here)。我非常密切地关注了博客文章here。我做的与博客文章中说的完全一样,但即使我尝试通过插件登录,我也会收到这样的错误:

Sorry, we were not able to find a user with that username and password.

这是我的BootStrap.groovy文件:

 def springSecurityService
    def init = { 
            def userRole = SecRole.findByAuthority('ROLE_USER') ?: new SecRole(authority: 'ROLE_USER').save(failOnError: true)
            def adminRole = SecRole.findByAuthority('ROLE_USER') ?: new SecRole(authority: 'ROLE_USER').save(failOnError: true)     
            def adminUser = SecUser.findByUsername('antoaravinth') ?: new SecUser(
                    username: 'antoaravinth',
                    password: springSecurityService.encodePassword('secret'),
                    enabled: true).save()

                if (!adminUser.authorities.contains(adminRole)) {
                    SecUserSecRole.create adminUser, adminRole
                }
            println "adminUser is $adminUser"
            println "adminRole is $adminRole"
}

当我尝试grails run-app时,我可以看到我的控制台上打印了adminUseradminRole值。但我还是无法登录。为什么?

提前致谢。

1 个答案:

答案 0 :(得分:2)

帖子有此更新,说明登录失败的原因:

  

更新从Spring Security Core插件的1.2版开始,   生成的User类在自动编码时自动编码   实例已保存。因此,您不再需要明确使用   SpringSecurityService.encodePassword()