我刚刚开始学习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
圣杯 2.3.3
我在一些项目中遇到过类似的问题,这对我来说一直是一个双重编码问题。我使用的是 Spring Security 插件的早期版本,但这种技术可以确保它不会双重编码。再说一遍,我使用的是不同的版本,但可能值得一试。
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)
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)