Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我可以使用SpringEL';具有Spring安全性的s布尔or运算符';s@预授权?_Java_Spring_Spring Security - Fatal编程技术网

Java 我可以使用SpringEL';具有Spring安全性的s布尔or运算符';s@预授权?

Java 我可以使用SpringEL';具有Spring安全性的s布尔or运算符';s@预授权?,java,spring,spring-security,Java,Spring,Spring Security,当我试图在@Preauthorize注释中使用“or”操作符时,我得到了以下错误 java.lang.IllegalArgumentException: Failed to evaluate expression '#authenticatingUser.id == #id or hasRole('ROLE_ADMIN')' 我认为我的语法是正确的,如下面文档中的“或”示例所示 Spring Security明确表示它使用“Spring EL表达式” 但我还没有在网上看到有人在@Preau

当我试图在@Preauthorize注释中使用“or”操作符时,我得到了以下错误

java.lang.IllegalArgumentException: Failed to evaluate expression '#authenticatingUser.id == #id or hasRole('ROLE_ADMIN')'
我认为我的语法是正确的,如下面文档中的“或”示例所示

Spring Security明确表示它使用“Spring EL表达式”

但我还没有在网上看到有人在@Preauthorize注释中使用布尔“or”运算符的例子

以下是完整的控制器代码。表面上,我希望用户能够更改自己的密码或管理员。我已经成功地单独使用了
#authenticatingUser.id==#id
hasRole('ROLE\u ADMIN')
,但是使用了或我得到了一个错误

@RequestMapping(value = "{id}", method = RequestMethod.PUT)
@ResponseBody
@PreAuthorize("#authenticatingUser.id == #id or hasRole('ROLE_ADMIN')")
public User newPassword(@PathVariable int id, @RequestParam String newPassword, @ModelAttribute User authenticatingUser) {
    User user = userService.findById(id);
    user.setPassword(newPassword);
    return userService.save(user);
}

您确实可以使用如上所示的EL,并使用所写的
#
访问器以您期望的方式为原语工作。我遇到的问题与SpringEL表达式的构造无关

@PreAuthorize("#authenticatingUser.id == #id or hasRole('ROLE_ADMIN')")
public User newPassword(@PathVariable int id, @RequestParam String newPassword, @ModelAttribute User authenticatingUser) {

您确实可以使用如上所示的EL,并使用所写的
#
访问器以您期望的方式为原语工作。我遇到的问题与SpringEL表达式的构造无关

@PreAuthorize("#authenticatingUser.id == #id or hasRole('ROLE_ADMIN')")
public User newPassword(@PathVariable int id, @RequestParam String newPassword, @ModelAttribute User authenticatingUser) {

1.您是否有此
@EnableGlobalMethodSecurity(prespenabled=true)
?2.你能再给我看看吗?我认为这个问题与
操作员无关。您是否有此
@EnableGlobalMethodSecurity(prespenabled=true)
?2.你能再给我看看吗?我认为这个问题与
操作员无关