diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java index bdfb29b7f34a..045d2cecbcf5 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/ExportUtils.java @@ -1019,35 +1019,40 @@ public static void addClientCertificatesToArchive(String archivePath, Identifier APIProvider provider, ExportFormat exportFormat, String organization) throws APIImportExportException { - List certificateMetadataDTOs; - try { - if (identifier instanceof APIProductIdentifier) { - certificateMetadataDTOs = provider - .searchClientCertificates(tenantId, null, null, - (APIProductIdentifier) identifier, organization); - } else { - certificateMetadataDTOs = provider - .searchClientCertificates(tenantId, null, null, - (APIIdentifier) identifier, organization); - } - if (!certificateMetadataDTOs.isEmpty()) { - String clientCertsDirectoryPath = - archivePath + File.separator + ImportExportConstants.CLIENT_CERTIFICATES_DIRECTORY; - CommonUtil.createDirectory(clientCertsDirectoryPath); + String[] keyTypes = new String[] {APIConstants.API_KEY_TYPE_PRODUCTION, APIConstants.API_KEY_TYPE_SANDBOX}; - JsonArray certificateList = getClientCertificateContentAndMetaData(certificateMetadataDTOs, - clientCertsDirectoryPath); + for (String keyType : keyTypes) { - if (certificateList.size() > 0) { - CommonUtil.writeDtoToFile(clientCertsDirectoryPath + ImportExportConstants.CLIENT_CERTIFICATE_FILE, - exportFormat, ImportExportConstants.TYPE_CLIENT_CERTIFICATES, certificateList); + List certificateMetadataDTOs; + try { + if (identifier instanceof APIProductIdentifier) { + certificateMetadataDTOs = provider + .searchClientCertificates(tenantId, null, keyType, + (APIProductIdentifier) identifier, organization); + } else { + certificateMetadataDTOs = provider + .searchClientCertificates(tenantId, null, keyType, + (APIIdentifier) identifier, organization); } + if (!certificateMetadataDTOs.isEmpty()) { + String clientCertsDirectoryPath = archivePath + File.separator + + ImportExportConstants.CLIENT_CERTIFICATES_DIRECTORY + File.separator + keyType; + CommonUtil.createDirectory(clientCertsDirectoryPath); + + JsonArray certificateList = getClientCertificateContentAndMetaData(certificateMetadataDTOs, + clientCertsDirectoryPath); + + if (certificateList.size() > 0) { + CommonUtil.writeDtoToFile(clientCertsDirectoryPath + ImportExportConstants.CLIENT_CERTIFICATE_FILE, + exportFormat, ImportExportConstants.TYPE_CLIENT_CERTIFICATES, certificateList); + } + } + } catch (IOException e) { + throw new APIImportExportException("Error while saving as YAML or JSON", e); + } catch (APIManagementException e) { + throw new APIImportExportException( + "Error retrieving certificate meta data. tenantId [" + tenantId + "] api [" + tenantId + "]", e); } - } catch (IOException e) { - throw new APIImportExportException("Error while saving as YAML or JSON", e); - } catch (APIManagementException e) { - throw new APIImportExportException( - "Error retrieving certificate meta data. tenantId [" + tenantId + "] api [" + tenantId + "]", e); } }