安装了spring-security-core 2.0-RC2(安装了grails 2.3.6),运行了快速入门,但是我无法登录。每次尝试时,我都收到“抱歉,我们找不到用户”使用该用户名和密码。”错误。
做了一些研究,我没有对密码进行双重编码,也没有使用盐(据我所知)。我在其他项目中使用了较早的版本,所以不确定发生了什么。我还从域类中删除了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)
}
}
和我的Bootstrap:
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
对我在做什么错有任何想法吗?
谢谢!
请您参考如下方法:
看起来不错,但是有趣的事情可能在幕后发生。我写了一些博客文章来帮助诊断此类问题。 checkout http://burtbeckwith.com/blog/?p=2003和http://burtbeckwith.com/blog/?p=2029




