Merge branch 'master' into 'master'

Enable HttpDownloader to use URL-based HTTP Basic Authentication.

This is a very small merge request that adds the possibility to use URL-based HTTP Basic Authentication in a repository URL. With this change you can for example use `https://user:password@my.repo.com` to authenticate against a private repository.

It would be great if you could merge my little feature request into the master, or let me know what I can do or have to change in order for the merge request to get accepted.

I'm of course open for discussion. My use-case is the identification of individual users. We dynamically create a signed index.jar file for each user which contains an individual set of apps depending on the permissions of the user etc.

HTTP Basic Authentication is on of the possible solutions, another solution would be to use the Android Account Manager, but this would be a much larger change.

Thank you for your consideration.

Best regards,
Christian Morgner


See merge request !167
This commit is contained in:
Daniel Martí 2015-11-13 10:00:20 +00:00
commit 41b2ad6a9d

View File

@ -20,6 +20,7 @@ import java.net.SocketAddress;
import java.net.URL;
import javax.net.ssl.SSLHandshakeException;
import org.apache.commons.net.util.Base64;
public class HttpDownloader extends Downloader {
private static final String TAG = "HttpDownloader";
@ -87,6 +88,10 @@ public class HttpDownloader extends Downloader {
connection = (HttpURLConnection) sourceUrl.openConnection(proxy);
} else {
connection = (HttpURLConnection) sourceUrl.openConnection();
final String userInfo = sourceUrl.getUserInfo();
if (userInfo != null) {
connection.setRequestProperty("Authorization", "Basic " + Base64.encodeBase64String(userInfo.getBytes()));
}
}
}
@ -143,4 +148,4 @@ public class HttpDownloader extends Downloader {
public void close() {
connection.disconnect();
}
}
}