使用属性注入@PreAuthorize hasRole值

时间:2019-05-02 09:00:14

标签: spring-security spring-cloud spring-security-oauth2

我们正尝试如下将值注入hasRole()

@PreAuthorize("hasRole(${role.rolename})")
public void method() {}

但它不起作用

还尝试了以下解决方案

@RestController("appVariablesHolder")
public class AppVariablesHolder {

@Value("${role.rolename}") 
private String someRole;

public String getSomeRole() {
    return this.someRole;
}
}

@PreAuthorize("hasRole(@appVariablesHolder.getSomeRole())")
public void method() {}

但是出现错误

{"exception": { "name":"java.lang.IllegalArgumentException","message":"Failed to evaluate 
 expression \u0027hasRole(@appVariablesHolder.getSomeRole())\u0027"
}
}

如何在hasRole()方法中将@value作为参数注入?

0 个答案:

没有答案