24.9.11
현재 구현
//모든 API의 서비스 메소드에서, 사용자의 동아리내 권한을 확인하는 검증 로직(아래 코드)을 일일이 포함하고 있다.
//TODO: AOP를 활용하여 권한 검증 로직과 비즈니스 로직을 분리하기
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
CustomUserDetail userDetails = (CustomUserDetail) authentication.getPrincipal();
User user = userRepository.findById(userDetails.getId())
.orElseThrow(() -> new NoSuchElementException("User not found"));
Club club = stepRepository.findById(stepId)
.orElseThrow(() -> new NoSuchElementException("Step not found"))
.getRecruitment().getClub();
//User와 Club을 이용하여, 사용자의 동아리 내 권한을 조회한다.
UserClubRole userClubRole = userClubRoleRepository.findByClubAndUser(club, user)
.orElseThrow(() -> new NoSuchElementException("User is not in Club"));
문제 상황
Aspect Oriented Programming with Spring :: Spring Framework