簡體   English   中英

獲取具有特定權限的人員-帶有Grails的春季安全

[英]Fetch persons with specific authorities - spring security with grails

我有典型的Spring Security域類布局(Person,Author和聯接表PersonAuthority)。 我進行了以下查詢,但是我不知道如何正確地建立標准來獲取僅具有特定權限的人(最后一個“ if”塊)。

public static def query(Map params=[:]){
    def criteria = Person.createCriteria();
    def rows = criteria.list(max:params.max,offset:params.offset){
    order(params.column?:"id",params.order?:"asc")
        if(params.id){
            idEq (params.id as Long);
        }        
        if(params.username){
            ilike "username","%"+params.username+"%"    
        }
        if(params.email){
            ilike "email","%"+params.email+"%"
        }
        if(params.accountLocked){
            eq "accountLocked",Boolean.valueOf(params.accountLocked)
        }
        if(params.enabled){
            eq "enabled",Boolean.valueOf(params.enabled)
        }
        if(params.passwordExpired){
            eq "passwordExpired",Boolean.valueOf(params.passwordExpired)
        }
        if(params.authorities){
            inList "authority",params.authorities;
        }
    }
    return rows;
}

對於此查詢,我得到org.hibernate.QueryException: could not resolve property: authority

如果您沒有修改默認的Spring Security選項和類的任何內容,那么我想您沒有一個authorityauthorities字段。

但是,您的Person類中應該有一個名為getAuthorities()的方法,該方法返回一組Authorities

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM