grails spring安全角色和组

Ber*_*ard 10 grails spring-security

我已将弹簧安全配置为与群组配合使用.

我用这个scipt来创建域类:

grails s2-quickstart com.yourapp User Role --groupClassName=RoleGroup
Run Code Online (Sandbox Code Playgroud)

我假设一个用户可以有很多组,其中一个组可以有很多角色

这是User类中生成的方法的样子:

Set<RoleGroup> getAuthorities() {
    UserRoleGroup.findAllByUser(this).collect { it.roleGroup }
}
Run Code Online (Sandbox Code Playgroud)

但是现在我看到脚本还创建了一个名为UserRole的类,它是User和Role之间的关联.那么用户也可以直接拥有多个角色?

我试过了,它保存在数据库中.我修改了这样的方法:

def getAuthorities() {
    def authorities = UserRoleGroup.findAllByUser(this).collect { it.roleGroup }

    authorities.addAll(UserRole.findAllByUser(this).collect { it.role })
    return authorities
}
Run Code Online (Sandbox Code Playgroud)

现在,当我在User < - > Role Association中创建数据库中的条目时.我不能再登录了.我得到spring security的默认消息,基本上说没有找到凭据.

当我手动删除条目时,我可以再次登录.我认为这是因为该方法只返回RoleGroup对象.

我的问题是:

a)我可以在配置组时直接分配角色

b)如果不是,为什么脚本会创建这个类

c)如果是,我该怎么做?

sha*_*del 5

我不认为人们会期望你的分配Role直接User当您使用Groups

分配Group给用户,并RoleGroup

我认为所呈现的代码结构在“降级”您的应用程序时可能很有用

仅使用Userand Roles,而不会破坏您当前的规则集。