Skip to content

Commit

Permalink
- Issue #466
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Mar 12, 2024
1 parent ca94003 commit ad32192
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.axway.apim.api.export.ExportAPI;
import com.axway.apim.api.export.jackson.serializer.APIExportSerializerModifier;
import com.axway.apim.api.export.lib.params.APIExportParams;
import com.axway.apim.api.model.AuthType;
import com.axway.apim.api.model.AuthenticationProfile;
import com.axway.apim.api.model.CaCert;
import com.axway.apim.api.model.Image;
import com.axway.apim.api.specification.APISpecification;
Expand All @@ -30,6 +32,7 @@
import java.io.IOException;
import java.util.Base64;
import java.util.List;
import java.util.Map;

public class ExportHelper {

Expand Down Expand Up @@ -84,6 +87,8 @@ public void saveAPILocally(ExportAPI exportAPI, APIResultHandler apiResultHandle
storeCaCerts(localFolder, exportAPI.getCaCerts());
}

storePrivateCerts(localFolder, exportAPI.getAuthenticationProfiles());

mapper.registerModule(new SimpleModule().setSerializerModifier(new APIExportSerializerModifier()));
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
Expand Down Expand Up @@ -135,6 +140,27 @@ private void storeCaCerts(File localFolder, List<CaCert> caCerts) throws AppExce
}
}

private void storePrivateCerts(File localFolder, List<AuthenticationProfile> authenticationProfiles) throws AppException {
for (AuthenticationProfile profile : authenticationProfiles) {
if (profile.getType() == AuthType.ssl && !EnvironmentProperties.PRINT_CONFIG_CONSOLE) {
try {
Map<String, Object> parameters = profile.getParameters();
String pfx = (String) parameters.get("pfx");
String content = pfx.replaceFirst("data:.+,", "");
byte[] data = Base64.getMimeDecoder().decode(content.replace("\\r\\n","\n"));
String fileName = "backend_cert.pfx";
writeBytesToFile(data, localFolder + "/" + fileName);
parameters.remove("pfx");
parameters.put("certFile", fileName);

} catch (AppException e) {
throw new AppException("Can't write certificate to disc", ErrorCode.UNXPECTED_ERROR, e);
}
}
}
}


public void writeContent(ObjectMapper mapper, ExportAPI exportAPI, File localFolder, String configFile) throws AppException {
try {
mapper.enable(SerializationFeature.INDENT_OUTPUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.axway.apim.apiimport.lib.params.APIImportParams;
import com.axway.apim.lib.APIPropertiesExport;
import com.axway.apim.lib.CoreParameters;
import com.axway.apim.lib.EnvironmentProperties;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.lib.error.ErrorCode;
import com.axway.apim.lib.utils.Utils;
Expand Down Expand Up @@ -666,12 +667,9 @@ private void handleOutboundOAuthAuthN(AuthenticationProfile authnProfile) throws

private void handleOutboundSSLAuthN(AuthenticationProfile authnProfile) throws AppException {
if (!authnProfile.getType().equals(AuthType.ssl)) return;
if (EnvironmentProperties.PRINT_CONFIG_CONSOLE) return;
String keystore = (String) authnProfile.getParameters().get("certFile");
String password = (String) authnProfile.getParameters().get("password");
if (keystore.contains(":")) {
LOG.warn("Keystore format: <keystorename>:<type> is deprecated. Please remove the keystore type.");
keystore = keystore.split(":")[0];
}
File clientCertFile = new File(keystore);
try {
if (!clientCertFile.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class ImportSimpleApplicationTestIT extends TestNGCitrusSpringSupport {
public void run(@Optional @CitrusResource TestContext context) {
description("Import application into API-Manager");
variable("appName", "My-App-" + RandomNumberFunction.getRandomNumber(4, true));
variable("useApiAdmin", "true");
$(echo("####### Import application: '${appName}' #######"));
String updatedConfigFile = TestUtils.createTestConfig("/com/axway/apim/appimport/apps/basic/SimpleTestApplication.json", context, "apps", true);
$(testContext -> {
Expand Down

0 comments on commit ad32192

Please sign in to comment.