Das*_*sma 0 grails spring-security
当我尝试在 @Secured 注释之外定义字符串时,我在 grails 中遇到以下错误。
我收到以下错误 Role.USER' to be an inline const of type java.lang.String not a property expression in @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()
}
Run Code Online (Sandbox Code Playgroud)
下面的控制器说明了我的问题..
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() {
}
}
Run Code Online (Sandbox Code Playgroud)
您必须显式公开 USER 和 ADMIN 常量,添加public修饰符
public final static String USER = "ROLE_USER"
public final static String ADMIN = "ROLE_ADMIN"
Run Code Online (Sandbox Code Playgroud)
在这种情况下,Groovy 将不会使用geters setter注释中不允许的内容。
| 归档时间: |
|
| 查看次数: |
3477 次 |
| 最近记录: |