[英]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選項和類的任何內容,那么我想您沒有一個authority
或authorities
字段。
但是,您的Person類中應該有一個名為getAuthorities()
的方法,該方法返回一組Authorities
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.