-
Notifications
You must be signed in to change notification settings - Fork 2
MOSU-132 chore: admin role 인가 로직 추가 #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,100 +6,52 @@ | |
| import life.mosu.mosuserver.infra.kmc.dto.KmcUserInfo; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.commons.codec.binary.Base32; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.util.StringUtils; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class KmcDataMapper { | ||
|
|
||
| private final KmcCryptoManager kmcCryptoManager; | ||
| private final OneTimeTokenProvider tokenProvider; | ||
|
|
||
| private static final String DELIMITER = "/"; | ||
| private static final int MIN_FIELD_COUNT = 18; | ||
|
|
||
| // KMC 응답 필드 인덱스를 상수로 정의하여 매직 넘버 제거 | ||
| private static final int CERT_NUM_INDEX = 0; | ||
| private static final int DATE_INDEX = 1; | ||
| private static final int CI_INDEX = 2; | ||
| private static final int PHONE_NO_INDEX = 3; | ||
| private static final int PHONE_CORP_INDEX = 4; | ||
| private static final int BIRTH_INDEX = 5; | ||
| private static final int GENDER_INDEX = 6; | ||
| private static final int NAME_INDEX = 8; | ||
| private static final int RESULT_SUCCESS_INDEX = 9; // 성공여부 | ||
| private static final int PLUS_INFO_INDEX = 16; | ||
| private static final int DI_INDEX = 17; | ||
|
|
||
| /** | ||
| * 복호화된 KMC 최종 데이터 문자열을 KmcUserInfo DTO로 변환합니다. | ||
| */ | ||
| public KmcUserInfo mapToUserInfo(String finalDecryptedData) { | ||
| String[] tokens = finalDecryptedData.split(DELIMITER, -1); | ||
| if (tokens.length < MIN_FIELD_COUNT) { | ||
| throw new CustomRuntimeException(ErrorCode.INVALID_TOKEN); | ||
| } | ||
|
|
||
| if (!tokens[RESULT_SUCCESS_INDEX].equals("Y")) { | ||
| throw new CustomRuntimeException(ErrorCode.VERIFICATION_FAILED); | ||
| } | ||
|
|
||
| logDecryptedData(tokens); | ||
|
|
||
| String name = tokens[NAME_INDEX]; | ||
| String birth = tokens[BIRTH_INDEX]; | ||
| String phoneNo = tokens[PHONE_NO_INDEX]; | ||
| String gender = tokens[GENDER_INDEX]; | ||
|
|
||
| String servieTerm = tokens[PLUS_INFO_INDEX]; | ||
| String signUpToken = tokenProvider.generateOneTimeToken(tokens[CERT_NUM_INDEX]); | ||
|
|
||
| return KmcUserInfo.of(name, birth, phoneNo, gender, servieTerm, signUpToken); | ||
| } | ||
|
|
||
| // production 시 삭제 | ||
| private void logDecryptedData(String[] tokens) { | ||
| if (!log.isInfoEnabled()) return; | ||
|
|
||
| String ci = decryptCiDiValue(tokens[CI_INDEX]); | ||
| String di = decryptCiDiValue(tokens[DI_INDEX]); | ||
|
|
||
| log.info("[KMCIS] Parsed User Information:"); | ||
| log.info(" - CertNum: {}", tokens[CERT_NUM_INDEX]); | ||
| log.info(" - Name: {}", tokens[NAME_INDEX]); | ||
| log.info(" - PhoneNo: {}", tokens[PHONE_NO_INDEX]); | ||
| log.info(" - Decrypted CI: {}", ci); | ||
| log.info(" - Decrypted DI: {}", di); | ||
| log.info(" - PlusInfo: {}", tokens[PLUS_INFO_INDEX]); | ||
|
|
||
| logPlusInfoDetail(tokens[PLUS_INFO_INDEX]); | ||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class KmcDataMapper { | ||
|
|
||
| private static final String DELIMITER = "/"; | ||
| private static final int MIN_FIELD_COUNT = 18; | ||
| private static final int CERT_NUM_INDEX = 0; | ||
| private static final int PHONE_NO_INDEX = 3; | ||
| private static final int BIRTH_INDEX = 5; | ||
| private static final int GENDER_INDEX = 6; | ||
| private static final int NAME_INDEX = 8; | ||
| private static final int RESULT_SUCCESS_INDEX = 9; // 성공여부 | ||
| private static final int PLUS_INFO_INDEX = 16; | ||
| private final OneTimeTokenProvider tokenProvider; | ||
|
|
||
| /** | ||
| * 복호화된 KMC 최종 데이터 문자열을 KmcUserInfo DTO로 변환합니다. | ||
| */ | ||
| public KmcUserInfo mapToUserInfo(String finalDecryptedData) { | ||
| String[] tokens = finalDecryptedData.split(DELIMITER, -1); | ||
| if (tokens.length < MIN_FIELD_COUNT) { | ||
| throw new CustomRuntimeException(ErrorCode.INVALID_TOKEN); | ||
| } | ||
|
|
||
| // production 시 삭제 | ||
| private void logPlusInfoDetail(String plusInfo) { | ||
| if (!StringUtils.hasText(plusInfo) || !plusInfo.contains("@")) return; | ||
|
|
||
| String[] parts = plusInfo.split("@", -1); | ||
| if (parts.length == 3) { | ||
| byte[] decodedBytes = new Base32().decode(parts[1]); | ||
| String decodedPassword = new String(decodedBytes); | ||
| log.info(" - Parsed PlusInfo -> loginId: {}, password(decoded): {}, term: {}", parts[0], decodedPassword, parts[2]); | ||
| } | ||
| if (!tokens[RESULT_SUCCESS_INDEX].equals("Y")) { | ||
| throw new CustomRuntimeException(ErrorCode.VERIFICATION_FAILED); | ||
| } | ||
|
|
||
| // CI/DI 복호화 유틸리티 | ||
| private String decryptCiDiValue(String encryptedValue) { | ||
| if (StringUtils.hasText(encryptedValue)) { | ||
| try { | ||
| return kmcCryptoManager.decrypt(encryptedValue); | ||
| } catch (Exception e) { | ||
| log.warn("Failed to decrypt CI/DI value.", e); | ||
| return "DECRYPTION_FAILED"; | ||
| } | ||
| } | ||
| return "EMPTY"; | ||
| } | ||
| } | ||
| String name = tokens[NAME_INDEX]; | ||
| String birth = tokens[BIRTH_INDEX]; | ||
| String phoneNo = tokens[PHONE_NO_INDEX]; | ||
| String gender = tokens[GENDER_INDEX]; | ||
| String serviceTerm = tokens[PLUS_INFO_INDEX]; | ||
| String signUpToken = tokenProvider.generateOneTimeToken(tokens[CERT_NUM_INDEX]); | ||
|
|
||
| // production시 삭제 | ||
| log.info("[KMCIS] Parsed User Information:"); | ||
| log.info(" - CertNum: {}", tokens[CERT_NUM_INDEX]); | ||
| log.info(" - Name: {}", tokens[NAME_INDEX]); | ||
| log.info(" - PhoneNo: {}", tokens[PHONE_NO_INDEX]); | ||
| log.info(" - PlusInfo: {}", tokens[PLUS_INFO_INDEX]); | ||
| log.info(" - PlusInfo -> {}", tokens[PLUS_INFO_INDEX]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| return KmcUserInfo.of(name, birth, phoneNo, gender, serviceTerm, signUpToken); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Javadocs and explanatory inline comments for
decryptResponseDatahave been removed. While the code might be clear now, this documentation is very valuable for future maintainers to understand the multi-step decryption and HMAC verification process. Please consider restoring the comments and Javadoc to improve code maintainability.