2

我无法使用 spring security 和 dynamodb 将我的用户登录到 grails 应用程序。

Grails 是 2.1,安装的插件是 spring-security core 和 dynamodb 最新的。

用户和角色由 s2-quickstart 创建,它唯一的修改是向用户、角色和用户角色类添加 String id 和静态 mapWith = "dynamodb"(需要字符串 id,因为 dynamodb 上的 id 是 UUID 生成的)

Bootstrap 是按照 spring 安全教程。

应用程序启动良好,并创建了 dynamodb 表和行。

我不断得到

身份验证失败:密码与存储的值不匹配

通过在 LoginController 上登录(我没有从教程中设置示例控制器)。有任何想法吗?

4

1 回答 1

0

如果您配置了多个数据源,我猜您会这样做,因为您使用了 mapWith,beforeUpdate 块将被调用不止一次。(每个数据源一次)我将以下内容添加到我的用户域对象中,它可以正常工作。

transient hasBeforeInsert = false
transient hasBeforeUpdate = false

...

  def beforeInsert()
  {
    if(!hasBeforeInsert)
    {
      hasBeforeInsert = true
      encodePassword()
    }
  }

  def beforeUpdate()
  {
    if(!hasBeforeUpdate)
    {
      hasBeforeUpdate = true

      if(isDirty('password'))
      {
        encodePassword()
      }
    }
于 2012-08-27T17:49:21.850 回答