diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 032747073..6a20a78ab 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -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 index 6c38ef9b3..000000000 --- a/src/gui/creds/shibboleth/shibbolethrefresher.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 - -#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 index 2e5a7aea3..000000000 --- a/src/gui/creds/shibboleth/shibbolethrefresher.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) by Krzesimir Nowak - * - * 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 - -#include - -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 diff --git a/src/gui/creds/shibbolethcredentials.cpp b/src/gui/creds/shibbolethcredentials.cpp index c65f71bbb..2c6e80dd8 100644 --- a/src/gui/creds/shibbolethcredentials.cpp +++ b/src/gui/creds/shibbolethcredentials.cpp @@ -12,7 +12,6 @@ * for more details. */ -#include #include #include #include @@ -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(csync_get_userdata(csync_ctx)); - AccountPtr account = engine->account(); - ShibbolethCredentials* creds = qobject_cast(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(_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) { diff --git a/src/gui/creds/shibbolethcredentials.h b/src/gui/creds/shibbolethcredentials.h index 424803825..f4cbd45a7 100644 --- a/src/gui/creds/shibbolethcredentials.h +++ b/src/gui/creds/shibbolethcredentials.h @@ -66,15 +66,10 @@ public: static QNetworkCookie findShibCookie(Account *, QList cookies = QList()); 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); diff --git a/src/libsync/creds/abstractcredentials.h b/src/libsync/creds/abstractcredentials.h index 658f4f4be..e19156d0e 100644 --- a/src/libsync/creds/abstractcredentials.h +++ b/src/libsync/creds/abstractcredentials.h @@ -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(); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9a1cb2fd7..19dc280e2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 )