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

How to use an authenticated proxy with azure-storage-blob 11.0.1. #555

Open
sesu-bio opened this issue Oct 22, 2020 · 0 comments
Open

How to use an authenticated proxy with azure-storage-blob 11.0.1. #555

sesu-bio opened this issue Oct 22, 2020 · 0 comments

Comments

@sesu-bio
Copy link

Which service(blob, file, queue, table) does this issue concern?

blob

Which version of the SDK was used?

I am working on a project which uses azure-storage-blob 11.0.1. Upgrading should be avoided if possible.

What problem was encountered?

The project needs to have proxy support added including proxy authentication. I managed to get an unauthenticated proxy server working. However, it is unclear to me how to supply credentials. I have seen #307 which mentions a default authenticator but it doesn't seem to work for the version I am working with. #307 mentions OperationContext for configuring the proxy which doesn't work for me either. Here is my code which includes the things I tried that didn't work.

/*
// configures the proxy for Javas HttpURLConnection but not Azure
System.setProperty("https.proxyHost", PROXY_HOST);
System.setProperty("https.proxyPort", PROXY_PORT);

// no effect, no option for authentication
OperationContext.setDefaultProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT_INT)));

// no effect
System.setProperty("https.proxyUser", PROXY_USER);
System.setProperty("https.proxyPassword", PROXY_PASS);
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");

// authentication which works for Javas HttpURLConnection but not Azure
Authenticator.setDefault(new Authenticator() {
	@Override
	public PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication(PROXY_USER, PROXY_PASS.toCharArray());
	}
});
*/

// works for configuring the proxy for Azure but no option for authentication
PipelineOptions pipeLineOptions = new PipelineOptions();
pipeLineOptions.withClient(HttpClient.createDefault(new HttpClientConfiguration(
		new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT_INT)))));

// try to download the file
BlockBlobURL blockBlobUrl = new BlockBlobURL(url, BlockBlobURL.createPipeline(pipeLineOptions));
blockBlobUrl.download().flatMapCompletable(response -> {
	AsynchronousFileChannel channel = AsynchronousFileChannel.open(Paths.get("./file.zip"),
			StandardOpenOption.CREATE, StandardOpenOption.WRITE);
	return FlowableUtil.writeFile(response.body(null), channel);
}).doOnComplete(() -> System.out.println("The blob was downloaded to ./file.zip")).blockingAwait();

Which results in this error when the proxy requires authentication:

Okt 22, 2020 2:02:44 PM com.microsoft.azure.storage.blob.LoggingFactory$LoggingPolicy log
SCHWERWIEGEND: Unexpected failure attempting to make request.
Error message:'http, none, /[removed proxy ip and port] => [mystorage].blob.core.windows.net/20.38.118.132:443, status: 407 Proxy Authentication Required'
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant