"X-API-KEY 방식 제거 및 내부 API 토큰 검증으로 변경
eapim-portal CI (from elink-portal-common) / build (push) Has been cancelled
eapim-portal CI (from elink-portal-common) / build (push) Has been cancelled
- ApiKeyInterceptor 삭제, InternalApiTokenInterceptor 도입 - 관련 config 및 테스트 코드 X-Internal-Token 방식으로 수정 - PortalPropertyService 연관 코드 정리 및 불필요 메서드 제거"
This commit is contained in:
@@ -95,16 +95,15 @@ public class InternalApiTokenService {
|
||||
*/
|
||||
public boolean matches(String presented) {
|
||||
String expected = ensureToken();
|
||||
if (expected == null) {
|
||||
log.error("내부 API 토큰({}/{})을 확보하지 못해 요청을 거부합니다.", PROP_GROUP, PROP_TOKEN);
|
||||
return false;
|
||||
return tokenMatches(presented, expected);
|
||||
}
|
||||
if (isBlank(presented)) {
|
||||
return false;
|
||||
}
|
||||
return MessageDigest.isEqual(
|
||||
presented.trim().getBytes(StandardCharsets.UTF_8),
|
||||
expected.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
/**
|
||||
* admin 등 토큰을 생성하면 안 되는 애플리케이션용 검증.
|
||||
* 프로퍼티가 없으면 생성하지 않고 거부한다.
|
||||
*/
|
||||
public boolean matchesReadOnly(String presented) {
|
||||
return tokenMatches(presented, findToken());
|
||||
}
|
||||
|
||||
/** 기동 시 1회 호출 — 헤더명/토큰 프로퍼티를 미리 만들어 둔다. (포탈 전용) */
|
||||
@@ -138,6 +137,19 @@ public class InternalApiTokenService {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean tokenMatches(String presented, String expected) {
|
||||
if (expected == null) {
|
||||
log.error("내부 API 토큰({}/{})을 확보하지 못해 요청을 거부합니다.", PROP_GROUP, PROP_TOKEN);
|
||||
return false;
|
||||
}
|
||||
if (isBlank(presented)) {
|
||||
return false;
|
||||
}
|
||||
return MessageDigest.isEqual(
|
||||
presented.trim().getBytes(StandardCharsets.UTF_8),
|
||||
expected.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/** JVM 당 1회만 생성되는 난수 토큰 (DB 에 값이 없을 때의 기본값). */
|
||||
private String localToken() {
|
||||
String token = generatedToken.get();
|
||||
|
||||
Reference in New Issue
Block a user