Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BLasan committed Oct 9, 2023
1 parent 56c3a1e commit 06e45e0
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ public static API importApi(String extractedFolderPath, APIDTO importedApiDTO, B
if (log.isDebugEnabled()) {
log.debug("Mutual SSL enabled. Importing client certificates.");
}
addClientCertificates(extractedFolderPath, apiProvider, new ApiTypeWrapper(importedApi), organization);
addClientCertificates(extractedFolderPath, apiProvider, new ApiTypeWrapper(importedApi), organization,
overwrite, tenantId);
}

// Change API lifecycle if state transition is required
Expand Down Expand Up @@ -2164,16 +2165,20 @@ private static void updateAPIWithCertificate(JsonElement certificate, APIProvide
* @throws APIImportExportException
*/
private static void addClientCertificates(String pathToArchive, APIProvider apiProvider,
ApiTypeWrapper apiTypeWrapper, String organization)
ApiTypeWrapper apiTypeWrapper, String organization, boolean isOverwrite, int tenantId)
throws APIManagementException {

try {
Identifier apiIdentifier = apiTypeWrapper.getId();
Identifier apiIdentifier = apiTypeWrapper.getId();
List<ClientCertificateDTO> certificateMetadataDTOS = retrieveClientCertificates(pathToArchive);
for (ClientCertificateDTO certDTO : certificateMetadataDTOS) {
apiProvider.addClientCertificate(APIUtil.replaceEmailDomainBack(apiIdentifier.getProviderName()),
apiTypeWrapper, certDTO.getCertificate(), certDTO.getAlias(), certDTO.getTierName(),
organization);
if (ResponseCode.ALIAS_EXISTS_IN_TRUST_STORE.getResponseCode() == (apiProvider.addClientCertificate(
APIUtil.replaceEmailDomainBack(apiIdentifier.getProviderName()), apiTypeWrapper,
certDTO.getCertificate(), certDTO.getAlias(), certDTO.getTierName(), organization))
&& isOverwrite) {
apiProvider.updateClientCertificate(certDTO.getCertificate(), certDTO.getAlias(), apiTypeWrapper,
certDTO.getTierName(), tenantId, organization);
}
}
} catch (APIManagementException e) {
throw new APIManagementException("Error while importing client certificate", e);
Expand Down Expand Up @@ -2461,7 +2466,9 @@ public static APIProduct importApiProduct(String extractedFolderPath, Boolean pr
if (log.isDebugEnabled()) {
log.debug("Mutual SSL enabled. Importing client certificates.");
}
addClientCertificates(extractedFolderPath, apiProvider, apiTypeWrapperWithUpdatedApiProduct, organization);
int tenantId = APIUtil.getTenantId(RestApiCommonUtil.getLoggedInUsername());
addClientCertificates(extractedFolderPath, apiProvider, apiTypeWrapperWithUpdatedApiProduct, organization,
overwriteAPIProduct, tenantId);

// Change API Product lifecycle if state transition is required
if (!lifecycleActions.isEmpty()) {
Expand Down

0 comments on commit 06e45e0

Please sign in to comment.