Grails中Shiro插件的正确标准

时间:2016-11-21 12:52:17

标签: grails gorm criteria shiro

我有如下的Shiro域类:

class ShiroUser {
String email
String password

static hasMany = [ roles: ShiroRole, permissions: String ]

static constraints = {
    email(nullable: false, blank: false, unique: true)
    }
}


class ShiroRole {
String name

static hasMany = [ users: ShiroUser, permissions: String ]
static belongsTo = ShiroUser

static constraints = {
    name(nullable: false, blank: false, unique: true)
     }
}

我从params.email收到了ShiroUser的电子邮件。我想使用标准()找出belongsTo ShiroUser的权限。

我尝试了以下代码,但无法成功。

 def criteria= permissions.createCriteria().listDistinct {
                ShiroRole{
                     ShiroUser{
                         eq("email", params.email)
                        }
                    }
                }

1 个答案:

答案 0 :(得分:0)

您的标准错误构建。我会保持简单并且像:

def permissions = ShiroUser.findByEmail( params.email )?.roles*.permissions.flatten() as Set

如果你想坚持标准:

def permissions = ShiroRole.createCriteria().listDistinct {
                    projections{ 
                       property 'permissions'
                    }
                    users{
                         eq "email", params.email
                    }
                }