【问题标题】:def user=User.findByUserIdAndPassword(params.userId,params.password) is null ?? IN GRAILSdef user=User.findByUserIdAndPassword(params.userId,params.password) 为空??在圣杯中
【发布时间】:2012-05-10 01:25:43
【问题描述】:

def user=User.findByUserIdAndPassword(params.userId,params.password) 即使在成功注册后仍为空...我正在使用 Spring Security。

我的用户域类是

class User {

   transient springSecurityService

   Integer id 
   String userId
   String password
   byte[] photo
   String fullName
   String bio
   String email
   String address
   String username

   boolean enabled
   boolean accountExpired
   boolean accountLocked
   boolean passwordExpired

   static hasMany = [places: Place, badges: Badge, checkIns:CheckIn, friend:User]

   static belongsTo = Place

   String toString(){
      "$userId"
   }

   static constraints = {
      fullName(nullable: true,maxSize:20,matches:"[a-zA-Z\40-\176]+")
      bio(nullable: true, maxSize: 100,matches:"[a-zA-Z\40-\176]+")
      email(email: true, blank: false)
      photo(nullable: true,maxSize:1000000)
      address( nullable:true,maxSize:40,matches:"[a-zA-Z0-9\40-\176]+")
      userId(size:5..10,unique:true,nullable:false,matches:"[a-zA-Z][a-zA-Z0-9 ]+")
      password(size:5..10,password:true,nullable:false)
      username blank: false, unique: true
   }

   static mapping = {
      password column: '`password`'
   }

   Set<Authority> getAuthorities() {
      UserAuthority.findAllByUser(this).collect { it.authority } as Set
   }

   def beforeInsert() {
      encodePassword()
   }

   def beforeUpdate() {
      if (isDirty('password')) {
         encodePassword()
      }
   }

   protected void encodePassword() {
      password = springSecurityService.encodePassword(password)
   }
}

如果我实现

System.out.println(" userid------------------->" + params.userId);
System.out.println(" password------------------->" + params.password);
System.out.println(" username------------------->" + params.username);

我可以看到登录用户的用户名和密码...但是为什么是

def user=User.findByUserIdAndPassword(params.userId,params.password)NULL??

【问题讨论】:

    标签: grails spring-security


    【解决方案1】:

    密码以散列方式存储在数据库中。因此 params.password 与数据库中存储的值不匹配。

    此外,您还想达到什么目标?您可以通过访问服务手动访问用户:

    springSecurityService.currentUser

    出于登录目的,我建议使用 spring-security-ui 插件。

    希望有帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      • 1970-01-01
      相关资源
      最近更新 更多