From ed08eabf0e76b2dfb66b2c7ef0daadb42a514a7f Mon Sep 17 00:00:00 2001 From: "Vincent Jansen (v.jansen@blueriq.com)" Date: Mon, 20 Aug 2018 14:09:23 +0200 Subject: [PATCH] Download using authentication with properties --- .../org/apache/maven/wrapper/DefaultDownloader.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/maven-wrapper/src/main/java/org/apache/maven/wrapper/DefaultDownloader.java b/maven-wrapper/src/main/java/org/apache/maven/wrapper/DefaultDownloader.java index 2f6478ebfd..57bb24ec1b 100644 --- a/maven-wrapper/src/main/java/org/apache/maven/wrapper/DefaultDownloader.java +++ b/maven-wrapper/src/main/java/org/apache/maven/wrapper/DefaultDownloader.java @@ -43,6 +43,7 @@ public class DefaultDownloader implements Downloader { this.applicationName = applicationName; this.applicationVersion = applicationVersion; configureProxyAuthentication(); + configureAuthentication(); } private void configureProxyAuthentication() { @@ -50,6 +51,16 @@ public class DefaultDownloader implements Downloader { Authenticator.setDefault(new SystemPropertiesProxyAuthenticator()); } } + + private void configureAuthentication() { + if (System.getProperty("MVNW_WRAPPER_AUTH_USERNAME") != null && System.getProperty("MVNW_WRAPPER_AUTH_PASSWORD") != null && System.getProperty("http.proxyUser") == null) { + Authenticator.setDefault(new Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(System.getProperty("MVNW_WRAPPER_AUTH_USERNAME"), System.getProperty("MVNW_WRAPPER_AUTH_PASSWORD").toCharArray()); + } + }); + } + } public void download(URI address, File destination) throws Exception { if (destination.exists()) {