[feat] 어드민 계정 전환(impersonation) 기능 추가#133
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an admin impersonation feature that allows administrators to switch to user accounts and revert back using cookies. The review feedback highlights the need to prevent nested impersonation to avoid losing the original admin token, recommends adding role verification for security, and suggests standardizing the backup cookie's expiration time. Furthermore, a correction was provided for the test suite to ensure the JWT utility is properly mocked using @MockitoBean.
| String adminToken = CookieUtil.getCookie(request, ACCESS_COOKIE_NAME) | ||
| .map(cookie -> cookie.getValue()) | ||
| .orElseThrow(() -> new BusinessException(AuthErrorStatus.INVALID_TOKEN_EXCEPTION)); |
There was a problem hiding this comment.
중첩 계정 전환(Nested Impersonation) 방지 및 권한 검증 로직이 필요합니다. 현재 로직은 이미 계정 전환이 된 상태에서 다시 impersonate를 호출하면 기존 백업된 어드민 토큰을 유저 토큰으로 덮어씌우게 되어 복귀가 불가능해집니다. 또한, 백업하려는 토큰이 실제 ADMIN 권한을 가졌는지 확인하는 절차가 보안상 권장됩니다.
| String adminToken = CookieUtil.getCookie(request, ACCESS_COOKIE_NAME) | |
| .map(cookie -> cookie.getValue()) | |
| .orElseThrow(() -> new BusinessException(AuthErrorStatus.INVALID_TOKEN_EXCEPTION)); | |
| String adminToken = CookieUtil.getCookie(request, ACCESS_COOKIE_NAME) | |
| .map(cookie -> cookie.getValue()) | |
| .orElseThrow(() -> new BusinessException(AuthErrorStatus.INVALID_TOKEN_EXCEPTION)); | |
| if (CookieUtil.getCookie(request, ADMIN_BACKUP_COOKIE_NAME).isPresent() || !"ADMIN".equals(jwtUtil.getRole(adminToken))) { | |
| throw new BusinessException(AuthErrorStatus.INVALID_TOKEN_EXCEPTION); | |
| } |
| .orElseThrow(() -> new BusinessException(UserErrorStatus.USER_NOT_FOUND)); | ||
|
|
||
| ResponseCookie backupCookie = CookieUtil.createCookie( | ||
| ADMIN_BACKUP_COOKIE_NAME, adminToken, accessTokenLifetimeInMillis * 8, cookieDomain); |
| @Autowired | ||
| private JwtUtil jwtUtil; |
어드민이 페르소나 계정으로 전환하고 복귀할 수 있는 API 추가