我想在 Spring Security 中使用SpEL,例如http://forum.spring.io/forum/spring-projects/security/100708-spel-and-spring-security-3-accessing-bean-reference-in@PreAuthorize中的示例-预授权
,但这对我在 Spring Security 4.1.4 中使用它时不起作用。下面是我的示例代码:
豆类:
package com.service.spel;
import org.springframework.stereotype.Component;
@Component(value="accessBean")
public class AccessCheckBean {
public String getPermision(){
/**
* return the api permision
*/
String scope = "#oauth2.hasScope('resource.Update')";
return scope;
}
}
Run Code Online (Sandbox Code Playgroud)
在控制器中:
@PreAuthorize("accessBean.getPermision()")
@GetMapping("/perm")
public @ResponseBody String getPerm(){
return "Perm";
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
无法评估表达式“accessBean.getPermission()”
看来我不能像上面那样使用 SpEL 。那么如果我使用这个版本的 Spring Security,我该如何进行?