2012-04-30 6 views
-1

def user=User.findByUserIdAndPassword(params.userId,params.password)は登録に成功してもnullです...私はSpring Securityを使用しています。私は私がログインしているユーザーのユーザーIDとパスワードを見ることができています...しかし、なぜdef user = User.findByUserIdAndPassword(params.userId、params.password)はnullですか?グレイスで

ある

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

を実装する場合

私のユーザードメインクラスは

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) 
    } 
} 

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

答えて

1

パスワードはデータベースにハッシュされて格納されます。したがって、params.passwordはデータベースに格納されている値と一致しません。

さらに、達成しようとしているのは何ですか?あなたは、サービスにアクセスすることにより、手動でユーザーにアクセスすることができます。

springSecurityService.currentUser

とログインの目的のために、私は春-セキュリティ-UIのプラグインを使用してお勧めします。

希望するもの:

関連する問題