Spring 安全注释应为内联常量
Spring security Annotation expected to be inline constant
当我尝试在 @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() {
}
}
您必须明确地创建 USER 和 ADMIN 常量 public,添加 public
修饰符
public final static String USER = "ROLE_USER"
public final static String ADMIN = "ROLE_ADMIN"
在那种情况下,Groovy 将不会使用 geters
setter
,这在注释中是不允许的。
当我尝试在 @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() {
}
}
您必须明确地创建 USER 和 ADMIN 常量 public,添加 public
修饰符
public final static String USER = "ROLE_USER"
public final static String ADMIN = "ROLE_ADMIN"
在那种情况下,Groovy 将不会使用 geters
setter
,这在注释中是不允许的。