Files
eapim-admin/WebContent/jsp/js/stringMaskingUtil.js
T
Rinjae 10db8129eb
eapim-admin CI / build (push) Has been cancelled
마스킹 표준화 적용 (eapim-admin/portal/JS)
- admin: elink-online-core 표준 위임(e메일/이름/전화/IP)으로 규칙 일원화
- portal/JS: 표준 로직 직접 구현 + 기존 owner 비마스킹 유지
- 호출처 무수정/인라인 중복 제거/테스트 통과
2026-06-18 17:56:32 +09:00

75 lines
2.4 KiB
JavaScript

/**
* 문자열 마스킹 처리를 위한 유틸리티
*
* 보안아키텍처 표준 마스킹 규칙(Java MaskingUtils)과 동일한 결과를 내도록 구현한다.
* 이름 2자: 뒤 1자리(가나→가*) / 3자 이상: 앞뒤 제외 가운데 전체(가나다라→가**라)
* 이메일 아이디 앞2·뒤2 마스킹, 4자 이하 전체(test→****, test123→**st1**)
* 전화 2·3번째 세그먼트 각각 뒤 2자리(010-1234-1234→010-12**-12**)
*/
const StringMaskingUtil = {
// null, empty 체크
isValidString: function(str) {
return str != null && str !== '';
},
// '*' 반복 생성
_stars: function(count) {
return count > 0 ? '*'.repeat(count) : '';
},
// 세그먼트 뒤 count 자리 마스킹
_maskSegmentTail: function(segment, count) {
if (segment.length <= count) {
return this._stars(segment.length);
}
return segment.substring(0, segment.length - count) + this._stars(count);
},
// 이름 마스킹 처리 (2자: 뒤 1자리, 3자 이상: 앞뒤 제외 가운데 전체)
maskName: function(name) {
if (!this.isValidString(name)) {
return name;
}
const len = name.length;
if (len === 1) {
return name;
}
if (len === 2) {
return name.charAt(0) + '*';
}
return name.charAt(0) + this._stars(len - 2) + name.charAt(len - 1);
},
// 이메일 마스킹 처리 (아이디 앞2·뒤2, 4자 이하 전체)
maskEmail: function(email) {
if (!this.isValidString(email) || !email.includes('@')) {
return email;
}
const atIdx = email.indexOf('@');
const local = email.substring(0, atIdx);
const domain = email.substring(atIdx);
if (local.length <= 4) {
return this._stars(local.length) + domain;
}
return this._stars(2) + local.substring(2, local.length - 2) + this._stars(2) + domain;
},
// 휴대폰/전화 번호 마스킹 처리 (2·3번째 세그먼트 각각 뒤 2자리)
maskMobileNumber: function(number) {
if (!this.isValidString(number)) {
return number;
}
const parts = number.split('-');
if (parts.length === 3) {
return parts[0] + '-' +
this._maskSegmentTail(parts[1], 2) + '-' +
this._maskSegmentTail(parts[2], 2);
}
return number;
}
};