From d5e179d7a2f8b2f93daaba86fc10cbfb8b9efee2 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Wed, 1 Feb 2017 10:34:42 +0100 Subject: [PATCH] Use preemptive authentication except in server versions where it is not compatible with session tracking --- .../lib/common/OwnCloudBasicCredentials.java | 4 ++-- .../lib/common/OwnCloudClientFactory.java | 4 ++-- .../lib/common/OwnCloudCredentialsFactory.java | 4 ++-- .../lib/common/accounts/AccountUtils.java | 2 +- .../lib/resources/status/OwnCloudVersion.java | 17 +++++++++++++++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/com/owncloud/android/lib/common/OwnCloudBasicCredentials.java b/src/com/owncloud/android/lib/common/OwnCloudBasicCredentials.java index bf7c62c1..4f7434a2 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudBasicCredentials.java +++ b/src/com/owncloud/android/lib/common/OwnCloudBasicCredentials.java @@ -42,10 +42,10 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials { mAuthenticationPreemptive = true; } - public OwnCloudBasicCredentials(String username, String password, boolean sessionEnabled) { + public OwnCloudBasicCredentials(String username, String password, boolean preemptiveMode) { mUsername = username != null ? username : ""; mPassword = password != null ? password : ""; - mAuthenticationPreemptive = !sessionEnabled; + mAuthenticationPreemptive = preemptiveMode; } @Override diff --git a/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java index b267e1b3..5d01e487 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClientFactory.java @@ -121,7 +121,7 @@ public class OwnCloudClientFactory { OwnCloudCredentialsFactory.newBasicCredentials( username, password, - (version != null && version.isSessionMonitoringSupported()) + (version != null && version.isPreemptiveAuthenticationPreferred()) ) ); @@ -201,7 +201,7 @@ public class OwnCloudClientFactory { OwnCloudCredentialsFactory.newBasicCredentials( username, password, - (version != null && version.isSessionMonitoringSupported()) + (version != null && version.isPreemptiveAuthenticationPreferred()) ) ); } diff --git a/src/com/owncloud/android/lib/common/OwnCloudCredentialsFactory.java b/src/com/owncloud/android/lib/common/OwnCloudCredentialsFactory.java index 647dac8f..e7cf12fd 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudCredentialsFactory.java +++ b/src/com/owncloud/android/lib/common/OwnCloudCredentialsFactory.java @@ -35,9 +35,9 @@ public class OwnCloudCredentialsFactory { } public static OwnCloudCredentials newBasicCredentials( - String username, String password, boolean sessionEnabled + String username, String password, boolean preemptiveMode ) { - return new OwnCloudBasicCredentials(username, password, sessionEnabled); + return new OwnCloudBasicCredentials(username, password, preemptiveMode); } public static OwnCloudCredentials newBearerCredentials(String authToken) { diff --git a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java index 3359593c..7ebf3d11 100644 --- a/src/com/owncloud/android/lib/common/accounts/AccountUtils.java +++ b/src/com/owncloud/android/lib/common/accounts/AccountUtils.java @@ -230,7 +230,7 @@ public class AccountUtils { credentials = OwnCloudCredentialsFactory.newBasicCredentials( username, password, - version.isSessionMonitoringSupported() + version.isPreemptiveAuthenticationPreferred() ); } diff --git a/src/com/owncloud/android/lib/resources/status/OwnCloudVersion.java b/src/com/owncloud/android/lib/resources/status/OwnCloudVersion.java index 00e6f661..76ae4710 100644 --- a/src/com/owncloud/android/lib/resources/status/OwnCloudVersion.java +++ b/src/com/owncloud/android/lib/resources/status/OwnCloudVersion.java @@ -55,6 +55,9 @@ public class OwnCloudVersion implements Comparable { private static final int MINIMUM_VERSION_WITH_SESSION_MONITORING = 0x09010000; // 9.1 + private static final int MINIMUM_VERSION_WITH_SESSION_MONITORING_WORKING_IN_PREEMPTIVE_MODE = 0x09010301; + // 9.1.3.1, final 9.1.3: https://github.com/owncloud/core/commit/f9a867b70c217463289a741d4d26079eb2a80dfd + private static final int MAX_DOTS = 3; // format is in version @@ -168,4 +171,18 @@ public class OwnCloudVersion implements Comparable { public boolean isSessionMonitoringSupported() { return (mVersion >= MINIMUM_VERSION_WITH_SESSION_MONITORING); } + + /** + * From OC 9.1 session tracking is a feature, but to get it working in the OC app we need the preemptive + * mode of basic authentication is disabled. This changes in OC 9.1.3, where preemptive mode is compatible + * with session tracking again. + * + * @return True for every version before 9.1 and from 9.1.3, false otherwise + */ + public boolean isPreemptiveAuthenticationPreferred() { + return ( + (mVersion < MINIMUM_VERSION_WITH_SESSION_MONITORING) || + (mVersion >= MINIMUM_VERSION_WITH_SESSION_MONITORING_WORKING_IN_PREEMPTIVE_MODE) + ); + } }