뭐가 문제인지 계속 찾아봤다.
근데 나 같은 경우가 정말 없어서 3시간동안 삽질하다가.. 결국 Admin 권한 체크 부분도 SpEL 표현식으로 바꿔주었다.
// 게시글 수정
@PutMapping("/posts/{postId}")
@PreAuthorize("(#customUserDetails.authorities.containsAll(@postService.getPostAuthorAuth())) or (#customUserDetails.userId == @postService.getPostAuthorId(#postId))")
public ResponseEntity<PostResponse> updatePost(@PathVariable Long postId,
@RequestBody @Valid PostUpdateRequest request,
@AuthenticationPrincipal CustomUserDetails customUserDetails) {
Post updatedPost = postService.update(postId, request);
return ResponseEntity
.ok(updatedPost.toResponse());
}
// ROLE_ADMIN 반환하는 메서드 - 권한 체크용
public Collection<GrantedAuthority> getPostAuthorAuth() {
Collection<GrantedAuthority> role = new ArrayList<>();
role.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
return role;
}
