Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 6fc2315

Browse files
authored
Merge pull request #489 from Azure/release/8.5.0
merging proxy support to legacy dev
2 parents 524c1d2 + 54c69c8 commit 6fc2315

File tree

8 files changed

+137
-5
lines changed

8 files changed

+137
-5
lines changed

ChangeLog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2019.08.15 Version 8.5.0
2+
* Support for HTTP proxy with Basic auth.
3+
* Support for HTTP proxy with Digest auth.
4+
15
2019.08.05 Version 8.4.0
26
* Support for 2019-02-02 REST version. Please see our REST API documentation and blogs for information about the related added features.
37
* Added support for setting rehydrate priority for SetBlobTier and CopyBlob APIs.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
3939
<dependency>
4040
<groupId>com.microsoft.azure</groupId>
4141
<artifactId>azure-storage</artifactId>
42-
<version>8.4.0</version>
42+
<version>8.5.0</version>
4343
</dependency>
4444
```
4545

microsoft-azure-storage-samples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>com.microsoft.azure</groupId>
2828
<artifactId>azure-storage</artifactId>
29-
<version>8.4.0</version>
29+
<version>8.5.0-preview</version>
3030
</dependency>
3131
<dependency>
3232
<groupId>com.microsoft.azure</groupId>

microsoft-azure-storage-samples/src/com/microsoft/azure/storage/logging/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>com.microsoft.azure</groupId>
2828
<artifactId>azure-storage</artifactId>
29-
<version>8.4.0</version>
29+
<version>8.5.0-preview</version>
3030
</dependency>
3131
<dependency>
3232
<groupId>com.microsoft.azure</groupId>

microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ public static class HeaderConstants {
765765
/**
766766
* Specifies the value to use for UserAgent header.
767767
*/
768-
public static final String USER_AGENT_VERSION = "8.4.0";
768+
public static final String USER_AGENT_VERSION = "8.5.0-preview";
769769

770770
/**
771771
* The default type for content-type and accept

microsoft-azure-storage/src/com/microsoft/azure/storage/OperationContext.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,31 @@ public final class OperationContext {
4545
*/
4646
private static Proxy proxyDefault;
4747

48+
/**
49+
* Represents a username to be used by default for a proxy when making a request.
50+
*/
51+
private static String proxyDefaultUsername = null;
52+
53+
/**
54+
* Represents a password to be used by default for a proxy when making a request.
55+
*/
56+
private static String proxyDefaultPassword = null;
57+
4858
/**
4959
* Represents a proxy to be used when making a request.
5060
*/
5161
private Proxy proxy;
5262

63+
/**
64+
* Represents a username for a proxy when making a request.
65+
*/
66+
private String proxyUsername = null;
67+
68+
/**
69+
* Represents a password for a proxy when making a request.
70+
*/
71+
private String proxyPassword = null;
72+
5373
/**
5474
* Represents the operation latency, in milliseconds, from the client's perspective. This may include any potential
5575
* retries.
@@ -241,6 +261,26 @@ public Proxy getProxy() {
241261
return this.proxy;
242262
}
243263

264+
/**
265+
* Gets a username for the authenticated proxy which will be used when making a request.
266+
* Default is <code>null</code>. To set a username use {@link #setProxyUsername(String)}
267+
*
268+
* @return A {@link String} to use when making a request.
269+
*/
270+
public String getProxyUsername() {
271+
return proxyUsername != null ? proxyUsername : getDefaultProxyUsername();
272+
}
273+
274+
/**
275+
* Gets the password for the authenticated proxy which will be used when making a request.
276+
* Default is <code>null</code>. To set a password to use {@link #setProxyPassword(String)}
277+
*
278+
* @return A {@link String} to use when making a request.
279+
*/
280+
public String getProxyPassword() {
281+
return proxyPassword != null ? proxyPassword : getDefaultProxyPassword();
282+
}
283+
244284
/**
245285
* Gets any additional headers for the request, for example, for proxy or logging information.
246286
*
@@ -446,6 +486,28 @@ public void setProxy(Proxy proxy) {
446486
this.proxy = proxy;
447487
}
448488

489+
/**
490+
* Sets a username for an authenticated proxy which will be used when making a request.
491+
* Default is <code>null</code>.
492+
*
493+
* @param username
494+
* A {@link java.lang.String} to use when making a request.
495+
*/
496+
public void setProxyUsername(final String username) {
497+
this.proxyUsername = username;
498+
}
499+
500+
/**
501+
* Sets a password for an authenticated proxy which will be used when making a request.
502+
* Default is <code>null</code>.
503+
*
504+
* @param password
505+
* A {@link java.lang.String} to use when making a request.
506+
*/
507+
public void setProxyPassword(final String password) {
508+
this.proxyPassword = password;
509+
}
510+
449511
/**
450512
* Sets any additional headers for the request, for example, for proxy or logging information.
451513
*
@@ -619,4 +681,46 @@ public static Proxy getDefaultProxy() {
619681
public static void setDefaultProxy(Proxy defaultProxy) {
620682
OperationContext.proxyDefault = defaultProxy;
621683
}
684+
685+
/**
686+
* Gets a default username for the authenticated proxy which will be used when making a request.
687+
* Default is <code>null</code>. To set a username use {@link #setDefaultProxyUsername(String)}
688+
*
689+
* @return A {@link String} to use when making a request.
690+
*/
691+
public static String getDefaultProxyUsername() {
692+
return OperationContext.proxyDefaultUsername;
693+
}
694+
695+
/**
696+
* Gets the default password for the authenticated proxy which will be used when making a request.
697+
* Default is <code>null</code>. To set a password to use {@link #setProxyPassword(String)}
698+
*
699+
* @return A {@link String} to use when making a request.
700+
*/
701+
public static String getDefaultProxyPassword() {
702+
return OperationContext.proxyDefaultPassword;
703+
}
704+
705+
/**
706+
* Sets a default username for an authenticated proxy which will be used when making a request.
707+
* Default is <code>null</code>.
708+
*
709+
* @param username
710+
* A {@link java.lang.String} to use when making a request.
711+
*/
712+
public static void setDefaultProxyUsername(final String username) {
713+
OperationContext.proxyDefaultUsername = username;
714+
}
715+
716+
/**
717+
* Sets a default password for an authenticated proxy which will be used when making a request.
718+
* Default is <code>null</code>.
719+
*
720+
* @param password
721+
* A {@link java.lang.String} to use when making a request.
722+
*/
723+
public static void setDefaultProxyPassword(final String password) {
724+
OperationContext.proxyDefaultPassword = password;
725+
}
622726
}

microsoft-azure-storage/src/com/microsoft/azure/storage/core/BaseRequest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
import java.io.ByteArrayOutputStream;
1818
import java.io.IOException;
19+
import java.net.Authenticator;
1920
import java.net.HttpURLConnection;
2021
import java.net.Proxy;
2122
import java.net.URI;
2223
import java.net.URISyntaxException;
2324
import java.net.URL;
25+
import java.net.PasswordAuthentication;
2426
import java.nio.charset.StandardCharsets;
2527
import java.util.List;
2628
import java.util.Map;
@@ -186,14 +188,36 @@ public static HttpURLConnection createURLConnection(final URI uri, final Request
186188

187189
// Get the proxy settings
188190
Proxy proxy = OperationContext.getDefaultProxy();
191+
String username = OperationContext.getDefaultProxyUsername();
192+
String password = OperationContext.getDefaultProxyPassword();
189193
if (opContext != null && opContext.getProxy() != null) {
190194
proxy = opContext.getProxy();
195+
if (opContext.getProxyUsername() != null) {
196+
username = opContext.getProxyUsername();
197+
}
198+
if (opContext.getProxyPassword() != null) {
199+
password = opContext.getProxyPassword();
200+
}
191201
}
192202

193203
// Set up connection, optionally with proxy settings
194204
final HttpURLConnection retConnection;
195205
if (proxy != null) {
196206
retConnection = (HttpURLConnection) resourceUrl.openConnection(proxy);
207+
if (username != null && password != null) {
208+
String authString = "Basic " + Utility.safeEncode(username + ":" + password);
209+
final String authUsername = username;
210+
final String authPassword = password;
211+
retConnection.setRequestProperty("Proxy-Authorization", authString);
212+
Authenticator.setDefault(new Authenticator() {
213+
@Override
214+
protected PasswordAuthentication getPasswordAuthentication() {
215+
PasswordAuthentication passwordAuthentication =
216+
new PasswordAuthentication (authUsername, authPassword.toCharArray());
217+
return passwordAuthentication;
218+
}
219+
});
220+
}
197221
}
198222
else {
199223
retConnection = (HttpURLConnection) resourceUrl.openConnection();

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<modelVersion>4.0.0</modelVersion>
1111
<groupId>com.microsoft.azure</groupId>
1212
<artifactId>azure-storage</artifactId>
13-
<version>8.4.0</version>
13+
<version>8.5.0-preview</version>
1414
<packaging>jar</packaging>
1515

1616
<name>Microsoft Azure Storage Client SDK</name>

0 commit comments

Comments
 (0)