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