package com.eactive.eai.manage.oauthtoken; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * 아웃바운드 OAuth 토큰 현황 조회 API. (HsmStatusController 와 동일한 응답 형태) * * 조회 전용이며 토큰을 발급하거나 캐시를 건드리지 않는다. * accessToken 은 앞 8자만 남기고 마스킹하며 clientSecret 은 응답에 담지 않는다. * * GET /manage/oauth-token/status → 등록된 전체 어댑터그룹의 토큰 현황 * GET /manage/oauth-token/status/{adapterGroupName} → 어댑터그룹 하나의 토큰 현황 */ @RestController @RequestMapping("/manage/oauth-token") public class OAuthTokenStatusController { private static final MediaType APPLICATION_JSON_UTF8 = new MediaType("application", "json", StandardCharsets.UTF_8); @Autowired private OAuthTokenStatusService oAuthTokenStatusService; @GetMapping("/status") public ResponseEntity status() { return respond(() -> { List list = oAuthTokenStatusService.getStatusList(); Map data = new HashMap<>(); data.put("count", list.size()); data.put("tokens", list); return data; }); } @GetMapping("/status/{adapterGroupName}") public ResponseEntity status(@PathVariable("adapterGroupName") String adapterGroupName) { return respond(() -> oAuthTokenStatusService.getStatus(adapterGroupName)); } private ResponseEntity respond(Callable action) { Map result = new HashMap<>(); try { result.put("success", true); result.put("data", action.call()); } catch (Exception e) { result.put("success", false); result.put("message", e.getMessage()); } return ResponseEntity.ok().contentType(APPLICATION_JSON_UTF8).body(result); } }