rewritten SSL support, refactor exporter
This commit is contained in:
parent
0fed5573d5
commit
b51689ea01
Binary file not shown.
@ -2,18 +2,21 @@ package cz.trask.migration;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.KeyStore;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -41,6 +44,8 @@ public abstract class AbstractProcess {
|
||||
|
||||
protected ConfigManager config = ConfigManager.getInstance();
|
||||
|
||||
private SSLContext sslCtx;
|
||||
|
||||
protected AbstractProcess() {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
@ -56,21 +61,25 @@ public abstract class AbstractProcess {
|
||||
});
|
||||
}
|
||||
|
||||
protected String getTrustStorePath() {
|
||||
String path = config.getTruststorePath();
|
||||
if (!new File(path).canRead()) {
|
||||
path = System.getProperty("user.dir") + File.separatorChar + config.getTruststorePath();
|
||||
if (!new File(path).canRead()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
protected void setTrustStoreCredentials() {
|
||||
log.info("Setting truststore: " + config.getTruststorePath());
|
||||
KeyStore trustStore;
|
||||
try {
|
||||
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
|
||||
try (FileInputStream tsFis = new FileInputStream(config.getTruststorePath())) {
|
||||
trustStore.load(tsFis, config.getTruststorePassword().toCharArray());
|
||||
}
|
||||
|
||||
protected void setTrustStoreCredentials() {
|
||||
log.info(getTrustStorePath());
|
||||
System.setProperty("javax.net.ssl.trustStore", getTrustStorePath());
|
||||
System.setProperty("javax.net.ssl.trustStorePassword", config.getTruststorePassword());
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
tmf.init(trustStore);
|
||||
|
||||
sslCtx = SSLContext.getInstance("TLS");
|
||||
sslCtx.init(null, tmf.getTrustManagers(), null);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Cannot set truststore.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,6 +252,7 @@ public abstract class AbstractProcess {
|
||||
URL url = new URL(urlStr);
|
||||
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
|
||||
con.setSSLSocketFactory(sslCtx.getSocketFactory());
|
||||
con.setRequestMethod("POST");
|
||||
con.setDoInput(true);
|
||||
con.setDoOutput(true);
|
||||
@ -323,7 +333,7 @@ public abstract class AbstractProcess {
|
||||
* @param api - zip file to upload
|
||||
* @throws Exception
|
||||
*/
|
||||
protected static HttpResponse makeFileRequest(String method, String urlStr, Map<String, String> httpHeaders,
|
||||
protected HttpResponse makeFileRequest(String method, String urlStr, Map<String, String> httpHeaders,
|
||||
byte[] buff, String attachmentFileName) throws Exception {
|
||||
|
||||
if (buff == null) {
|
||||
@ -338,6 +348,7 @@ public abstract class AbstractProcess {
|
||||
URL url = new URL(urlStr);
|
||||
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
|
||||
con.setSSLSocketFactory(sslCtx.getSocketFactory());
|
||||
con.setUseCaches(false);
|
||||
con.setDoOutput(true);
|
||||
|
||||
|
||||
@ -3,8 +3,8 @@ package cz.trask.migration;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import cz.trask.migration.impl.ExportToWso2;
|
||||
import cz.trask.migration.impl.v32.ImportToApicurio;
|
||||
import cz.trask.migration.impl.v45.ExportToWso2FromV32;
|
||||
import cz.trask.migration.model.StartParameters;
|
||||
|
||||
public class ApiSync {
|
||||
@ -27,7 +27,7 @@ public class ApiSync {
|
||||
imp.process();
|
||||
} else if (sp.getCommand().equals("export")) {
|
||||
log.info("Export command selected.");
|
||||
ExportToWso2 exp = new ExportToWso2();
|
||||
ExportToWso2FromV32 exp = new ExportToWso2FromV32();
|
||||
exp.process();
|
||||
log.error("Export command not implemented yet.");
|
||||
} else {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package cz.trask.migration.impl;
|
||||
package cz.trask.migration.impl.v45;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -24,15 +24,15 @@ import io.apicurio.registry.rest.v2.beans.SearchedArtifact;
|
||||
import io.apicurio.registry.rest.v2.beans.SearchedVersion;
|
||||
import io.apicurio.registry.rest.v2.beans.VersionSearchResults;
|
||||
|
||||
public class ExportToWso2 extends AbstractProcess {
|
||||
public class ExportToWso2FromV32 extends AbstractProcess {
|
||||
|
||||
private static final Logger log = LogManager.getLogger(ExportToWso2.class);
|
||||
private static final Logger log = LogManager.getLogger(ExportToWso2FromV32.class);
|
||||
|
||||
private final AtomicInteger apiCounter = new AtomicInteger(1);
|
||||
|
||||
private final RegistryClient client;
|
||||
|
||||
public ExportToWso2() throws Exception {
|
||||
public ExportToWso2FromV32() throws Exception {
|
||||
this.client = RegistryClientFactory.create(config.getApicurioApiUrl());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user