Spring-Boot @PreAuthorize allow operation only for admin or if the authenticated user id is same as path parameter id
问题 I have a controller which has User CRUD operations. @Controller public class UserController { // @TODO need to check whether userId == authUser.id or authUser is admin?? // @PreAuthorize("hasRole('ROLE_ADMIN) or ...???...") @PostMapping("/user/{id}/edit") public boolean editUser(@PathVariable("id") long userId, @RequestBody User newUserObj, @CurrentUser authUser) { // I don't like to always call a helper function from here // check(authUser.getId() == userId); return userService.edit(userId,