Grails:OR角色的@Secured注释

Ami*_*.io 2 grails spring spring-security grails-3.0

在Grails我正在使用

import grails.plugin.springsecurity.annotation.Secured

@Secured({'ROLE_COMPANY', 'ROLE_BACKEND_ADMIN'})
class MobileSendersController {
Run Code Online (Sandbox Code Playgroud)

但它在角色之间建立了AND关系.我需要OR关系.允许访问ROLE_COMPANYROLE_BACKEND_ADMIN.

在这个问题中,答案是建议使用@PreAuthorize.我在Grails中尝试过,但没有运气.也许我需要修改注释前后,但我找不到配置.

有任何想法吗?

Jos*_*ore 7

如果你看一下文档,@Secured你会看到它使用SpEL表达式(文档,关于这个),所以你可以做很多事情.特别是,你想要这样使用hasAnyRole():

@Secured("hasAnyRole('ROLE_COMPANY', 'ROLE_BACKEND_ADMIN')")


Ank*_*wal 5

这样可以解决问题 -

import grails.plugin.springsecurity.annotation.Secured

@Secured(['ROLE_COMPANY', 'ROLE_BACKEND_ADMIN'])
class MobileSendersController {
Run Code Online (Sandbox Code Playgroud)

请参阅文档http://grails-plugins.github.io/grails-spring-security-core/v3/index.html#securedAnnotations