FIX 932 : take basic authentication from userInfo in the mven repository
URL
MODIFY
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/DefaultPluginRegistry.java
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/DefaultPluginRegistry.java
*/
package io.apiman.gateway.engine.impl;
-import io.apiman.common.plugin.Plugin;
-import io.apiman.common.plugin.PluginClassLoader;
-import io.apiman.common.plugin.PluginCoordinates;
-import io.apiman.common.plugin.PluginSpec;
-import io.apiman.common.plugin.PluginUtils;
-import io.apiman.gateway.engine.IPluginRegistry;
-import io.apiman.gateway.engine.async.AsyncResultImpl;
-import io.apiman.gateway.engine.async.IAsyncResult;
-import io.apiman.gateway.engine.async.IAsyncResultHandler;
-import io.apiman.gateway.engine.i18n.Messages;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -36,6 +25,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.HashSet;
@@ -51,6 +41,17 @@ import java.util.concurrent.TimeoutException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import io.apiman.common.plugin.Plugin;
+import io.apiman.common.plugin.PluginClassLoader;
+import io.apiman.common.plugin.PluginCoordinates;
+import io.apiman.common.plugin.PluginSpec;
+import io.apiman.common.plugin.PluginUtils;
+import io.apiman.gateway.engine.IPluginRegistry;
+import io.apiman.gateway.engine.async.AsyncResultImpl;
+import io.apiman.gateway.engine.async.IAsyncResult;
+import io.apiman.gateway.engine.async.IAsyncResultHandler;
+import io.apiman.gateway.engine.i18n.Messages;
+
/**
* A simple plugin registry that stores plugins in a temporary location. This
* implementation shouldn't really be used except for testing and perhaps getting
@@ -387,6 +388,11 @@ public class DefaultPluginRegistry implements IPluginRegistry {
OutputStream ostream = null;
try {
URLConnection connection = artifactUrl.openConnection();
+ // add the basic authentification contains in the Url
+ if (artifactUrl.getUserInfo() != null) {
+ String authStr = java.util.Base64.getEncoder().encodeToString(artifactUrl.getUserInfo().getBytes(StandardCharsets.UTF_8));
+ connection.addRequestProperty("Authorization", "Basic " + authStr);
+ }
connection.connect();
if (connection instanceof HttpURLConnection) {
HttpURLConnection httpConnection = (HttpURLConnection) connection;

MODIFY
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/engine/VertxPluginRegistry.java
gateway/platforms/vertx3/vertx3/src/main/java/io/apiman/gateway/platforms/vertx3/engine/VertxPluginRegistry.java
*/
package io.apiman.gateway.platforms.vertx3.engine;
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+
import io.apiman.gateway.engine.async.AsyncResultImpl;
import io.apiman.gateway.engine.async.IAsyncResultHandler;
import io.apiman.gateway.engine.impl.DefaultPluginRegistry;
@@ -27,20 +39,10 @@ import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpClientResponse;
+import io.vertx.core.http.HttpHeaders;
import io.vertx.core.net.ProxyOptions;
import io.vertx.core.net.ProxyType;
-import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.URL;
-import java.net.UnknownHostException;
-import java.nio.file.Files;
-import java.nio.file.StandardOpenOption;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Map;
-
/**
* A vertx implementation of the API Gateway's plugin registry. This version simply extends the default
* implementation but provides its own (actually asynchronous) downloading
@@ -155,6 +157,13 @@ public class VertxPluginRegistry extends DefaultPluginRegistry {
handler.handle(AsyncResultImpl.create(error, File.class));
});
+ // add the basic authentification contains in the Url
+ if (artifactUrl.getUserInfo() != null) {
+ String authStr = java.util.Base64.getEncoder().encodeToString(artifactUrl.getUserInfo().getBytes(StandardCharsets.UTF_8));
+ request.putHeader(HttpHeaders.AUTHORIZATION, "Basic " + authStr);
+ }
+
+
request.end();
}

FIX 932 : take basic authentication from userInfo in the mven repository (#936)

URL

Co-authored-by: S826330 <william.beck@apave.com>