Projects/HubEleven

[리팩토링] 권한 별 기능 제한 로직 구현 (3) (업데이트 중..)

annovation 2026. 1. 16. 17:51

Controller

💡@PreAuthorize

@PreAuthorize("#userId == authentication.principal.userId")
@PutMapping("/users/{userId}")
public void update(
        @PathVariable Long userId,
        @AuthenticationPrincipal CustomUserDetails user
) {
}
  • userRole 역할 별로 필터링 하기

💡@AuthenticationPrincipal

@GetMapping("/profile")
public ResponseEntity<?> profile(
        @AuthenticationPrincipal CustomUserDetails userDetails
) {
    profileService.getProfile(userDetails.getUserId());
    return ResponseEntity.ok().build();
}
  • user 정보 받아오기