앱 관리 (승인)

This commit is contained in:
현성필
2025-11-01 11:58:45 +09:00
parent aee51fae13
commit e831b38588
3 changed files with 25 additions and 129 deletions
@@ -63,7 +63,6 @@ public class PortalAppApprovalListener implements ApprovalListener {
@Autowired
private AgentUtilService agentUtilService;
private final PortalPropertyService portalPropertyService;
private final ApiGroupService apiGroupService;
private final AppRequestRepository appRequestRepository;
private final CredentialManService credentialManService;
@@ -71,30 +70,6 @@ public class PortalAppApprovalListener implements ApprovalListener {
private final ClientManService clientManService;
private final MessageSendService messageSendService;
public static RestTemplate createRestTemplateWithTimeout(int connectTimeout) {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(connectTimeout)
.setConnectTimeout(connectTimeout)
.setSocketTimeout(connectTimeout)
.build();
HttpClient httpClient =
HttpClientBuilder.create()
.setMaxConnTotal(50)
.setMaxConnPerRoute(20)
.setDefaultRequestConfig(requestConfig)
.build();
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(factory);
return restTemplate;
}
@Override
public void execute(Approval approval, Map<String, Object> option1) throws ApprovalDeployException {
@@ -103,20 +78,11 @@ public class PortalAppApprovalListener implements ApprovalListener {
AppRequest appRequest = optRequest.orElseGet(null);
if (appRequest != null) {
AppRequestType type = appRequest.getType();
String server = determineServer(type);
CredentialUI credentialUI = null;
if (appRequest.getType().equals(AppRequestType.PROD_NEW)) {
credentialUI = createAndSaveCredentialUI("prod", optRequest.get());
} else if (appRequest.getType().equals(AppRequestType.PROD_MODIFY)) {
credentialUI = modifyClientUI(optRequest.get());
} else if (appRequest.getType().equals(AppRequestType.PROD_DELETE)) {
credentialManService.delete(optRequest.get().getClientId());
credentialUI = new CredentialUI();
credentialUI.setClientid(optRequest.get().getClientId());
} else if (appRequest.getType().equals(AppRequestType.NEW)) {
credentialUI = createAndSaveCredentialUI("stg", optRequest.get());
if (appRequest.getType().equals(AppRequestType.NEW)) {
credentialUI = createAndSaveCredentialUI(optRequest.get());
} else if (appRequest.getType().equals(AppRequestType.MODIFY)) {
credentialUI = modifyClientUI(optRequest.get());
} else if (appRequest.getType().equals(AppRequestType.DELETE)) {
@@ -124,7 +90,7 @@ public class PortalAppApprovalListener implements ApprovalListener {
credentialUI = new CredentialUI();
credentialUI.setClientid(optRequest.get().getClientId());
}
syncTargetServer(server, determineAction(type), credentialUI);
syncTargetServer(type, credentialUI);
sendApprovalResult(appRequest);
}
}
@@ -138,81 +104,27 @@ public class PortalAppApprovalListener implements ApprovalListener {
messageSendService.sendMessage("APP_REGISTER_APPROVED", recipient, params);
}
private String determineAction(AppRequestType type) {
if (type == AppRequestType.PROD_NEW || type == AppRequestType.NEW) {
return "insert";
} else if (type == AppRequestType.PROD_MODIFY || type == AppRequestType.MODIFY) {
return "update";
} else if (type == AppRequestType.PROD_DELETE || type == AppRequestType.DELETE) {
return "delete";
} else {
return "none";
private void syncTargetServer(AppRequestType action, CredentialUI credentialUI) throws ApprovalDeployException {
DataSourceType type = DataSourceTypeManager.getDataSourceType("APIGW");
DataSourceContextHolder.setDataSourceType(type);
if (action.equals(AppRequestType.NEW)) {
clientManService.insert(credentialUIMapper.mapClient(credentialUI));
} else if (action.equals(AppRequestType.MODIFY)) {
clientManService.update(credentialUIMapper.mapClient(credentialUI));
} else if (action.equals(AppRequestType.DELETE)) {
clientManService.delete(credentialUI.getClientid());
}
}
private String determineServer(AppRequestType type) {
if (type == AppRequestType.NEW || type == AppRequestType.MODIFY || type == AppRequestType.DELETE) {
return "stg";
} else {
return "prod";
}
}
//TODO: commit 처리
private void syncTargetServer(String server, String action, CredentialUI credentialUI) throws ApprovalDeployException {
// 프록시를 통한 스테이징 서버 호출 추가
Map<String, String> properties = portalPropertyService.getPortalPropertiesAsMap(PORTAL_PROPERTY_GROUP);
String prodUseProxy = properties.getOrDefault("deploy.prod_use_proxy", "N");
CommonCommand.builder()
.name(CommonCommand.RELOAD_CLIENT_COMMAND)
.args(credentialUI.getClientid())
.build().broadcast(agentUtilService);
if (server.equalsIgnoreCase("prod") && prodUseProxy.equalsIgnoreCase("N")) {
if (action.equalsIgnoreCase("insert")) {
clientManService.insert(credentialUIMapper.mapClient(credentialUI));
} else if (action.equalsIgnoreCase("update")) {
clientManService.update(credentialUIMapper.mapClient(credentialUI));
} else if (action.equalsIgnoreCase("delete")) {
clientManService.delete(credentialUI.getClientid());
}
DataSourceType type = DataSourceTypeManager.getDataSourceType("APIGW");
DataSourceContextHolder.setDataSourceType(type);
CommonCommand.builder()
.name(CommonCommand.RELOAD_CLIENT_COMMAND)
.args(credentialUI.getClientid())
.build().broadcast(agentUtilService);
} else {
String apiKey = properties.get("apiKey");
String proxyUrl = properties.get("portal.url");
String timeout = properties.getOrDefault("deploy.proxy_timeout", "10000");
String proxyEndpoint = proxyUrl + "/_onl/admin/authserver/clientMan.json?serviceType=APIGW";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("X-API-KEY", apiKey);
headers.set("target_host", server);
headers.set("action", action);
HttpEntity<ClientUI> request = new HttpEntity<>(credentialUIMapper.mapClient(credentialUI), headers);
try {
ResponseEntity<String> response = createRestTemplateWithTimeout(Integer.parseInt(timeout)).exchange(
proxyEndpoint,
HttpMethod.POST,
request,
String.class
);
if (!response.getStatusCode().is2xxSuccessful()) {
logger.error("Failed to sync with {} server. Status: {}, Body: {}", server, response.getStatusCode(), response.getBody());
throw new ApprovalDeployException("API키 배포에 실패 했습니다.");
}
} catch (Exception e) {
logger.error("Failed to sync with {} server. {}", server, e.getMessage());
throw new ApprovalDeployException("API키 배포에 실패 했습니다.");
}
}
}
@@ -231,9 +143,8 @@ public class PortalAppApprovalListener implements ApprovalListener {
return existingCredential;
}
private CredentialUI createAndSaveCredentialUI(String server, AppRequest appRequest) {
private CredentialUI createAndSaveCredentialUI(AppRequest appRequest) {
CredentialUI credentialUI = new CredentialUI();
credentialUI.setServer(server);
credentialUI.setClientid(RandomStringGenerator.generateString(32));
credentialUI.setClientsecret(RandomStringGenerator.generateString(128));
credentialUI.setClientname(appRequest.getClientName());
@@ -241,6 +152,9 @@ public class PortalAppApprovalListener implements ApprovalListener {
credentialUI.setGranttypes("client_credentials");
credentialUI.setOrgid(appRequest.getOrg().getId());
credentialUI.setOrgname(appRequest.getOrg().getOrgName());
credentialUI.setAllowedips(appRequest.getIpWhitelist());
credentialUI.setRedirecturi(appRequest.getCallbackUrl());
credentialUI.setAppIconFileId(appRequest.getAppIconFileId());
credentialUI.setAccesstokenvalidityseconds("86400");
Set<String> apiIds = processApiGroups(appRequest);
@@ -53,4 +53,6 @@ public class CredentialUI implements Serializable, com.eactive.eai.data.Data {
private int dailytokenlimit;
private List<ApiSpecInfoUI> apiList = new ArrayList<>();
private String appIconFileId;
}
@@ -101,26 +101,6 @@ public class ClientController extends OnlBaseAnnotationController {
return ResponseEntity.ok().build();
}
@PostMapping(value = "/_onl/admin/authserver/clientMan.json", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> apiRequest(@RequestHeader(value = "action", required = false, defaultValue = "none") String action,
@RequestBody ClientUI clientUI) {
if (action.equalsIgnoreCase("insert")) {
clientManService.insert(clientUI);
} else if (action.equalsIgnoreCase("update")) {
clientManService.update(clientUI);
} else if (action.equalsIgnoreCase("delete")) {
clientManService.delete(clientUI.getClientId());
}
CommonCommand.builder()
.name(CommonCommand.RELOAD_CLIENT_COMMAND)
.args(clientUI.getClientId())
.build().broadcast(agentUtilService);
return ResponseEntity.ok().build();
}
@PostMapping(value = "/onl/admin/authserver/clientMan.json", params = "cmd=DELETE")
public ResponseEntity<Void> delete(String clientId) {
clientManService.delete(clientId);