Get rid of ShibbolethRefresher
authorJocelyn Turcotte <jturcotte@woboq.com>
Fri, 4 Sep 2015 20:28:21 +0000 (22:28 +0200)
committerJocelyn Turcotte <jturcotte@woboq.com>
Sat, 5 Sep 2015 13:45:54 +0000 (15:45 +0200)
This is only for neon and not necessary if we want to show a notification
instead of a login window when the network reports invalid credentials.

src/gui/CMakeLists.txt
src/gui/creds/shibboleth/shibbolethrefresher.cpp [deleted file]
src/gui/creds/shibboleth/shibbolethrefresher.h [deleted file]
src/gui/creds/shibbolethcredentials.cpp
src/gui/creds/shibbolethcredentials.h
src/libsync/creds/abstractcredentials.h
test/CMakeLists.txt

index 032747073139d77b62bf83ef6c7e6454beb9d0c1..6a20a78abfd7418ac070eb25e42e9aad48af9e9f 100644 (file)
@@ -72,7 +72,6 @@ set(client_SRCS
     creds/httpcredentialsgui.cpp
     creds/shibbolethcredentials.cpp
     creds/shibboleth/shibbolethwebview.cpp
-    creds/shibboleth/shibbolethrefresher.cpp
     creds/shibboleth/shibbolethuserjob.cpp
     wizard/abstractcredswizardpage.cpp
     wizard/owncloudadvancedsetuppage.cpp
diff --git a/src/gui/creds/shibboleth/shibbolethrefresher.cpp b/src/gui/creds/shibboleth/shibbolethrefresher.cpp
deleted file mode 100644 (file)
index 6c38ef9..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) by Krzesimir Nowak <krzesimir@endocode.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#include <QEventLoop>
-
-#include "account.h"
-#include "creds/shibboleth/shibbolethrefresher.h"
-#include "creds/shibbolethcredentials.h"
-
-namespace OCC
-{
-
-ShibbolethRefresher::ShibbolethRefresher(AccountPtr account, ShibbolethCredentials* creds, CSYNC* csync_ctx, QObject* parent)
-    : QObject(parent),
-      _account(account),
-      _creds(creds),
-      _csync_ctx(csync_ctx)
-{}
-
-void ShibbolethRefresher::refresh()
-{
-    QEventLoop loop;
-
-    connect(_creds, SIGNAL(invalidatedAndFetched(QByteArray)),
-            this, SLOT(onInvalidatedAndFetched(QByteArray)));
-    connect(_creds, SIGNAL(invalidatedAndFetched(QByteArray)),
-            &loop, SLOT(quit()));
-    QMetaObject::invokeMethod(_creds, "invalidateAndFetch",Qt::QueuedConnection,
-                              Q_ARG(AccountPtr, _account));
-    loop.exec();
-    disconnect(_creds, SIGNAL(invalidatedAndFetched(QByteArray)),
-               &loop, SLOT(quit()));
-}
-
-void ShibbolethRefresher::onInvalidatedAndFetched(const QByteArray& cookies)
-{
-    // "cookies" is const and its data() return const void*. We want just void*.
-    QByteArray myCookies(cookies);
-
-    disconnect(_creds, SIGNAL(invalidatedAndFetched(QByteArray)),
-               this, SLOT(onInvalidatedAndFetched(QByteArray)));
-    csync_set_module_property(_csync_ctx, "session_key", myCookies.data());
-}
-
-} // namespace OCC
diff --git a/src/gui/creds/shibboleth/shibbolethrefresher.h b/src/gui/creds/shibboleth/shibbolethrefresher.h
deleted file mode 100644 (file)
index 2e5a7ae..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) by Krzesimir Nowak <krzesimir@endocode.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#ifndef MIRALL_CREDS_SHIBBOLETH_REFRESHER_H
-#define MIRALL_CREDS_SHIBBOLETH_REFRESHER_H
-
-#include <QObject>
-
-#include <csync.h>
-
-class QByteArray;
-
-namespace OCC
-{
-
-class Account;
-class ShibbolethCredentials;
-
-/**
- * @brief The ShibbolethRefresher class
- * @ingroup gui
- */
-class ShibbolethRefresher : public QObject
-{
-    Q_OBJECT
-
-public:
-    ShibbolethRefresher(AccountPtr account, ShibbolethCredentials* creds, CSYNC* csync_ctx, QObject* parent = 0);
-
-    void refresh();
-
-private Q_SLOTS:
-    void onInvalidatedAndFetched(const QByteArray& cookieData);
-
-private:
-    AccountPtr _account;
-    ShibbolethCredentials* _creds;
-    CSYNC* _csync_ctx;
-};
-
-} // namespace OCC
-
-#endif
index c65f71bbbbb193e7da3b4ef9d792b263fafe23b9..2c6e80dd8fa1121cc8a9524f46b7bcea852bd4c7 100644 (file)
@@ -12,7 +12,6 @@
  * for more details.
  */
 
-#include <QMutex>
 #include <QSettings>
 #include <QNetworkReply>
 #include <QMessageBox>
@@ -21,7 +20,6 @@
 
 #include "creds/shibbolethcredentials.h"
 #include "creds/shibboleth/shibbolethwebview.h"
-#include "creds/shibboleth/shibbolethrefresher.h"
 #include "creds/shibbolethcredentials.h"
 #include "shibboleth/shibbolethuserjob.h"
 #include "creds/credentialscommon.h"
@@ -47,39 +45,6 @@ namespace
 const char userC[] = "shib_user";
 const char shibCookieNameC[] = "_shibsession_";
 
-int shibboleth_redirect_callback(CSYNC* csync_ctx,
-                                 const char* uri)
-{
-    if (!csync_ctx || !uri) {
-        return 1;
-    }
-
-    const QString qurl(QString::fromLatin1(uri));
-    QRegExp shibbolethyWords ("SAML|wayf");
-
-    shibbolethyWords.setCaseSensitivity (Qt::CaseInsensitive);
-    if (!qurl.contains(shibbolethyWords)) {
-        return 1;
-    }
-
-    SyncEngine* engine = reinterpret_cast<SyncEngine*>(csync_get_userdata(csync_ctx));
-    AccountPtr account = engine->account();
-    ShibbolethCredentials* creds = qobject_cast<ShibbolethCredentials*>(account->credentials());
-    if (!creds) {
-      qDebug() << "Not a Shibboleth creds instance!";
-      return 1;
-    }
-
-    QMutex mutex;
-    QMutexLocker locker(&mutex);
-    ShibbolethRefresher refresher(account, creds, csync_ctx);
-
-    // blocks
-    refresher.refresh();
-
-    return creds->ready() ? 0 : 1;
-}
-
 } // ns
 
 ShibbolethCredentials::ShibbolethCredentials()
@@ -132,12 +97,7 @@ QByteArray ShibbolethCredentials::prepareCookieData() const
 
 void ShibbolethCredentials::syncContextPreStart (CSYNC* ctx)
 {
-    typedef int (*csync_owncloud_redirect_callback_t)(CSYNC* ctx, const char* uri);
-
-    csync_owncloud_redirect_callback_t cb = shibboleth_redirect_callback;
-
     csync_set_module_property(ctx, "session_key", prepareCookieData().data());
-    csync_set_module_property(ctx, "redirect_callback", &cb);
 }
 
 bool ShibbolethCredentials::changed(AbstractCredentials* credentials) const
@@ -232,9 +192,11 @@ void ShibbolethCredentials::persist()
     }
 }
 
-// only used by Application::slotLogout(). Use invalidateAndFetch for normal usage
 void ShibbolethCredentials::invalidateToken()
 {
+    _ready = false;
+    _fetchJobInProgress = true;
+
     CookieJar *jar = static_cast<CookieJar*>(_account->networkAccessManager()->cookieJar());
 
     // Remove the _shibCookie
@@ -311,38 +273,6 @@ void ShibbolethCredentials::slotBrowserRejected()
     Q_EMIT fetched();
 }
 
-void ShibbolethCredentials::invalidateAndFetch()
-{
-    _ready = false;
-    _fetchJobInProgress = true;
-
-    // delete the credentials, then in the slot fetch them again (which will trigger browser)
-    DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
-    job->setSettings(_account->settingsWithGroup(Theme::instance()->appName(), job).release());
-    connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotInvalidateAndFetchInvalidateDone(QKeychain::Job*)));
-    job->setKey(keychainKey(_account->url().toString(), "shibAssertion"));
-    job->start();
-}
-
-void ShibbolethCredentials::slotInvalidateAndFetchInvalidateDone(QKeychain::Job*)
-{
-    connect (this, SIGNAL(fetched()),
-             this, SLOT(onFetched()));
-    _fetchJobInProgress = false;
-    // small hack to support the ShibbolethRefresher hack
-    // we already rand fetch() with a valid account object,
-    // and hence know the url on refresh
-    fetch();
-}
-
-void ShibbolethCredentials::onFetched()
-{
-    disconnect (this, SIGNAL(fetched()),
-                this, SLOT(onFetched()));
-
-    Q_EMIT invalidatedAndFetched(prepareCookieData());
-}
-
 void ShibbolethCredentials::slotReadJobDone(QKeychain::Job *job)
 {
     if (job->error() == QKeychain::NoError) {
index 424803825598231e8034ba5ddc3c4d40adeef9cf..f4cbd45a763b789e78b3e094c10c7b7b05666359 100644 (file)
@@ -66,15 +66,10 @@ public:
     static QNetworkCookie findShibCookie(Account *, QList<QNetworkCookie> cookies = QList<QNetworkCookie>());
     static QByteArray shibCookieName();
 
-public Q_SLOTS:
-    void invalidateAndFetch() Q_DECL_OVERRIDE;
-
 private Q_SLOTS:
     void onShibbolethCookieReceived(const QNetworkCookie&);
     void slotBrowserRejected();
-    void onFetched();
     void slotReadJobDone(QKeychain::Job*);
-    void slotInvalidateAndFetchInvalidateDone(QKeychain::Job*);
     void slotReplyFinished(QNetworkReply*);
     void slotUserFetched(const QString& user);
     void slotFetchUser();
@@ -82,7 +77,6 @@ private Q_SLOTS:
 
 Q_SIGNALS:
     void newCookie(const QNetworkCookie& cookie);
-    void invalidatedAndFetched(const QByteArray& cookieData);
 
 private:
     void storeShibCookie(const QNetworkCookie &cookie);
index 658f4f4bed2bd0b3e8662d240d4c43f35a8919da..e19156d0e6c7fa15da822b6e4929c49e9a694f76 100644 (file)
@@ -54,7 +54,7 @@ public:
     virtual void persist() = 0;
     /** Invalidates auth token, or password for basic auth */
     virtual void invalidateToken() = 0;
-    virtual void invalidateAndFetch() {
+    void invalidateAndFetch() {
         invalidateToken();
         fetch();
     }
index 9a1cb2fd7cbe9d5102f535054406b61818c029fb..19dc280e270b3c74fcc668d549599351d0dc42cc 100644 (file)
@@ -50,7 +50,6 @@ list(APPEND FolderMan_SRC ../src/gui/accountstate.cpp )
 #list(APPEND FolderMan_SRC ../src/gui/creds/shibbolethcredentials.cpp )
 #list(APPEND FolderMan_SRC ../src/gui/creds/credentialsfactory.cpp )
 #list(APPEND FolderMan_SRC ../src/gui/creds/shibboleth/shibbolethuserjob.cpp )
-#list(APPEND FolderMan_SRC ../src/gui/creds/shibboleth/shibbolethrefresher.cpp )
 #list(APPEND FolderMan_SRC ../src/gui/creds/shibboleth/shibbolethwebview.cpp )
 #list(APPEND FolderMan_SRC ../src/gui/creds/httpcredentialsgui.cpp )
 #list(APPEND FolderMan_SRC ../src/gui/sslerrordialog.cpp )