2014-03-26 152 views
1

安裝了spring-security-core 2.0-RC2(帶有grails 2.3.6),跑起來很快,但我無法登錄。每次嘗試時,我都會得到'抱歉,我們無法找到具有該用戶名和密碼的用戶。'錯誤。Grails Spring Security Core無法登錄

做了一些研究,我沒有雙重密碼編碼,或者我也沒有使用鹽(從我可以告訴)。我在其他項目中使用過早期版本,所以不知道發生了什麼。我也從域類扔下encodePassword(),並在數據庫中驗證了這就是我希望它是

這裏是我的用戶域類:

class User { 

transient springSecurityService 

String username 
String password 
boolean enabled = true 
boolean accountExpired 
boolean accountLocked 
boolean passwordExpired 

static transients = ['springSecurityService'] 

static constraints = { 
    username blank: false, unique: true 
    password blank: false 
} 

static mapping = { 
    password column: '`password`' 
} 

Set<Role> getAuthorities() { 
    UserRole.findAllByUser(this).collect { it.role } as Set 
} 

def beforeInsert() { 
    encodePassword() 
} 

def beforeUpdate() { 
    if (isDirty('password')) { 
     encodePassword() 
    } 
} 

protected void encodePassword() { 
    password = springSecurityService.encodePassword(password) 
} 
} 

和我的引導:

def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true) 
def userRole = new Role(authority: 'ROLE_USER').save(flush: true) 

def testUser = new User(username: 'me', password: 'me') 
testUser.save(flush: true) 

UserRole.create testUser, adminRole, true 
UserRole.create testUser, userRole, true 

任何想法我做錯了什麼?

謝謝!

+0

你會請你驗證你的引導數據。例如通過在保存調用中添加''failOnError:true''或通過查看數據庫(例如使用gracon的dbconsole)。只是爲了保存它。 – cfrick

+0

我已通過檢查數據庫驗證了保存調用正在工作。 –

回答

2

看起來很好,但有趣的事情可能會發生在引擎蓋下。我寫了一些博客文章來幫助診斷這樣的問題。檢查出http://burtbeckwith.com/blog/?p=2003http://burtbeckwith.com/blog/?p=2029

+0

謝謝伯特! 原來我使用的mongo插件是錯誤的根源。啓用日誌記錄並使用事件偵聽器爲我提供了找出根本原因所需的詳細信息。 –

+0

很酷。如果您正在使用Mongo,您可能還想查看http://burtbeckwith.com/blog/?p=1992 –

相關問題