Download using authentication with properties

This commit is contained in:
Vincent Jansen (v.jansen@blueriq.com) 2018-08-20 14:09:23 +02:00 committed by rfscholte
parent b9e6795b6c
commit ed08eabf0e
1 changed files with 11 additions and 0 deletions

View File

@ -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()) {