Spring安全注释预期为内联常量

时间:2018-03-26 18:16:20

标签: grails spring-security

当我尝试在@Secured注释之外定义我的字符串时,我在grails中得到以下错误。

我收到以下错误 Role.USER'是java.lang.String类型的内联常量,而不是@ grails.plugin.springsecurity.annotation.Secured中的属性表达式

class Role {
    final static String USER = "ROLE_USER"
    final static String ADMIN = "ROLE_ADMIN"


    public final static String[] LOGINED_USER = [USER, ADMIN].asImmutable()

}

以下控制器说明了我的问题..

class MyController {

    @Secured(["permitAll"]) //Works fine
    def action1() {
    }


    @Secured(LOGINED_USER) //Doesn't work
    def action2() {
    }

    @Secured([Role.ADMIN, Role.USER]) //Doesn't work
    def action3() {
    }


    @Secured(["ROLE_ADMIN", "ROLE_USER"]) //Works fine
    def action4() {
    }
}

1 个答案:

答案 0 :(得分:1)

您必须显式公开USER和ADMIN常量,并添加public修饰符

public final static String USER = "ROLE_USER"
public final static String ADMIN = "ROLE_ADMIN"

在这种情况下,Groovy将不会使用注释中不允许的geters setter