Get rid of ShibbolethRefresher

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.
This commit is contained in:
Jocelyn Turcotte 2015-09-04 22:28:21 +02:00
parent dcb687929f
commit 94a57fe8d5
7 changed files with 4 additions and 190 deletions

View file

@ -72,7 +72,6 @@ set(client_SRCS
creds/httpcredentialsgui.cpp creds/httpcredentialsgui.cpp
creds/shibbolethcredentials.cpp creds/shibbolethcredentials.cpp
creds/shibboleth/shibbolethwebview.cpp creds/shibboleth/shibbolethwebview.cpp
creds/shibboleth/shibbolethrefresher.cpp
creds/shibboleth/shibbolethuserjob.cpp creds/shibboleth/shibbolethuserjob.cpp
wizard/abstractcredswizardpage.cpp wizard/abstractcredswizardpage.cpp
wizard/owncloudadvancedsetuppage.cpp wizard/owncloudadvancedsetuppage.cpp

View file

@ -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

View file

@ -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

View file

@ -12,7 +12,6 @@
* for more details. * for more details.
*/ */
#include <QMutex>
#include <QSettings> #include <QSettings>
#include <QNetworkReply> #include <QNetworkReply>
#include <QMessageBox> #include <QMessageBox>
@ -21,7 +20,6 @@
#include "creds/shibbolethcredentials.h" #include "creds/shibbolethcredentials.h"
#include "creds/shibboleth/shibbolethwebview.h" #include "creds/shibboleth/shibbolethwebview.h"
#include "creds/shibboleth/shibbolethrefresher.h"
#include "creds/shibbolethcredentials.h" #include "creds/shibbolethcredentials.h"
#include "shibboleth/shibbolethuserjob.h" #include "shibboleth/shibbolethuserjob.h"
#include "creds/credentialscommon.h" #include "creds/credentialscommon.h"
@ -47,39 +45,6 @@ namespace
const char userC[] = "shib_user"; const char userC[] = "shib_user";
const char shibCookieNameC[] = "_shibsession_"; 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 } // ns
ShibbolethCredentials::ShibbolethCredentials() ShibbolethCredentials::ShibbolethCredentials()
@ -132,12 +97,7 @@ QByteArray ShibbolethCredentials::prepareCookieData() const
void ShibbolethCredentials::syncContextPreStart (CSYNC* ctx) 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, "session_key", prepareCookieData().data());
csync_set_module_property(ctx, "redirect_callback", &cb);
} }
bool ShibbolethCredentials::changed(AbstractCredentials* credentials) const 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() void ShibbolethCredentials::invalidateToken()
{ {
_ready = false;
_fetchJobInProgress = true;
CookieJar *jar = static_cast<CookieJar*>(_account->networkAccessManager()->cookieJar()); CookieJar *jar = static_cast<CookieJar*>(_account->networkAccessManager()->cookieJar());
// Remove the _shibCookie // Remove the _shibCookie
@ -311,38 +273,6 @@ void ShibbolethCredentials::slotBrowserRejected()
Q_EMIT fetched(); 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) void ShibbolethCredentials::slotReadJobDone(QKeychain::Job *job)
{ {
if (job->error() == QKeychain::NoError) { if (job->error() == QKeychain::NoError) {

View file

@ -66,15 +66,10 @@ public:
static QNetworkCookie findShibCookie(Account *, QList<QNetworkCookie> cookies = QList<QNetworkCookie>()); static QNetworkCookie findShibCookie(Account *, QList<QNetworkCookie> cookies = QList<QNetworkCookie>());
static QByteArray shibCookieName(); static QByteArray shibCookieName();
public Q_SLOTS:
void invalidateAndFetch() Q_DECL_OVERRIDE;
private Q_SLOTS: private Q_SLOTS:
void onShibbolethCookieReceived(const QNetworkCookie&); void onShibbolethCookieReceived(const QNetworkCookie&);
void slotBrowserRejected(); void slotBrowserRejected();
void onFetched();
void slotReadJobDone(QKeychain::Job*); void slotReadJobDone(QKeychain::Job*);
void slotInvalidateAndFetchInvalidateDone(QKeychain::Job*);
void slotReplyFinished(QNetworkReply*); void slotReplyFinished(QNetworkReply*);
void slotUserFetched(const QString& user); void slotUserFetched(const QString& user);
void slotFetchUser(); void slotFetchUser();
@ -82,7 +77,6 @@ private Q_SLOTS:
Q_SIGNALS: Q_SIGNALS:
void newCookie(const QNetworkCookie& cookie); void newCookie(const QNetworkCookie& cookie);
void invalidatedAndFetched(const QByteArray& cookieData);
private: private:
void storeShibCookie(const QNetworkCookie &cookie); void storeShibCookie(const QNetworkCookie &cookie);

View file

@ -54,7 +54,7 @@ public:
virtual void persist() = 0; virtual void persist() = 0;
/** Invalidates auth token, or password for basic auth */ /** Invalidates auth token, or password for basic auth */
virtual void invalidateToken() = 0; virtual void invalidateToken() = 0;
virtual void invalidateAndFetch() { void invalidateAndFetch() {
invalidateToken(); invalidateToken();
fetch(); fetch();
} }

View 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/shibbolethcredentials.cpp )
#list(APPEND FolderMan_SRC ../src/gui/creds/credentialsfactory.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/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/shibboleth/shibbolethwebview.cpp )
#list(APPEND FolderMan_SRC ../src/gui/creds/httpcredentialsgui.cpp ) #list(APPEND FolderMan_SRC ../src/gui/creds/httpcredentialsgui.cpp )
#list(APPEND FolderMan_SRC ../src/gui/sslerrordialog.cpp ) #list(APPEND FolderMan_SRC ../src/gui/sslerrordialog.cpp )