Simplify the authentication code paths #3350
authorJocelyn Turcotte <jturcotte@woboq.com>
Sat, 5 Sep 2015 13:37:20 +0000 (15:37 +0200)
committerJocelyn Turcotte <jturcotte@woboq.com>
Sat, 5 Sep 2015 14:00:45 +0000 (16:00 +0200)
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
src/libsync/account.cpp
src/libsync/connectionvalidator.cpp
src/libsync/connectionvalidator.h
src/libsync/creds/abstractcredentials.h

index 70d5d20099c0b54493efa0e3a647e5ce98f1c89c..e389c276ae7fa3f2683a4e3a5bc40d2b6a437516 100644 (file)
@@ -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;
index 1c75a08abcee7a2d1db3746e2709bef53f2ac95c..9ce6608e7e8d3577007947ac5a49158ae280fa80 100644 (file)
@@ -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();
 }
 
index bcc285c952a6e9dc766a80e838206163d3782103..2b715ff330ed2025c8288757531046045454480a 100644 (file)
@@ -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());
index f723831307f1fba34593eaf34ef6f27f855e2ded..afd598cf9c2dd9fd022ac3a96b5f0e5fd1dd913a 100644 (file)
@@ -45,10 +45,9 @@ namespace OCC {
         |
         +-> slotJobTimeout --> X
         |
-        +-> slotStatusFound
-                credential->fetch() --+
-                                      |
-  +-----------------------------------+
+        +-> slotStatusFound --+--> X (if credentials are still missing)
+                              |
+  +---------------------------+
   |
 *-+-> checkAuthentication (PROPFIND on root)
         PropfindJob
index e19156d0e6c7fa15da822b6e4929c49e9a694f76..6e83febbd326396624e4e3c1a11839389b958603 100644 (file)
@@ -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);