기록일자

24.9.11

문제상황

🙋 2종류의 권한으로 분리한 이유

현재 구현

//모든 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"));

문제 상황

  1. 각 API 호출 시, 사용자의 동아리 내 역할(동아리장 또는 동아리원)을 검사해야 하는 로직이 서비스 메소드에 중복되어 작성되고 있음.
  2. 또한, 해당 API의 주요 비즈니스 로직이 clubId가 필요하지 않은 상황에서도 사용자 검증을 위해 clubId를 함께 보내야 하는 상황이 발생.

문제 해결

AOP 기초