grails spring security工作不正常

时间:2013-05-12 11:29:32

标签: grails grails-plugin grails-2.0

我已经为我的项目安装了spring-security-core插件用于登录安全性。安装后一切正常,例如如果account_locked = true则显示帐户被锁定的消息,如果启用= false则显示帐户未启用。但是当一切正常时,它会显示"抱歉,我们无法找到具有该用户名和密码的用户"。虽然我有这个用户名和密码。有人可以帮我这个吗?

这是我的创建操作>>>

def createUser = {
    def user = new User()
    user.properties = params
    println(user.username)
    def password = user.password
    def salt = user.username //depends on what you're using as a salt
    user.password = springSecurityService.encodePassword(password, salt)
    user.save()
}

1 个答案:

答案 0 :(得分:1)

要插入用户对象,您需要加密密码字段,例如:

def springSecurityService

def someAction() {
   def user = ...
   def password = ...
   def salt = user.username //depends on what you're using as a salt
   user.password = springSecurityService.encodePassword(password, salt)
   user.save()      
}

请参阅插件文档:http://grails-plugins.github.io/grails-spring-security-core/docs/manual/guide/12%20Password%20and%20Account%20Protection.html

Salt用于打败预先计算的彩虹表攻击,否则可以用来大大提高破解密码数据库的效率。见http://en.wikipedia.org/wiki/Salt_(cryptography)