7723e830cf
- GET /manage/oauth-token/status[/{어댑터그룹명}] 조회 전용
- SessionManager.peekOutboundAccessToken 추가 : 캐시만 조회해 상태 조회가 토큰 발급을 유발하지 않도록 함
- AccessTokenManagerByDB 에 조회 전용 getter 추가
- accessToken 은 앞 8자만 노출하고 clientSecret 은 응답에 미포함
- Ehcache 백엔드는 아웃바운드 토큰 캐시 미지원이므로 사유를 담아 응답
- 단위테스트 10건 추가
63 lines
2.4 KiB
Java
63 lines
2.4 KiB
Java
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<OAuthTokenStatusDTO> list = oAuthTokenStatusService.getStatusList();
|
|
Map<String, Object> 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<Object> action) {
|
|
Map<String, Object> 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);
|
|
}
|
|
}
|