安裝了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
任何想法我做錯了什麼?
謝謝!
你會請你驗證你的引導數據。例如通過在保存調用中添加''failOnError:true''或通過查看數據庫(例如使用gracon的dbconsole)。只是爲了保存它。 – cfrick
我已通過檢查數據庫驗證了保存調用正在工作。 –