[英]Fetch persons with specific authorities - spring security with grails
I have typical Spring Security domain class layout (Person, Authority and join table PersonAuthority). 我有典型的Spring Security域类布局(Person,Author和联接表PersonAuthority)。 I made following query, but I don't know how to build properly criteria for fetching persons that have only specific authorities (last 'if' block).
我进行了以下查询,但是我不知道如何正确地建立标准来获取仅具有特定权限的人(最后一个“ 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;
}
For this query I get org.hibernate.QueryException: could not resolve property: authority
对于此查询,我得到
org.hibernate.QueryException: could not resolve property: authority
If you haven't modified anything form the default Spring Security options and classes, then I suppose you don't have an authority
or authorities
fields. 如果您没有修改默认的Spring Security选项和类的任何内容,那么我想您没有一个
authority
或authorities
字段。
However, you should have a method in your Person class called getAuthorities()
that returns a set of Authorities 但是,您的Person类中应该有一个名为
getAuthorities()
的方法,该方法返回一组Authorities
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.