![](/img/trans.png)
[英]Grails/Spring Security: Unable to login with a newly created user
[英]Grails + Spring Security: unable to login
我剛剛開始學習Grails和Spring,我已經按照官方教程創建了一個登錄系統。 但我無法登錄,“用戶名或密碼不匹配”。 我知道在90%的情況下這是由於雙重編碼或多個數據源(這也導致雙重編碼),但我也沒有做到。
class BootStrap {
def init = { servletContext ->
def adminRole = new SecurityRole(authority: 'ROLE_ADMIN').save(failOnError: true, flush: true)
def userRole = new SecurityRole(authority: 'ROLE_USER').save(failOnError: true, flush: true)
def testUser = new User(username: 'admin', password: 'admin')
testUser.save(failOnError: true, flush: true)
SecurityUserSecurityRole.create testUser, adminRole, true
assert User.count() == 1
assert SecurityRole.count() == 2
assert SecurityUserSecurityRole.count() == 1
println testUser.username
println testUser.password
}
彈簧安全核:2.0 RC2
grails 2.3.3
我在一些項目中遇到了類似的問題,對我來說一直是一個雙重編碼問題。 我使用的是Spring Security Plugin的早期版本,但這種技術可以確保它不會進行雙重編碼。 同樣,我在不同的版本,但可能值得一試。
class User {
// regular generated code should still be included
boolean beforeInsertRunOnce = false
boolean beforeUpdateRunOnce = false
def beforeInsert() {
if (! beforeInsertRunOnce) {
beforeInsertRunOnce = true
encodePassword()
}
}
def afterInsert() {
beforeInsertRunOnce = false
}
def beforeUpdate() {
if (isDirty('password') && ! beforeUpdateRunOnce ) {
beforeUpdateRunOnce = true
encodePassword()
}
}
def afterUpdate() {
beforeUpdateRunOnce = false
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.