From 410a04dc114b24a636948fc44cc5858454730554 Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Fri, 16 Oct 2015 19:29:33 +0200 Subject: [PATCH] Support Basic and Digest auth --- .../java/at/bitfire/davdroid/HttpClient.java | 40 ++----------------- dav4android | 2 +- 2 files changed, 4 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/HttpClient.java b/app/src/main/java/at/bitfire/davdroid/HttpClient.java index 117bcaac..6064d615 100644 --- a/app/src/main/java/at/bitfire/davdroid/HttpClient.java +++ b/app/src/main/java/at/bitfire/davdroid/HttpClient.java @@ -33,12 +33,12 @@ import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.X509TrustManager; +import at.bitfire.dav4android.BasicDigestAuthenticator; import at.bitfire.dav4android.HttpUtils; import de.duenndns.ssl.MemorizingTrustManager; import lombok.RequiredArgsConstructor; public class HttpClient extends OkHttpClient { - protected static final String HEADER_AUTHORIZATION = "Authorization"; final static UserAgentInterceptor userAgentInterceptor = new UserAgentInterceptor(); @@ -80,7 +80,7 @@ public class HttpClient extends OkHttpClient { if (preemptive) networkInterceptors().add(new PreemptiveAuthenticationInterceptor(username, password)); else - setAuthenticator(new DavAuthenticator(null, username, password)); + setAuthenticator(new BasicDigestAuthenticator(null, username, password)); } /** @@ -98,7 +98,7 @@ public class HttpClient extends OkHttpClient { username = client.username; password = client.password; - setAuthenticator(new DavAuthenticator(host, username, password)); + setAuthenticator(new BasicDigestAuthenticator(host, username, password)); } @@ -160,38 +160,4 @@ public class HttpClient extends OkHttpClient { } } - @RequiredArgsConstructor - public static class DavAuthenticator implements Authenticator { - final String host, username, password; - - @Override - public Request authenticate(Proxy proxy, Response response) throws IOException { - Request request = response.request(); - - if (host != null && !request.httpUrl().host().equalsIgnoreCase(host)) { - Constants.log.warn("Not authenticating against " + host + " for security reasons!"); - return null; - } - - // check whether this is the first authentication try with our credentials - Response priorResponse = response.priorResponse(); - boolean triedBefore = priorResponse != null ? priorResponse.request().header(HEADER_AUTHORIZATION) != null : false; - if (triedBefore) - // credentials didn't work last time, and they won't work now → stop here - return null; - - //List schemes = HttpUtils.parseWwwAuthenticate(response.headers("WWW-Authenticate")); - // TODO Digest auth - - return request.newBuilder() - .header(HEADER_AUTHORIZATION, Credentials.basic(username, password)) - .build(); - } - - @Override - public Request authenticateProxy(Proxy proxy, Response response) throws IOException { - return null; - } - } - } diff --git a/dav4android b/dav4android index b1ca2ff7..9f722654 160000 --- a/dav4android +++ b/dav4android @@ -1 +1 @@ -Subproject commit b1ca2ff7383381a407baffd05a6b3532e4cd1690 +Subproject commit 9f722654e355e6e82b8b6e39a515b250feb111a9