Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "Apache5 HTTP Client (Preview)",
"contributor": "",
"description": "Fix bug where preemptive Basic authentication was not honored for proxies. Similar to fix for Apache 4.x in [#6333](https://github.com/aws/aws-sdk-java-v2/issues/6333)."
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private static void addPreemptiveAuthenticationProxy(HttpClientContext clientCon
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
basicAuth.initPreemptive(credsProvider.getCredentials(newAuthScope(proxyConfiguration), clientContext));
authCache.put(targetHost, basicAuth);

clientContext.setCredentialsProvider(credsProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import static com.github.tomakehurst.wiremock.client.WireMock.any;
import static com.github.tomakehurst.wiremock.client.WireMock.anyRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.matching;
import static org.assertj.core.api.Assertions.assertThat;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import java.net.URI;
import java.util.Base64;
Expand Down Expand Up @@ -66,6 +68,43 @@
}
}

@Test
public void proxyAuthentication_whenPreemptiveAuthEnabled_shouldSendProxyAuthorizationHeader() throws Exception {

Check warning on line 72 in http-clients/apache5-client/src/test/java/software/amazon/awssdk/http/apache5/Apache5HttpClientProxyAuthTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZq9u4JfgDJwnYYwAQPe&open=AZq9u4JfgDJwnYYwAQPe&pullRequest=6585
mockProxy.stubFor(any(anyUrl())
.withHeader("Proxy-Authorization", equalTo(BASIC_PROXY_AUTH_HEADER))
.willReturn(aResponse()
.withStatus(200)
.withBody("Success")));

// Create HTTP client with preemptive proxy authentication enabled
httpClient = Apache5HttpClient.builder()
.proxyConfiguration(ProxyConfiguration.builder()
.endpoint(URI.create("http://localhost:" + mockProxy.port()))
.username("testuser")
.password("testpass")
.preemptiveBasicAuthenticationEnabled(true)
.build())
.build();

// Create a request
SdkHttpRequest request = SdkHttpRequest.builder()
.method(SdkHttpMethod.GET)
.uri(URI.create("http://example.com/test"))
.build();

HttpExecuteRequest executeRequest = HttpExecuteRequest.builder()
.request(request)
.build();

// Execute the request - should succeed with preemptive auth header
HttpExecuteResponse response = httpClient.prepareRequest(executeRequest).call();
assertThat(response.httpResponse().statusCode()).isEqualTo(200);

mockProxy.verify(1, anyRequestedFor(anyUrl()));
mockProxy.verify(WireMock.getRequestedFor(anyUrl())
.withHeader("Proxy-Authorization", equalTo(BASIC_PROXY_AUTH_HEADER)));
}

@Test
public void proxyAuthentication_whenPreemptiveAuthDisabled_shouldUseChallengeResponseAuth() throws Exception {
// First request without auth header should get 407
Expand All @@ -83,13 +122,13 @@

// Create HTTP client with preemptive proxy authentication disabled
httpClient = Apache5HttpClient.builder()
.proxyConfiguration(ProxyConfiguration.builder()
.endpoint(URI.create("http://localhost:" + mockProxy.port()))
.username("testuser")
.password("testpass")
.preemptiveBasicAuthenticationEnabled(false)
.build())
.build();
.proxyConfiguration(ProxyConfiguration.builder()
.endpoint(URI.create("http://localhost:" + mockProxy.port()))
.username("testuser")
.password("testpass")
.preemptiveBasicAuthenticationEnabled(false)
.build())
.build();

// Create a request
SdkHttpRequest request = SdkHttpRequest.builder()
Expand Down
Loading