简体   繁体   English

获取具有特定权限的人员-带有Grails的春季安全

[英]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选项和类的任何内容,那么我想您没有一个authorityauthorities字段。

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.

相关问题 春季安全性中错误的自定义设计用户/权限 - wrong custom design user/authorities in spring security 如何使用Hibernate / JPA2实现Spring Security用户/权限? - Howto implement Spring Security User/Authorities with Hibernate/JPA2? Grails:乐观锁定,StaleObjectStateException与Spring Security会话中的域,更新计数器 - Grails: Optimistic locking, StaleObjectStateException with domain on session with Spring Security, updating counters 如何在 Grails 应用程序和 Java 应用程序之间共享 Spring 安全类? - How to share Spring Security classes between a Grails app and a Java app? 查找具有特定Spring安全角色的用户 - Find user with specific spring security role Spring Security登录时如何获取自定义用户实体以进行自定义身份验证? - How to fetch custom user entity for custom authentication in login on spring security? Spring MVC休眠以形成登录页面,权限和身份验证问题 - spring mvc hibernate to form log in page, authorities and authentication questions Spring和Hibernate:如何使用jsp和复选框修改用户权限 - Spring and Hibernate: How to modify user authorities using jsp and checkboxes Grails Spring Security查询没有特定角色的用户 - Grails Spring Security querying users which don't have a certain role Grails Spring-security-core插件需要角色表中的用户名列 - Grails spring-security-core plugin expects a username column in the role table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM