앱 관리 (승인)
This commit is contained in:
+23
-109
@@ -63,7 +63,6 @@ public class PortalAppApprovalListener implements ApprovalListener {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AgentUtilService agentUtilService;
|
private AgentUtilService agentUtilService;
|
||||||
|
|
||||||
private final PortalPropertyService portalPropertyService;
|
|
||||||
private final ApiGroupService apiGroupService;
|
private final ApiGroupService apiGroupService;
|
||||||
private final AppRequestRepository appRequestRepository;
|
private final AppRequestRepository appRequestRepository;
|
||||||
private final CredentialManService credentialManService;
|
private final CredentialManService credentialManService;
|
||||||
@@ -71,30 +70,6 @@ public class PortalAppApprovalListener implements ApprovalListener {
|
|||||||
private final ClientManService clientManService;
|
private final ClientManService clientManService;
|
||||||
private final MessageSendService messageSendService;
|
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
|
@Override
|
||||||
public void execute(Approval approval, Map<String, Object> option1) throws ApprovalDeployException {
|
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);
|
AppRequest appRequest = optRequest.orElseGet(null);
|
||||||
if (appRequest != null) {
|
if (appRequest != null) {
|
||||||
AppRequestType type = appRequest.getType();
|
AppRequestType type = appRequest.getType();
|
||||||
String server = determineServer(type);
|
|
||||||
|
|
||||||
CredentialUI credentialUI = null;
|
CredentialUI credentialUI = null;
|
||||||
|
|
||||||
if (appRequest.getType().equals(AppRequestType.PROD_NEW)) {
|
if (appRequest.getType().equals(AppRequestType.NEW)) {
|
||||||
credentialUI = createAndSaveCredentialUI("prod", optRequest.get());
|
credentialUI = createAndSaveCredentialUI(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());
|
|
||||||
} else if (appRequest.getType().equals(AppRequestType.MODIFY)) {
|
} else if (appRequest.getType().equals(AppRequestType.MODIFY)) {
|
||||||
credentialUI = modifyClientUI(optRequest.get());
|
credentialUI = modifyClientUI(optRequest.get());
|
||||||
} else if (appRequest.getType().equals(AppRequestType.DELETE)) {
|
} else if (appRequest.getType().equals(AppRequestType.DELETE)) {
|
||||||
@@ -124,7 +90,7 @@ public class PortalAppApprovalListener implements ApprovalListener {
|
|||||||
credentialUI = new CredentialUI();
|
credentialUI = new CredentialUI();
|
||||||
credentialUI.setClientid(optRequest.get().getClientId());
|
credentialUI.setClientid(optRequest.get().getClientId());
|
||||||
}
|
}
|
||||||
syncTargetServer(server, determineAction(type), credentialUI);
|
syncTargetServer(type, credentialUI);
|
||||||
sendApprovalResult(appRequest);
|
sendApprovalResult(appRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,81 +104,27 @@ public class PortalAppApprovalListener implements ApprovalListener {
|
|||||||
messageSendService.sendMessage("APP_REGISTER_APPROVED", recipient, params);
|
messageSendService.sendMessage("APP_REGISTER_APPROVED", recipient, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String determineAction(AppRequestType type) {
|
private void syncTargetServer(AppRequestType action, CredentialUI credentialUI) throws ApprovalDeployException {
|
||||||
if (type == AppRequestType.PROD_NEW || type == AppRequestType.NEW) {
|
|
||||||
return "insert";
|
DataSourceType type = DataSourceTypeManager.getDataSourceType("APIGW");
|
||||||
} else if (type == AppRequestType.PROD_MODIFY || type == AppRequestType.MODIFY) {
|
DataSourceContextHolder.setDataSourceType(type);
|
||||||
return "update";
|
|
||||||
} else if (type == AppRequestType.PROD_DELETE || type == AppRequestType.DELETE) {
|
if (action.equals(AppRequestType.NEW)) {
|
||||||
return "delete";
|
clientManService.insert(credentialUIMapper.mapClient(credentialUI));
|
||||||
} else {
|
} else if (action.equals(AppRequestType.MODIFY)) {
|
||||||
return "none";
|
clientManService.update(credentialUIMapper.mapClient(credentialUI));
|
||||||
|
} else if (action.equals(AppRequestType.DELETE)) {
|
||||||
|
clientManService.delete(credentialUI.getClientid());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private String determineServer(AppRequestType type) {
|
//TODO: commit 처리
|
||||||
if (type == AppRequestType.NEW || type == AppRequestType.MODIFY || type == AppRequestType.DELETE) {
|
|
||||||
return "stg";
|
|
||||||
} else {
|
|
||||||
return "prod";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void syncTargetServer(String server, String action, CredentialUI credentialUI) throws ApprovalDeployException {
|
|
||||||
|
|
||||||
// 프록시를 통한 스테이징 서버 호출 추가
|
CommonCommand.builder()
|
||||||
Map<String, String> properties = portalPropertyService.getPortalPropertiesAsMap(PORTAL_PROPERTY_GROUP);
|
.name(CommonCommand.RELOAD_CLIENT_COMMAND)
|
||||||
String prodUseProxy = properties.getOrDefault("deploy.prod_use_proxy", "N");
|
.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;
|
return existingCredential;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CredentialUI createAndSaveCredentialUI(String server, AppRequest appRequest) {
|
private CredentialUI createAndSaveCredentialUI(AppRequest appRequest) {
|
||||||
CredentialUI credentialUI = new CredentialUI();
|
CredentialUI credentialUI = new CredentialUI();
|
||||||
credentialUI.setServer(server);
|
|
||||||
credentialUI.setClientid(RandomStringGenerator.generateString(32));
|
credentialUI.setClientid(RandomStringGenerator.generateString(32));
|
||||||
credentialUI.setClientsecret(RandomStringGenerator.generateString(128));
|
credentialUI.setClientsecret(RandomStringGenerator.generateString(128));
|
||||||
credentialUI.setClientname(appRequest.getClientName());
|
credentialUI.setClientname(appRequest.getClientName());
|
||||||
@@ -241,6 +152,9 @@ public class PortalAppApprovalListener implements ApprovalListener {
|
|||||||
credentialUI.setGranttypes("client_credentials");
|
credentialUI.setGranttypes("client_credentials");
|
||||||
credentialUI.setOrgid(appRequest.getOrg().getId());
|
credentialUI.setOrgid(appRequest.getOrg().getId());
|
||||||
credentialUI.setOrgname(appRequest.getOrg().getOrgName());
|
credentialUI.setOrgname(appRequest.getOrg().getOrgName());
|
||||||
|
credentialUI.setAllowedips(appRequest.getIpWhitelist());
|
||||||
|
credentialUI.setRedirecturi(appRequest.getCallbackUrl());
|
||||||
|
credentialUI.setAppIconFileId(appRequest.getAppIconFileId());
|
||||||
credentialUI.setAccesstokenvalidityseconds("86400");
|
credentialUI.setAccesstokenvalidityseconds("86400");
|
||||||
|
|
||||||
Set<String> apiIds = processApiGroups(appRequest);
|
Set<String> apiIds = processApiGroups(appRequest);
|
||||||
|
|||||||
@@ -53,4 +53,6 @@ public class CredentialUI implements Serializable, com.eactive.eai.data.Data {
|
|||||||
private int dailytokenlimit;
|
private int dailytokenlimit;
|
||||||
|
|
||||||
private List<ApiSpecInfoUI> apiList = new ArrayList<>();
|
private List<ApiSpecInfoUI> apiList = new ArrayList<>();
|
||||||
|
|
||||||
|
private String appIconFileId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,26 +101,6 @@ public class ClientController extends OnlBaseAnnotationController {
|
|||||||
return ResponseEntity.ok().build();
|
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")
|
@PostMapping(value = "/onl/admin/authserver/clientMan.json", params = "cmd=DELETE")
|
||||||
public ResponseEntity<Void> delete(String clientId) {
|
public ResponseEntity<Void> delete(String clientId) {
|
||||||
clientManService.delete(clientId);
|
clientManService.delete(clientId);
|
||||||
|
|||||||
Reference in New Issue
Block a user