2012-01-01 86 views
-3

我安裝了Spring Security Plugin(from here)。我非常密切地關注了博客文章here。我也完全一樣在博客中說,但即使當我試圖通過插件登錄,我得到這樣的錯誤:我無法通過Spring Security Plugin登錄

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值。但是我仍然無法登錄,爲什麼?

在此先感謝。

+0

你沒有仔細閱讀博客文章,我想你應該找自己,而不是要求每一個問題上SO的解決方案。 – 2012-01-01 15:23:31

+0

@downvoters:爲什麼downvote? – 2012-01-01 15:29:06

+0

哦,非常抱歉..!我在閱讀時忽略了這部分:(對不起這樣一個愚蠢的問題!) – 2012-01-01 15:35:20

回答

2

該柱具有此更新,其中介紹了爲什麼您的登錄失敗:

更新作爲Spring Security的核心插件的版本1.2,當 實例保存在 生成的用戶類自動編碼的密碼。因此,你不再需要明確地使用 SpringSecurityService.encodePassword()

+0

哦非常抱歉..!我在閱讀時忽略了這部分:(對不起這樣一個愚蠢的問題!!)Thanks @Burt Beckwith sir .. – 2012-01-01 15:34:56