Java 我可以使用SpringEL';具有Spring安全性的s布尔or运算符';s@预授权?
当我试图在@Preauthorize注释中使用“or”操作符时,我得到了以下错误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
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.你能再给我看看吗?我认为这个问题与或操作员无关