Skip to content

Commit

Permalink
Merge pull request #69 from scottslewis/issue-330
Browse files Browse the repository at this point in the history
Proposed fix for Basic authentication support in javahttpclient provider
  • Loading branch information
scottslewis authored Sep 24, 2023
2 parents e501cc4 + e53370f commit dbacc2a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.eclipse.ecf.provider.filetransfer.httpclientjava;singleton:=true
Bundle-Version: 2.0.0.qualifier
Bundle-Version: 2.0.100.qualifier
Bundle-Vendor: %plugin.provider
Bundle-Localization: plugin
Automatic-Module-Name: org.eclipse.ecf.provider.filetransfer.httpclientjava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<relativePath>../../../</relativePath>
</parent>
<artifactId>org.eclipse.ecf.provider.filetransfer.httpclientjava</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpRequest.Builder;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Base64;
import java.util.List;
import java.util.Locale;
import java.util.OptionalLong;
Expand Down Expand Up @@ -247,6 +250,9 @@ protected void runRequest() throws Exception {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=249990
// fix the fix for bug 249990 with bug 410813
requestConfigBuilder.header(CACHE_CONTROL_HEADER, "max-age=" + maxAge);

// Add Basic Authentication to request config builder
setupBasicAuthentication(requestConfigBuilder);

HttpRequest request = requestConfigBuilder.build();

Expand Down Expand Up @@ -308,6 +314,13 @@ protected void runRequest() throws Exception {
}
}

private void setupBasicAuthentication(Builder requestConfigBuilder) {
if (username != null) {
byte[] credentials = Base64.getEncoder().encode((username + ":" + password).getBytes(StandardCharsets.UTF_8));
requestConfigBuilder.header("Authorization", "Basic " + new String(credentials, StandardCharsets.UTF_8));
}
}

private INTLMProxyHandler getNTLMProxyHandler(IHttpClientContext httpContext) {
Object value = httpContext.getAttribute(ECFHttpClientFactory.NTLM_PROXY_HANDLER_ATTR);
if (value instanceof INTLMProxyHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import java.net.http.HttpRequest.Builder;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -304,6 +306,11 @@ protected void setRequestHeaderValues(Builder builder) throws InvalidFileRangeSp
// fix the fix for bug 249990 with bug 410813
builder.header(HttpClientFileSystemBrowser.CACHE_CONTROL_HEADER, "max-age=" + maxAge); //$NON-NLS-1$
setRequestHeaderValuesFromOptions(builder);
// Setup Basic Authentication
if (username != null) {
byte[] credentials = Base64.getEncoder().encode((username + ":" + password).getBytes(StandardCharsets.UTF_8));
requestConfigBuilder.header("Authorization", "Basic " + new String(credentials, StandardCharsets.UTF_8));
}
}

private void setRangeHeader(final IFileRangeSpecification rangeSpec, final long resumePosition, Builder builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.ecf.filetransfer.httpclientjava.feature"
label="%featureName"
version="2.0.0.qualifier"
version="2.0.100.qualifier"
provider-name="%providerName"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
</parent>
<artifactId>org.eclipse.ecf.filetransfer.httpclientjava.feature</artifactId>
<packaging>eclipse-feature</packaging>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.100-SNAPSHOT</version>
</project>

0 comments on commit dbacc2a

Please sign in to comment.