0

spring security acl を使用して、メールアドレスでユーザーを認証しようとしています。User ドメイン オブジェクトに属する accountPerson の電子メール アドレスを使用したいと考えています。ユーザーを保存すると、すべてが正常に機能し、データベースが正しく更新されますが、認証しようとするhibernate.QueryException: could not resolve property: accountPerson.email of: com.loggyt.Userと、コードとエラー メッセージが表示されます。どんな助けでも大歓迎です。ありがとう

AccountPerson.groovy

class AccountPerson implements Serializable{

String firstName
String lastName
Address address
String email
String primaryPhone
String secondaryPhone

static belongsTo = [user:User]

static mapping = {
    address cascade: 'all'
}

Date dateCreated
Date lastUpdated

static constraints = {
    firstName nullable: false, blank: false
    lastName  nullable: false, blank: false
    address nullable: true
    primaryPhone blank: false, nullable: false
    secondaryPhone blank: true, nullable: true
    email nullable: false, blank: false, email: true, unique: true
}
}

ユーザー.groovy:

import java.util.Date

class User implements Serializable{

transient springSecurityService

transient String password

boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired

Date dateCreated
Date lastUpdated

static hasOne = [accountPerson: AccountPerson]

static constraints = {
    password blank: false
    accountPerson bindable: true
    password bindable: true
}

static mapping = {
    password column: '`password`'
    accountPerson fetch: 'join'
}

Set<Role> getAuthorities() {
    UserRole.findAllByUser(this).collect { it.role } as Set
}

void beforeInsert() {
    encodePassword()
}

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

/**
 * After this user has been updated to the database, log the user back in
 * using the new credentials.
 */
void afterUpdate() {
    this.discard()
    this.springSecurityService.reauthenticate(person.email)
}


/**
 * Get a user based on its email address.
 *
 * @param email email of a user
 * @return the user that has the email parameter
 */
static User findByEmail(String email){
    User.createCriteria().get{
        accountPerson{
            eq('email', email)
        }
    }
}

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

設定

// Added by the Spring Security Core plugin:
grails.plugins.springsecurity.userLookup.userDomainClassName = 'com.loggyt.User'
grails.plugins.springsecurity.userLookup.usernamePropertyName = 'accountPerson.email'
grails.plugins.springsecurity.userLookup.passwordPropertyName = 'password'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'com.loggyt.UserRole'
grails.plugins.springsecurity.authority.className = 'com.loggyt.Role'

ブートストラップ

    def dbCreate = grailsApplication.config.dataSource.dbCreate
    if(dbCreate == "create" || dbCreate == "create-drop"){

        /**
         * Create Roles. 
         * 
         */
        def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush:true)
        def userRole = new Role(authority: 'ROLE_USER').save(flush:true)

        def person = new AccountPerson(
            firstName: 'Otto',
            lastName: 'Admin',
            email: "noreply@loggyt.com",
            primaryPhone: "555-555-5555")

        def user = new User (enabled: true, password: "password")
        user.accountPerson = person
        user.save(flush:true)

        UserRole.create user, adminRole, true

        person = new AccountPerson(
            firstName: 'Normal',
            lastName: 'User',
            email: "user@loggyt.com",
            primaryPhone: "555-555-5555")

        user = new User (enabled: true, password: "password")
        user.accountPerson = person
        user.save(flush:true)

        UserRole.create user, userRole, true

        assert User.count() == 2
        assert Role.count() == 2
        assert UserRole.count() == 2
    }
}

log4j デバッグ メッセージ

2013-07-07 00:57:33,088 [http-bio-8443-exec-3] DEBUG authentication.ProviderManager  - Authentication attempt using org.springframework.security.authentication.dao.DaoAuthenticationProvider
2013-07-07 00:57:33,138 [http-bio-8443-exec-3] DEBUG datasource.DataSourceUtils  - Fetching JDBC Connection from DataSource
2013-07-07 00:57:33,162 [http-bio-8443-exec-3] DEBUG support.TransactionTemplate  - Initiating transaction rollback on application exception
Message: could not resolve property: accountPerson.email of: com.loggyt.User; nested exception is org.hibernate.QueryException: could not resolve property: accountPerson.email of: com.loggyt.User
    Line | Method
->>  592 | findWhere       in org.grails.datastore.gorm.GormStaticApi
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    686 | withTransaction in     ''
|   1110 | runWorker . . . in java.util.concurrent.ThreadPoolExecutor
|    603 | run             in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . . . . in java.lang.Thread

Caused by QueryException: could not resolve property: accountPerson.email of: com.loggyt.User
->>  592 | findWhere       in org.grails.datastore.gorm.GormStaticApi
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    686 | withTransaction in     ''
|   1110 | runWorker . . . in java.util.concurrent.ThreadPoolExecutor
|    603 | run             in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . . . . in java.lang.Thread
4

1 に答える 1