|
|
|
@ -35,8 +35,8 @@ public class ExternalAuthService {
|
|
|
|
@Value("${external.auth.edge-search-url}")
|
|
|
|
@Value("${external.auth.edge-search-url}")
|
|
|
|
private String edgeSearchUrl;
|
|
|
|
private String edgeSearchUrl;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${external.edge.add-url:https://cuuva.com:24443/api/datamanager/edge-pkg/add}")
|
|
|
|
@Value("${external.auth.sw-search-url}")
|
|
|
|
private String edgeAddUrl;
|
|
|
|
private String swSearchUrl;
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
@PostConstruct
|
|
|
|
public void init() {
|
|
|
|
public void init() {
|
|
|
|
@ -127,7 +127,6 @@ public class ExternalAuthService {
|
|
|
|
URI uri = URI.create(url);
|
|
|
|
URI uri = URI.create(url);
|
|
|
|
|
|
|
|
|
|
|
|
// 추가 안전권장(선택) : 실제 호출되는 호스트가 설정한 base URL의 호스트와 동일한지 확인
|
|
|
|
// 추가 안전권장(선택) : 실제 호출되는 호스트가 설정한 base URL의 호스트와 동일한지 확인
|
|
|
|
// (내부망 차단을 원치 않으셨으므로 private IP 검사 코드는 제외)
|
|
|
|
|
|
|
|
URI baseUri = URI.create(edgeSearchUrl);
|
|
|
|
URI baseUri = URI.create(edgeSearchUrl);
|
|
|
|
if (!uri.getHost().equalsIgnoreCase(baseUri.getHost())) {
|
|
|
|
if (!uri.getHost().equalsIgnoreCase(baseUri.getHost())) {
|
|
|
|
throw new SecurityException("요청 호스트가 허용된 서비스와 일치하지 않습니다.");
|
|
|
|
throw new SecurityException("요청 호스트가 허용된 서비스와 일치하지 않습니다.");
|
|
|
|
@ -156,4 +155,55 @@ public class ExternalAuthService {
|
|
|
|
throw new RuntimeException("외부 Edge API 호출 중 오류가 발생했습니다.");
|
|
|
|
throw new RuntimeException("외부 Edge API 호출 중 오류가 발생했습니다.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Edge 패키지 검색 API 호출
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public Map<String, Object> getSWPackageList(String id, String token) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 1) 입력 검증: id에 URL/공격 문자열 포함 금지
|
|
|
|
|
|
|
|
if (id == null || id.isBlank()) {
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("잘못된 사용자 ID입니다.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id.contains("http://") || id.contains("https://")) {
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("ID에 URL을 포함할 수 없습니다.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2) 안전하게 파라미터 인코딩 및 URL 구성 (base URL은 외부 입력에서 분리)
|
|
|
|
|
|
|
|
String safeId = URLEncoder.encode(id, StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
String url = String.format("%s?sw_group=-1&sw_type=-1&searchType=&searchText=&pageNum=1&pageSize=10&auth_id=%s&user_id=",
|
|
|
|
|
|
|
|
swSearchUrl, safeId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3) URI 생성 (edgeSearchUrl이 올바른 형식인지 확인)
|
|
|
|
|
|
|
|
URI uri = URI.create(url);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 추가 안전권장(선택) : 실제 호출되는 호스트가 설정한 base URL의 호스트와 동일한지 확인
|
|
|
|
|
|
|
|
URI baseUri = URI.create(swSearchUrl);
|
|
|
|
|
|
|
|
if (!uri.getHost().equalsIgnoreCase(baseUri.getHost())) {
|
|
|
|
|
|
|
|
throw new SecurityException("요청 호스트가 허용된 서비스와 일치하지 않습니다.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4) 요청 헤더 구성
|
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
|
|
headers.setBearerAuth(token);
|
|
|
|
|
|
|
|
headers.setAccept(java.util.List.of(MediaType.APPLICATION_JSON));
|
|
|
|
|
|
|
|
HttpEntity<Void> request = new HttpEntity<>(headers);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 5) 요청 수행
|
|
|
|
|
|
|
|
ResponseEntity<Map> response = restTemplate.exchange(uri, HttpMethod.GET, request, Map.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
|
|
|
|
|
|
|
|
return response.getBody();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new RuntimeException("외부 Edge 패키지 조회 실패");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (IllegalArgumentException iae) {
|
|
|
|
|
|
|
|
// 입력 검증 실패는 호출자에게 명확히 알릴 수 있음
|
|
|
|
|
|
|
|
throw iae;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
// 내부 상세 예외는 래핑하여 외부에 노출하지 않음
|
|
|
|
|
|
|
|
throw new RuntimeException("외부 Edge API 호출 중 오류가 발생했습니다.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|