当我尝试在@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() {
}
}
答案 0 :(得分:1)
您必须显式公开USER和ADMIN常量,并添加public
修饰符
public final static String USER = "ROLE_USER"
public final static String ADMIN = "ROLE_ADMIN"
在这种情况下,Groovy将不会使用注释中不允许的geters
setter
。