endpoint security fixes, refactor
This commit is contained in:
parent
e26477e8d1
commit
f7da49a36c
Binary file not shown.
@ -38,7 +38,7 @@ import cz.trask.migration.config.ConfigManager;
|
|||||||
import cz.trask.migration.model.APIInfo;
|
import cz.trask.migration.model.APIInfo;
|
||||||
import cz.trask.migration.model.APIList;
|
import cz.trask.migration.model.APIList;
|
||||||
import cz.trask.migration.model.ApplicationConfig;
|
import cz.trask.migration.model.ApplicationConfig;
|
||||||
import cz.trask.migration.model.ApplicationConfig.Wso2Endpoints;
|
import cz.trask.migration.model.ApplicationConfig.Wso2Settings;
|
||||||
import cz.trask.migration.model.HttpResponse;
|
import cz.trask.migration.model.HttpResponse;
|
||||||
import cz.trask.migration.model.RegisterResponse;
|
import cz.trask.migration.model.RegisterResponse;
|
||||||
import cz.trask.migration.model.TokenResponse;
|
import cz.trask.migration.model.TokenResponse;
|
||||||
@ -58,8 +58,6 @@ public abstract class AbstractProcess {
|
|||||||
protected static final String PARAM_SOURCE_APIM = "source_apim";
|
protected static final String PARAM_SOURCE_APIM = "source_apim";
|
||||||
protected static final String VERSION_32 = "v32";
|
protected static final String VERSION_32 = "v32";
|
||||||
|
|
||||||
public static final String PRIVATE_KEY_APIM_32 = "wso2apim32-pk.pem";
|
|
||||||
|
|
||||||
public static final String ARTIFACT_GROUP_SUBSCRIPTIONS = "SUBSCRIPTIONS";
|
public static final String ARTIFACT_GROUP_SUBSCRIPTIONS = "SUBSCRIPTIONS";
|
||||||
public static final String ARTIFACT_NAME_SUBSCRIPTIONS = "subs.yaml";
|
public static final String ARTIFACT_NAME_SUBSCRIPTIONS = "subs.yaml";
|
||||||
|
|
||||||
@ -155,7 +153,7 @@ public abstract class AbstractProcess {
|
|||||||
connection.setSSLSocketFactory(sslContext.getSocketFactory());
|
connection.setSSLSocketFactory(sslContext.getSocketFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TokenResponse authenticateToWso2AndGetToken(Wso2Endpoints endpoints) throws Exception {
|
protected TokenResponse authenticateToWso2AndGetToken(Wso2Settings endpoints) throws Exception {
|
||||||
RegisterResponse register = register(endpoints.getRegistrationApiUrl(), endpoints.getWso2User());
|
RegisterResponse register = register(endpoints.getRegistrationApiUrl(), endpoints.getWso2User());
|
||||||
|
|
||||||
String clientId = register.getClientId();
|
String clientId = register.getClientId();
|
||||||
@ -282,7 +280,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(proxy!=null ? proxy : Proxy.NO_PROXY);
|
||||||
con.setRequestMethod(method);
|
con.setRequestMethod(method);
|
||||||
con.setDoInput(true);
|
con.setDoInput(true);
|
||||||
configureHttpsConnection(con);
|
configureHttpsConnection(con);
|
||||||
@ -345,7 +343,7 @@ public abstract class AbstractProcess {
|
|||||||
|
|
||||||
URL url = new URL(urlStr);
|
URL url = new URL(urlStr);
|
||||||
|
|
||||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(proxy);
|
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(proxy!=null ? proxy : Proxy.NO_PROXY);
|
||||||
con.setRequestMethod("POST");
|
con.setRequestMethod("POST");
|
||||||
con.setDoInput(true);
|
con.setDoInput(true);
|
||||||
con.setDoOutput(true);
|
con.setDoOutput(true);
|
||||||
@ -457,7 +455,7 @@ public abstract class AbstractProcess {
|
|||||||
|
|
||||||
URL url = new URL(urlStr);
|
URL url = new URL(urlStr);
|
||||||
|
|
||||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(proxy);
|
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(proxy!=null ? proxy : Proxy.NO_PROXY);
|
||||||
con.setUseCaches(false);
|
con.setUseCaches(false);
|
||||||
con.setDoOutput(true);
|
con.setDoOutput(true);
|
||||||
configureHttpsConnection(con);
|
configureHttpsConnection(con);
|
||||||
@ -510,6 +508,31 @@ public abstract class AbstractProcess {
|
|||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int publishApiToWso2(String fileName, byte[] data, TokenResponse tokenResponse) {
|
||||||
|
int responseCode = -1;
|
||||||
|
try {
|
||||||
|
String url = config.getTarget().getPublisherApiUrl()
|
||||||
|
.concat(String.format("?preserveProvider=false&overwrite=true"));
|
||||||
|
|
||||||
|
log.info("API Import URL: " + url);
|
||||||
|
|
||||||
|
Map<String, String> httpHeaders = new HashMap<>();
|
||||||
|
|
||||||
|
httpHeaders.put("Authorization", "Bearer " + tokenResponse.getAccess_token());
|
||||||
|
|
||||||
|
HttpResponse response = makeFileRequest("POST", url, httpHeaders, data, fileName);
|
||||||
|
|
||||||
|
responseCode = response.getResponseCode();
|
||||||
|
|
||||||
|
if (response.getResponseCode() != 201 && response.getResponseCode() != 200) {
|
||||||
|
log.info("Cannot import API file: " + fileName + ", response code: " + response.getResponseCode());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("IO error while importing API file: " + fileName + ", error: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return responseCode;
|
||||||
|
}
|
||||||
|
|
||||||
protected void setArtifactMetaData(ArtifactMetaData meta, String name, String description, Map<String, String> props) {
|
protected void setArtifactMetaData(ArtifactMetaData meta, String name, String description, Map<String, String> props) {
|
||||||
EditableMetaData metaData = new EditableMetaData();
|
EditableMetaData metaData = new EditableMetaData();
|
||||||
metaData.setName(name);
|
metaData.setName(name);
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import cz.trask.migration.impl.v32.Wso2AppsToApicurio;
|
import cz.trask.migration.impl.v32.Wso2AppsToApicurio;
|
||||||
import cz.trask.migration.impl.v32.Wso2v32ToApicurio;
|
import cz.trask.migration.impl.v32.Wso2v32ToApicurio;
|
||||||
import cz.trask.migration.impl.v32.Wso2v32ToApicurioFromDir;
|
import cz.trask.migration.impl.v32.Wso2v32ToApicurioFromDir;
|
||||||
|
import cz.trask.migration.impl.v45.ApiFilesToWso2;
|
||||||
import cz.trask.migration.impl.v45.ExportApisToWso2FromV32;
|
import cz.trask.migration.impl.v45.ExportApisToWso2FromV32;
|
||||||
import cz.trask.migration.impl.v45.ExportAppsToWso2FromV32;
|
import cz.trask.migration.impl.v45.ExportAppsToWso2FromV32;
|
||||||
import cz.trask.migration.model.StartParameters;
|
import cz.trask.migration.model.StartParameters;
|
||||||
@ -44,6 +45,10 @@ public class ApiSync {
|
|||||||
log.info("apicurioAppsToWso2 command selected.");
|
log.info("apicurioAppsToWso2 command selected.");
|
||||||
ExportAppsToWso2FromV32 exp = new ExportAppsToWso2FromV32();
|
ExportAppsToWso2FromV32 exp = new ExportAppsToWso2FromV32();
|
||||||
exp.process();
|
exp.process();
|
||||||
|
} else if (sp.getCommand().equalsIgnoreCase("apiFilesToWso2")) {
|
||||||
|
log.info("apiFilesToWso2 command selected.");
|
||||||
|
ApiFilesToWso2 imp = new ApiFilesToWso2();
|
||||||
|
imp.process();
|
||||||
} else {
|
} else {
|
||||||
log.error("Unknown command: " + sp.getCommand());
|
log.error("Unknown command: " + sp.getCommand());
|
||||||
printHelp();
|
printHelp();
|
||||||
|
|||||||
@ -0,0 +1,86 @@
|
|||||||
|
package cz.trask.migration.impl.v45;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import cz.trask.migration.AbstractProcess;
|
||||||
|
import cz.trask.migration.model.TokenResponse;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
public class ApiFilesToWso2 extends AbstractProcess {
|
||||||
|
|
||||||
|
private final AtomicInteger apiCounter = new AtomicInteger(1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main entry point for the import process.
|
||||||
|
*
|
||||||
|
* @throws RuntimeException if any error occurs
|
||||||
|
*/
|
||||||
|
public void process() {
|
||||||
|
try {
|
||||||
|
log.info("Starting API import to WSO2 from directory...");
|
||||||
|
|
||||||
|
TokenResponse token = authenticateToWso2AndGetToken(config.getTarget());
|
||||||
|
|
||||||
|
File root = new File(config.getSource().getWso2ApisDir());
|
||||||
|
|
||||||
|
File[] apiFiles = root.listFiles((dir, name) -> name.endsWith(".zip"));
|
||||||
|
if (apiFiles == null || apiFiles.length == 0) {
|
||||||
|
log.warn("No API zip files found in directory: {}", config.getSource().getWso2ApisDir());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Found {} APIs", apiFiles.length);
|
||||||
|
|
||||||
|
for (File api : apiFiles) {
|
||||||
|
final int index = apiCounter.getAndIncrement();
|
||||||
|
processApi(api, token, index, apiFiles.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Finished processing APIs.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error while importing APIs.", e);
|
||||||
|
throw new RuntimeException("Import failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process a single API – fetches the data, creates or updates the corresponding
|
||||||
|
* artifact in WSO2.
|
||||||
|
*/
|
||||||
|
private void processApi(File apiFile, TokenResponse token, int index, int total) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("Processing API {} of {}", index, total);
|
||||||
|
|
||||||
|
String fileName = apiFile.getName();
|
||||||
|
byte[] data = null;
|
||||||
|
try {
|
||||||
|
data = Files.readAllBytes(apiFile.toPath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Failed to read API file '{}': {}", apiFile.getName(), e.getMessage(), e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data != null && data.length > 0 && fileName != null && !fileName.isEmpty()) {
|
||||||
|
int responseCode = publishApiToWso2(fileName, data, token);
|
||||||
|
if (responseCode == 200 || responseCode == 201) {
|
||||||
|
log.info(" - API version {} imported successfully", fileName);
|
||||||
|
} else {
|
||||||
|
log.warn(" - API version {} import failed with response code {}", fileName,
|
||||||
|
responseCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Successfully imported API '{}' ({}). Took {} ms", apiFile.getName(),
|
||||||
|
apiFile.getName(),
|
||||||
|
System.currentTimeMillis() - start);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Cannot export API '{}': {}", apiFile.getName(), e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,9 +5,7 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -23,7 +21,6 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|||||||
import cz.trask.migration.AbstractProcess;
|
import cz.trask.migration.AbstractProcess;
|
||||||
import cz.trask.migration.mapper.ApiDefinitionMapper32to45;
|
import cz.trask.migration.mapper.ApiDefinitionMapper32to45;
|
||||||
import cz.trask.migration.model.FileType;
|
import cz.trask.migration.model.FileType;
|
||||||
import cz.trask.migration.model.HttpResponse;
|
|
||||||
import cz.trask.migration.model.TokenResponse;
|
import cz.trask.migration.model.TokenResponse;
|
||||||
import cz.trask.migration.model.v32.ApiDefinition32;
|
import cz.trask.migration.model.v32.ApiDefinition32;
|
||||||
import cz.trask.migration.model.v32.Documents32;
|
import cz.trask.migration.model.v32.Documents32;
|
||||||
@ -136,31 +133,6 @@ public class ExportApisToWso2FromV32 extends AbstractProcess {
|
|||||||
/* Helper methods */
|
/* Helper methods */
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
private int publishApiToWso2(String fileName, byte[] data, TokenResponse tokenResponse) {
|
|
||||||
int responseCode = -1;
|
|
||||||
try {
|
|
||||||
String url = config.getTarget().getPublisherApiUrl()
|
|
||||||
.concat(String.format("?preserveProvider=false&overwrite=true"));
|
|
||||||
|
|
||||||
log.info("API Import URL: " + url);
|
|
||||||
|
|
||||||
Map<String, String> httpHeaders = new HashMap<>();
|
|
||||||
|
|
||||||
httpHeaders.put("Authorization", "Bearer " + tokenResponse.getAccess_token());
|
|
||||||
|
|
||||||
HttpResponse response = makeFileRequest("POST", url, httpHeaders, data, fileName);
|
|
||||||
|
|
||||||
responseCode = response.getResponseCode();
|
|
||||||
|
|
||||||
if (response.getResponseCode() != 201 && response.getResponseCode() != 200) {
|
|
||||||
log.info("Cannot import API file: " + fileName + ", response code: " + response.getResponseCode());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("IO error while importing API file: " + fileName + ", error: " + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
return responseCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] prepareApiZipFile32to45(SearchedVersion ver, List<ArtifactReference> ref) throws Exception {
|
public byte[] prepareApiZipFile32to45(SearchedVersion ver, List<ArtifactReference> ref) throws Exception {
|
||||||
|
|
||||||
String baseDir = ver.getName() + "-" + ver.getVersion() + "/";
|
String baseDir = ver.getName() + "-" + ver.getVersion() + "/";
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import cz.trask.migration.model.v45.ApiDefinition45;
|
|||||||
import cz.trask.migration.model.v45.ApiDefinition45.ApiPolicies;
|
import cz.trask.migration.model.v45.ApiDefinition45.ApiPolicies;
|
||||||
import cz.trask.migration.model.v45.ApiDefinition45.Operation;
|
import cz.trask.migration.model.v45.ApiDefinition45.Operation;
|
||||||
import cz.trask.migration.model.v45.ApiDefinition45.OperationPolicies;
|
import cz.trask.migration.model.v45.ApiDefinition45.OperationPolicies;
|
||||||
|
import cz.trask.migration.util.CredentialsDecoder;
|
||||||
|
|
||||||
public class ApiDefinitionMapper32to45 {
|
public class ApiDefinitionMapper32to45 {
|
||||||
|
|
||||||
@ -54,13 +55,15 @@ public class ApiDefinitionMapper32to45 {
|
|||||||
oldApi.getTransports() != null ? List.of(oldApi.getTransports().split(",")) : Collections.emptyList());
|
oldApi.getTransports() != null ? List.of(oldApi.getTransports().split(",")) : Collections.emptyList());
|
||||||
data.setTags(oldApi.getTags());
|
data.setTags(oldApi.getTags());
|
||||||
data.setVisibility(oldApi.getVisibility().toUpperCase());
|
data.setVisibility(oldApi.getVisibility().toUpperCase());
|
||||||
//data.setVisibleRoles(oldApi.getVisibleRoles()!=null ? List.of(oldApi.getVisibleRoles().split(",")) : Collections.emptyList());
|
// data.setVisibleRoles(oldApi.getVisibleRoles()!=null ?
|
||||||
|
// List.of(oldApi.getVisibleRoles().split(",")) : Collections.emptyList());
|
||||||
data.setVisibleRoles(List.of("Internal/publisher"));
|
data.setVisibleRoles(List.of("Internal/publisher"));
|
||||||
data.setVisibleTenants(Collections.emptyList());
|
data.setVisibleTenants(Collections.emptyList());
|
||||||
data.setAccessControl("NONE");
|
data.setAccessControl("NONE");
|
||||||
//data.setAccessControlRoles(Collections.emptyList());
|
// data.setAccessControlRoles(Collections.emptyList());
|
||||||
data.setOrganizationPolicies(Collections.emptyList());
|
data.setOrganizationPolicies(Collections.emptyList());
|
||||||
data.setType(oldApi.getType()!=null && !oldApi.getType().toLowerCase().equals("null") ? oldApi.getType() : "HTTP");
|
data.setType(
|
||||||
|
oldApi.getType() != null && !oldApi.getType().toLowerCase().equals("null") ? oldApi.getType() : "HTTP");
|
||||||
data.setAudiences(Arrays.asList("all"));
|
data.setAudiences(Arrays.asList("all"));
|
||||||
|
|
||||||
List<String> policies = new ArrayList<>();
|
List<String> policies = new ArrayList<>();
|
||||||
@ -102,7 +105,7 @@ public class ApiDefinitionMapper32to45 {
|
|||||||
data.setCorsConfiguration(mapCors(oldApi.getCorsConfiguration()));
|
data.setCorsConfiguration(mapCors(oldApi.getCorsConfiguration()));
|
||||||
|
|
||||||
// ---------- endpoint ----------
|
// ---------- endpoint ----------
|
||||||
data.setEndpointConfig(fixEndpointConfig(oldApi.getEndpointConfig()));
|
data.setEndpointConfig(mapEndpointConfig(oldApi.getEndpointConfig()));
|
||||||
data.setEndpointImplementationType(oldApi.getImplementation());
|
data.setEndpointImplementationType(oldApi.getImplementation());
|
||||||
|
|
||||||
// ---------- API policies ----------
|
// ---------- API policies ----------
|
||||||
@ -155,23 +158,67 @@ public class ApiDefinitionMapper32to45 {
|
|||||||
return newApi;
|
return newApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map fixEndpointConfig(Map endpointConfig) {
|
private static Map mapEndpointConfig(Map endpointConfig) {
|
||||||
if (endpointConfig == null || endpointConfig.isEmpty())
|
if (endpointConfig == null || endpointConfig.isEmpty())
|
||||||
return new HashMap();
|
return new HashMap();
|
||||||
|
|
||||||
Map<String, Object> endpointProd = (Map<String, Object>) endpointConfig.get("production_endpoints");
|
if (endpointConfig.get("production_endpoints") != null
|
||||||
if (endpointProd != null && endpointProd.containsKey("config")) {
|
&& (endpointConfig.get("production_endpoints") instanceof Map)) {
|
||||||
Object value = endpointProd.get("config");
|
Map<String, Object> endpointProd = (Map<String, Object>) endpointConfig.get("production_endpoints");
|
||||||
if (value==null) {
|
if (endpointProd != null && endpointProd.containsKey("config")) {
|
||||||
endpointProd.remove("config");
|
Object value = endpointProd.get("config");
|
||||||
|
if (value == null) {
|
||||||
|
endpointProd.remove("config");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> endpointSand = (Map<String, Object>) endpointConfig.get("sandbox_endpoints");
|
if (endpointConfig.get("sandbox_endpoints") != null && (endpointConfig.get("sandbox_endpoints") instanceof Map)) {
|
||||||
if (endpointSand != null && endpointSand.containsKey("config")) {
|
Map<String, Object> endpointSand = (Map<String, Object>) endpointConfig.get("sandbox_endpoints");
|
||||||
Object value = endpointSand.get("config");
|
if (endpointSand != null && endpointSand.containsKey("config")) {
|
||||||
if (value==null) {
|
Object value = endpointSand.get("config");
|
||||||
endpointSand.remove("config");
|
if (value == null) {
|
||||||
|
endpointSand.remove("config");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endpointConfig.get("endpoint_security") != null && (endpointConfig.get("endpoint_security") instanceof Map)) {
|
||||||
|
Map<String, Object> endpointSecurity = (Map<String, Object>) endpointConfig.get("endpoint_security");
|
||||||
|
Map<String, Object> sandbox = endpointSecurity.get("sandbox") != null
|
||||||
|
&& endpointSecurity.get("sandbox") instanceof Map
|
||||||
|
? (Map<String, Object>) endpointSecurity.get("sandbox")
|
||||||
|
: null;
|
||||||
|
Map<String, Object> production = endpointSecurity.get("production") != null
|
||||||
|
&& endpointSecurity.get("production") instanceof Map
|
||||||
|
? (Map<String, Object>) endpointSecurity.get("production")
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (sandbox != null && sandbox.containsKey("clientSecret") && sandbox.get("clientSecret") != null) {
|
||||||
|
String encodedSecret = sandbox.get("clientSecret").toString();
|
||||||
|
sandbox.put("clientSecret", CredentialsDecoder.decodeCredentials(encodedSecret));
|
||||||
|
}
|
||||||
|
if (production != null && production.containsKey("clientSecret") && production.get("clientSecret") != null) {
|
||||||
|
String encodedSecret = production.get("clientSecret").toString();
|
||||||
|
production.put("clientSecret", CredentialsDecoder.decodeCredentials(encodedSecret));
|
||||||
|
}
|
||||||
|
if (sandbox != null && sandbox.containsKey("customParameters") && sandbox.get("customParameters") != null) {
|
||||||
|
String customParamsStr = sandbox.get("customParameters").toString();
|
||||||
|
try {
|
||||||
|
Map<String, Object> customParams = AbstractProcess.mapperYaml.readValue(customParamsStr, Map.class);
|
||||||
|
sandbox.put("customParameters", customParams);
|
||||||
|
} catch (Exception e) {
|
||||||
|
sandbox.put("customParameters", Collections.emptyMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (production != null && production.containsKey("customParameters") && production.get("customParameters") != null) {
|
||||||
|
String customParamsStr = production.get("customParameters").toString();
|
||||||
|
try {
|
||||||
|
Map<String, Object> customParams = AbstractProcess.mapperYaml.readValue(customParamsStr, Map.class);
|
||||||
|
production.put("customParameters", customParams);
|
||||||
|
} catch (Exception e) {
|
||||||
|
production.put("customParameters", Collections.emptyMap());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,73 +306,81 @@ public class ApiDefinitionMapper32to45 {
|
|||||||
return cors;
|
return cors;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private static ApiDefinition45.EndpointConfig mapEndpointConfig(ApiDefinition32.EndpointConfig oldEndpoint) {
|
// private static ApiDefinition45.EndpointConfig
|
||||||
// if (oldEndpoint == null)
|
// mapEndpointConfig(ApiDefinition32.EndpointConfig oldEndpoint) {
|
||||||
// return null;
|
// if (oldEndpoint == null)
|
||||||
//
|
// return null;
|
||||||
// ApiDefinition45.EndpointConfig newEndpoint = new ApiDefinition45.EndpointConfig();
|
//
|
||||||
// newEndpoint.setEndpoint_type(oldEndpoint.getEndpointType());
|
// ApiDefinition45.EndpointConfig newEndpoint = new
|
||||||
//
|
// ApiDefinition45.EndpointConfig();
|
||||||
// if (oldEndpoint.getSandboxEndpoints() != null) {
|
// newEndpoint.setEndpoint_type(oldEndpoint.getEndpointType());
|
||||||
// ApiDefinition45.EndpointGroup sandbox = new ApiDefinition45.EndpointGroup();
|
//
|
||||||
// sandbox.setUrl(oldEndpoint.getSandboxEndpoints().getUrl());
|
// if (oldEndpoint.getSandboxEndpoints() != null) {
|
||||||
// newEndpoint.setSandbox_endpoints(sandbox);
|
// ApiDefinition45.EndpointGroup sandbox = new ApiDefinition45.EndpointGroup();
|
||||||
// }
|
// sandbox.setUrl(oldEndpoint.getSandboxEndpoints().getUrl());
|
||||||
//
|
// newEndpoint.setSandbox_endpoints(sandbox);
|
||||||
// if (oldEndpoint.getProductionEndpoints() != null) {
|
// }
|
||||||
// ApiDefinition45.EndpointGroup production = new ApiDefinition45.EndpointGroup();
|
//
|
||||||
// production.setUrl(oldEndpoint.getProductionEndpoints().getUrl());
|
// if (oldEndpoint.getProductionEndpoints() != null) {
|
||||||
// newEndpoint.setProduction_endpoints(production);
|
// ApiDefinition45.EndpointGroup production = new
|
||||||
// }
|
// ApiDefinition45.EndpointGroup();
|
||||||
//
|
// production.setUrl(oldEndpoint.getProductionEndpoints().getUrl());
|
||||||
// if (oldEndpoint.getEndpointSecurity() != null) {
|
// newEndpoint.setProduction_endpoints(production);
|
||||||
// ApiDefinition45.EndpointSecurity security = new ApiDefinition45.EndpointSecurity();
|
// }
|
||||||
// security.setSandbox(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getSandbox()));
|
//
|
||||||
// security.setProduction(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getProduction()));
|
// if (oldEndpoint.getEndpointSecurity() != null) {
|
||||||
// newEndpoint.setEndpoint_security(security);
|
// ApiDefinition45.EndpointSecurity security = new
|
||||||
// }
|
// ApiDefinition45.EndpointSecurity();
|
||||||
//
|
// security.setSandbox(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getSandbox()));
|
||||||
// return newEndpoint;
|
// security.setProduction(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getProduction()));
|
||||||
// }
|
// newEndpoint.setEndpoint_security(security);
|
||||||
//
|
// }
|
||||||
// private static ApiDefinition45.SecurityEnv mapSecurityEnv(ApiDefinition32.SecurityEnvironment oldSec) {
|
//
|
||||||
// if (oldSec == null)
|
// return newEndpoint;
|
||||||
// return null;
|
// }
|
||||||
//
|
//
|
||||||
// ApiDefinition45.SecurityEnv newSec = new ApiDefinition45.SecurityEnv();
|
// private static ApiDefinition45.SecurityEnv
|
||||||
// newSec.setType(oldSec.getType());
|
// mapSecurityEnv(ApiDefinition32.SecurityEnvironment oldSec) {
|
||||||
// newSec.setTokenUrl(oldSec.getTokenUrl());
|
// if (oldSec == null)
|
||||||
// newSec.setClientId(oldSec.getClientId());
|
// return null;
|
||||||
// newSec.setClientSecret(
|
//
|
||||||
// CredentialsDecoder.decodeCredentials(oldSec.getClientSecret(), AbstractProcess.PRIVATE_KEY_APIM_32));
|
// ApiDefinition45.SecurityEnv newSec = new ApiDefinition45.SecurityEnv();
|
||||||
// newSec.setUsername(oldSec.getUsername());
|
// newSec.setType(oldSec.getType());
|
||||||
// newSec.setPassword(oldSec.getPassword());
|
// newSec.setTokenUrl(oldSec.getTokenUrl());
|
||||||
// newSec.setGrantType(oldSec.getGrantType());
|
// newSec.setClientId(oldSec.getClientId());
|
||||||
// newSec.setEnabled(oldSec.isEnabled());
|
// newSec.setClientSecret(
|
||||||
// newSec.setConnectionTimeoutDuration(0);
|
// CredentialsDecoder.decodeCredentials(oldSec.getClientSecret(),
|
||||||
// newSec.setSocketTimeoutDuration(0);
|
// AbstractProcess.PRIVATE_KEY_APIM_32));
|
||||||
// newSec.setConnectionRequestTimeoutDuration(0);
|
// newSec.setUsername(oldSec.getUsername());
|
||||||
// newSec.setProxyConfigs(new ApiDefinition45.ProxyConfigs());
|
// newSec.setPassword(oldSec.getPassword());
|
||||||
//
|
// newSec.setGrantType(oldSec.getGrantType());
|
||||||
// // ---------- parse customParameters JSON string ----------
|
// newSec.setEnabled(oldSec.isEnabled());
|
||||||
// if (oldSec.getCustomParameters() != null && !oldSec.getCustomParameters().isEmpty()) {
|
// newSec.setConnectionTimeoutDuration(0);
|
||||||
// try {
|
// newSec.setSocketTimeoutDuration(0);
|
||||||
// Map<String, Object> map = AbstractProcess.mapperYaml.readValue(oldSec.getCustomParameters(),
|
// newSec.setConnectionRequestTimeoutDuration(0);
|
||||||
// new TypeReference<>() {
|
// newSec.setProxyConfigs(new ApiDefinition45.ProxyConfigs());
|
||||||
// });
|
//
|
||||||
// newSec.setCustomParameters(map);
|
// // ---------- parse customParameters JSON string ----------
|
||||||
// } catch (Exception e) {
|
// if (oldSec.getCustomParameters() != null &&
|
||||||
// newSec.setCustomParameters(Collections.emptyMap());
|
// !oldSec.getCustomParameters().isEmpty()) {
|
||||||
// }
|
// try {
|
||||||
// } else {
|
// Map<String, Object> map =
|
||||||
// newSec.setCustomParameters(Collections.emptyMap());
|
// AbstractProcess.mapperYaml.readValue(oldSec.getCustomParameters(),
|
||||||
// }
|
// new TypeReference<>() {
|
||||||
//
|
// });
|
||||||
// // ---------- parse additionalProperties JSON string ----------
|
// newSec.setCustomParameters(map);
|
||||||
// newSec.setAdditionalProperties(Collections.emptyMap());
|
// } catch (Exception e) {
|
||||||
//
|
// newSec.setCustomParameters(Collections.emptyMap());
|
||||||
// return newSec;
|
// }
|
||||||
// }
|
// } else {
|
||||||
|
// newSec.setCustomParameters(Collections.emptyMap());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // ---------- parse additionalProperties JSON string ----------
|
||||||
|
// newSec.setAdditionalProperties(Collections.emptyMap());
|
||||||
|
//
|
||||||
|
// return newSec;
|
||||||
|
// }
|
||||||
|
|
||||||
public static List<Operation> mapOperations(String swaggerYamlString) throws Exception {
|
public static List<Operation> mapOperations(String swaggerYamlString) throws Exception {
|
||||||
JsonNode root = AbstractProcess.mapperYaml.readTree(swaggerYamlString);
|
JsonNode root = AbstractProcess.mapperYaml.readTree(swaggerYamlString);
|
||||||
|
|||||||
@ -8,9 +8,9 @@ import lombok.Data;
|
|||||||
public class ApplicationConfig {
|
public class ApplicationConfig {
|
||||||
|
|
||||||
@JsonProperty("source")
|
@JsonProperty("source")
|
||||||
private Wso2Endpoints source;
|
private Wso2Settings source;
|
||||||
@JsonProperty("target")
|
@JsonProperty("target")
|
||||||
private Wso2Endpoints target;
|
private Wso2Settings target;
|
||||||
@JsonProperty("truststore")
|
@JsonProperty("truststore")
|
||||||
private TrustStore trustStore;
|
private TrustStore trustStore;
|
||||||
@JsonProperty("patterns")
|
@JsonProperty("patterns")
|
||||||
@ -51,7 +51,7 @@ public class ApplicationConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class Wso2Endpoints {
|
public static class Wso2Settings {
|
||||||
@JsonProperty("registration_api_url")
|
@JsonProperty("registration_api_url")
|
||||||
private String registrationApiUrl;
|
private String registrationApiUrl;
|
||||||
@JsonProperty("publisher_api_url")
|
@JsonProperty("publisher_api_url")
|
||||||
@ -66,7 +66,8 @@ public class ApplicationConfig {
|
|||||||
private String wso2User;
|
private String wso2User;
|
||||||
@JsonProperty("wso2_apis_dir")
|
@JsonProperty("wso2_apis_dir")
|
||||||
private String wso2ApisDir;
|
private String wso2ApisDir;
|
||||||
|
@JsonProperty("secrets_decryption_cert")
|
||||||
|
private String secretsDecryptionCert;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@ -12,12 +12,13 @@ import javax.crypto.Cipher;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import cz.trask.migration.config.ConfigManager;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class CredentialsDecoder {
|
public class CredentialsDecoder {
|
||||||
|
|
||||||
public static String decodeCredentials(String credentials, String pkFile) {
|
public static String decodeCredentials(String credentials) {
|
||||||
if (credentials == null || credentials.isEmpty()) {
|
if (credentials == null || credentials.isEmpty()) {
|
||||||
log.warn("No credentials provided to decode.");
|
log.warn("No credentials provided to decode.");
|
||||||
return null;
|
return null;
|
||||||
@ -33,7 +34,7 @@ public class CredentialsDecoder {
|
|||||||
String transformation = jsonMap.get("t");
|
String transformation = jsonMap.get("t");
|
||||||
log.debug("Used algorithm: {}", transformation);
|
log.debug("Used algorithm: {}", transformation);
|
||||||
|
|
||||||
String privateKeyPEM = new String(Files.readAllBytes(Paths.get(pkFile)))
|
String privateKeyPEM = new String(Files.readAllBytes(Paths.get(ConfigManager.getInstance().getConfig().getSource().getSecretsDecryptionCert())))
|
||||||
.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "")
|
.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "")
|
||||||
.replaceAll("\\s+", "");
|
.replaceAll("\\s+", "");
|
||||||
byte[] privateKeyBytes = Base64.getDecoder().decode(privateKeyPEM);
|
byte[] privateKeyBytes = Base64.getDecoder().decode(privateKeyPEM);
|
||||||
|
|||||||
@ -1,23 +1,24 @@
|
|||||||
proxy:
|
#proxy:
|
||||||
host: proxy.jtfg.com
|
# host: proxy.jtfg.com
|
||||||
port: 3128
|
# port: 3128
|
||||||
|
|
||||||
source:
|
source:
|
||||||
registration_api_url: https://developerstest.jtfg.com/client-registration/v0.17/register
|
registration_api_url: https://localhost:9444/client-registration/v0.17/register
|
||||||
publisher_api_url: https://developerstest.jtfg.com/api/am/publisher
|
publisher_api_url: https://localhost:9444/api/am/publisher
|
||||||
admin_api_url: https://developerstest.jtfg.com/api/am/admin/v1
|
admin_api_url: https://localhost:9444/api/am/admin/v1
|
||||||
devportal_api_url: https://developerstest.jtfg.com/api/am/store
|
devportal_api_url: https://localhost:9444/api/am/store
|
||||||
publisher_token_url: https://developerstest.jtfg.com/oauth2/token
|
publisher_token_url: https://localhost:9444/oauth2/token
|
||||||
wso2_user: YWRtaW46UkllSTVBeGN4LXZRQVZsSA==
|
secrets_decryption_cert: wso2apim32-pk.pem
|
||||||
wso2_apis_dir: apis
|
wso2_user: YWRtaW46YWRtaW4=
|
||||||
|
wso2_apis_dir: ./apis
|
||||||
|
|
||||||
target:
|
target:
|
||||||
registration_api_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/client-registration/v0.17/register
|
registration_api_url: https://localhost:9443/client-registration/v0.17/register
|
||||||
publisher_api_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/api/am/publisher/v4/apis/import
|
publisher_api_url: https://localhost:9443/api/am/publisher/v4/apis/import
|
||||||
admin_api_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/api/am/admin/v4
|
admin_api_url: https://localhost:9443/api/am/admin/v4
|
||||||
devportal_api_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/api/am/devportal
|
devportal_api_url: https://localhost:9443/api/am/devportal
|
||||||
publisher_token_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/oauth2/token
|
publisher_token_url: https://localhost:9443/oauth2/token
|
||||||
wso2_user: YWRtaW46Tiw5YzEpeFh0NTNr
|
wso2_user: YWRtaW46YWRtaW4=
|
||||||
|
|
||||||
truststore:
|
truststore:
|
||||||
path: client-truststore.jks
|
path: client-truststore.jks
|
||||||
@ -28,7 +29,7 @@ patterns:
|
|||||||
devportal_url_pattern: https://developers/devportal/apis/{API_ID}/overview
|
devportal_url_pattern: https://developers/devportal/apis/{API_ID}/overview
|
||||||
|
|
||||||
apicurio:
|
apicurio:
|
||||||
api_url: https://apim-apicurio-app-apim-wso2.apps.oshift-akc.jtfg.com/apis/registry/v2
|
api_url: http://apicurio:8095/apis/registry/v2
|
||||||
default_api_group: api
|
default_api_group: api
|
||||||
overwrite_existing_application: true
|
overwrite_existing_application: true
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user