[Pkg-owncloud-commits] [owncloud-client] 16/484: Simplify the authentication code paths #3350

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:03 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 89f69209dde7b5f859073cc9f7401aae2a847b07
Author: Jocelyn Turcotte <jturcotte at woboq.com>
Date:   Sat Sep 5 15:37:20 2015 +0200

    Simplify the authentication code paths #3350
    
    The AccountState is now the only class responsible for triggering credentials
    fetching from the keychain or from the user.
    
    With the ShibbolethRefresher out of the question it's possible
    to remove the invalidateAndFetch virtual and manually call invalidateToken.
    This also allows us to move that code from Account to AccountState.
    In the end this also allows us to move the fetch() call from the
    ConnectionValidator and use the same code path as for invalid credentials.
---
 src/gui/accountstate.cpp                | 11 +++++++----
 src/libsync/account.cpp                 |  8 --------
 src/libsync/connectionvalidator.cpp     | 18 +++++-------------
 src/libsync/connectionvalidator.h       |  7 +++----
 src/libsync/creds/abstractcredentials.h |  5 -----
 5 files changed, 15 insertions(+), 34 deletions(-)

diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index 70d5d20..e389c27 100644
--- a/src/gui/accountstate.cpp
+++ b/src/gui/accountstate.cpp
@@ -202,8 +202,8 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta
         // much more likely, so keep trying to connect.
         setState(NetworkError);
         break;
-    case ConnectionValidator::CredentialsWrong:
-        account()->handleInvalidCredentials();
+    case ConnectionValidator::CredentialsMissingOrWrong:
+        slotInvalidCredentials();
         break;
     case ConnectionValidator::UserCanceledCredentials:
         setState(SignedOut);
@@ -219,9 +219,12 @@ void AccountState::slotConnectionValidatorResult(ConnectionValidator::Status sta
 
 void AccountState::slotInvalidCredentials()
 {
-    if (isSignedOut()) {
+    if (isSignedOut() || _waitingForNewCredentials)
         return;
-    }
+
+    if (account()->credentials()->ready())
+        account()->credentials()->invalidateToken();
+    account()->credentials()->fetchFromKeychain();
 
     setState(ConfigurationError);
     _waitingForNewCredentials = true;
diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp
index 1c75a08..9ce6608 100644
--- a/src/libsync/account.cpp
+++ b/src/libsync/account.cpp
@@ -425,14 +425,6 @@ void Account::slotCredentialsFetched()
 
 void Account::handleInvalidCredentials()
 {
-    // invalidate & forget token/password
-    // but try to re-sign in.
-    if (_credentials->ready()) {
-        _credentials->invalidateAndFetch();
-    } else {
-        _credentials->fetch();
-    }
-
     emit invalidCredentials();
 }
 
diff --git a/src/libsync/connectionvalidator.cpp b/src/libsync/connectionvalidator.cpp
index bcc285c..2b715ff 100644
--- a/src/libsync/connectionvalidator.cpp
+++ b/src/libsync/connectionvalidator.cpp
@@ -42,7 +42,7 @@ QString ConnectionValidator::statusString( Status stat )
         return QLatin1String("NotConfigured");
     case ServerVersionMismatch:
         return QLatin1String("Server Version Mismatch");
-    case CredentialsWrong:
+    case CredentialsMissingOrWrong:
         return QLatin1String("Credentials Wrong");
     case StatusNotFound:
         return QLatin1String("Status not found");
@@ -122,18 +122,10 @@ void ConnectionValidator::slotStatusFound(const QUrl&url, const QVariantMap &inf
     }
 
     // now check the authentication
-    AbstractCredentials *creds = _account->credentials();
-    if (creds->ready()) {
+    if (_account->credentials()->ready())
         QTimer::singleShot( 0, this, SLOT( checkAuthentication() ));
-    } else {
-        // We can't proceed with the auth check because we don't have credentials.
-        // Fetch them now! Once fetched, a new connectivity check will be
-        // initiated anyway.
-        creds->fetch(_credentialsFetchMode);
-
-        // no result is reported
-        deleteLater();
-    }
+    else
+        reportResult( CredentialsMissingOrWrong );
 }
 
 // status.php could not be loaded (network or server issue!).
@@ -184,7 +176,7 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply)
         qDebug() <<  reply->error() << reply->errorString();
         qDebug() << "******** Password is wrong!";
         _errors << tr("The provided credentials are not correct");
-        stat = CredentialsWrong;
+        stat = CredentialsMissingOrWrong;
 
     } else if( reply->error() != QNetworkReply::NoError ) {
         _errors << errorMessage(reply->errorString(), reply->readAll());
diff --git a/src/libsync/connectionvalidator.h b/src/libsync/connectionvalidator.h
index f723831..afd598c 100644
--- a/src/libsync/connectionvalidator.h
+++ b/src/libsync/connectionvalidator.h
@@ -45,10 +45,9 @@ namespace OCC {
         |
         +-> slotJobTimeout --> X
         |
-        +-> slotStatusFound
-                credential->fetch() --+
-                                      |
-  +-----------------------------------+
+        +-> slotStatusFound --+--> X (if credentials are still missing)
+                              |
+  +---------------------------+
   |
 *-+-> checkAuthentication (PROPFIND on root)
         PropfindJob
diff --git a/src/libsync/creds/abstractcredentials.h b/src/libsync/creds/abstractcredentials.h
index e19156d..6e83feb 100644
--- a/src/libsync/creds/abstractcredentials.h
+++ b/src/libsync/creds/abstractcredentials.h
@@ -54,11 +54,6 @@ public:
     virtual void persist() = 0;
     /** Invalidates auth token, or password for basic auth */
     virtual void invalidateToken() = 0;
-    void invalidateAndFetch() {
-        invalidateToken();
-        fetch();
-    }
-
 
     static QString keychainKey(const QString &url, const QString &user);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list