Skip to content

[feat] 어드민 계정 전환(impersonation) 기능 추가#133

Merged
k3vin7 merged 1 commit into
mainfrom
feature/admin-impersonation
Apr 8, 2026
Merged

[feat] 어드민 계정 전환(impersonation) 기능 추가#133
k3vin7 merged 1 commit into
mainfrom
feature/admin-impersonation

Conversation

@k3vin7

@k3vin7 k3vin7 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

어드민이 페르소나 계정으로 전환하고 복귀할 수 있는 API 추가

@k3vin7 k3vin7 merged commit b91d61b into main Apr 8, 2026
1 check passed
@k3vin7 k3vin7 deleted the feature/admin-impersonation branch April 8, 2026 03:50

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +46 to +48
String adminToken = CookieUtil.getCookie(request, ACCESS_COOKIE_NAME)
.map(cookie -> cookie.getValue())
.orElseThrow(() -> new BusinessException(AuthErrorStatus.INVALID_TOKEN_EXCEPTION));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

중첩 계정 전환(Nested Impersonation) 방지 및 권한 검증 로직이 필요합니다. 현재 로직은 이미 계정 전환이 된 상태에서 다시 impersonate를 호출하면 기존 백업된 어드민 토큰을 유저 토큰으로 덮어씌우게 되어 복귀가 불가능해집니다. 또한, 백업하려는 토큰이 실제 ADMIN 권한을 가졌는지 확인하는 절차가 보안상 권장됩니다.

Suggested change
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

백업 쿠키의 만료 시간을 액세스 토큰의 8배로 설정한 근거가 불분명합니다. 어드민의 전환 유지 시간이 이보다 길어질 경우 복귀 시 쿠키가 만료되어 문제가 발생할 수 있습니다. 해당 값을 상수로 관리하거나 리프레시 토큰 만료 시간 등과 연동하는 것을 고려해 보세요.

Comment on lines +38 to +39
@Autowired
private JwtUtil jwtUtil;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

jwtUtil을 사용하여 스터빙(when(...))을 하고 있으므로, @Autowired 대신 @MockitoBean을 사용하여 모킹(Mocking)해야 합니다. 그렇지 않으면 실제 빈이 주입되어 테스트 실행 시 오류가 발생할 수 있습니다.

Suggested change
@Autowired
private JwtUtil jwtUtil;
@MockitoBean
private JwtUtil jwtUtil;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant