diff --git a/CHANGELOG.md b/CHANGELOG.md index 0162cdef84b..8174d2a804a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Fix #5264: Remove deprecated `Config.errorMessages` field * Fix #6008: removing the optional dependency on bouncy castle * Fix #6230: introduced Quantity.multiply(int) to allow for Quantity multiplication by an integer +* Fix #6247: Support for proxy authentication from proxy URL user info * Fix #6281: use GitHub binary repo for Kube API Tests * Fix #6282: Allow annotated types with Pattern, Min, and Max with Lists and Maps and CRD generation * Fix #5480: Move `io.fabric8:zjsonpatch` to KubernetesClient project diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java index 3022a748fce..d98d71d2ef8 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java @@ -123,12 +123,15 @@ public static Map createA return interceptors; } - public static String basicCredentials(String username, String password) { - String usernameAndPassword = username + ":" + password; + public static String basicCredentials(String usernameAndPassword) { String encoded = Base64.getEncoder().encodeToString(usernameAndPassword.getBytes(StandardCharsets.UTF_8)); return "Basic " + encoded; } + public static String basicCredentials(String username, String password) { + return basicCredentials(username + ":" + password); + } + /** * @deprecated you should not need to call this method directly. Please create your own HttpClient.Factory * should you need to customize your clients. @@ -229,6 +232,11 @@ static void configureProxy(Config config, HttpClient.Builder builder) builder.proxyAuthorization(basicCredentials(config.getProxyUsername(), config.getProxyPassword())); } + String userInfo = proxyUri.getUserInfo(); + if (userInfo != null) { + builder.proxyAuthorization(basicCredentials(userInfo)); + } + builder.proxyType(toProxyType(proxyUri.getScheme())); } } diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java index 25cfcaed57e..208c8c39267 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java @@ -90,6 +90,18 @@ void testConfigureSocksProxy() throws Exception { Mockito.verify(builder).proxyAddress(new InetSocketAddress("192.168.0.1", 8080)); } + @Test + void testConfigureProxyAuth() throws Exception { + Config config = new ConfigBuilder().withMasterUrl("http://localhost").withHttpProxy("http://user:password@192.168.0.1:8080") + .build(); + Builder builder = Mockito.mock(HttpClient.Builder.class, Mockito.RETURNS_SELF); + + HttpClientUtils.configureProxy(config, builder); + + Mockito.verify(builder).proxyType(HttpClient.ProxyType.HTTP); + Mockito.verify(builder).proxyAuthorization("Basic dXNlcjpwYXNzd29yZA=="); + } + @Test void testCreateApplicableInterceptors() { // Given