From 704ba791fdd9c9c8c0335435831d9920312870e2 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Wed, 7 Aug 2013 14:00:47 +0200 Subject: [PATCH] Fail the sync if we close the browser without passing proper credentials. --- src/creds/shibbolethcredentials.cpp | 27 +++++++++++++++++++++++---- src/creds/shibbolethcredentials.h | 2 ++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/creds/shibbolethcredentials.cpp b/src/creds/shibbolethcredentials.cpp index 3f06c2d9d..430b5ffd3 100644 --- a/src/creds/shibbolethcredentials.cpp +++ b/src/creds/shibbolethcredentials.cpp @@ -56,7 +56,7 @@ int shibboleth_redirect_callback(CSYNC* csync_ctx, // blocks refresher.refresh(); - return 0; + return creds->ready() ? 0 : 1; } } // ns @@ -100,7 +100,9 @@ QByteArray ShibbolethCredentials::prepareCookieData() const uniqueCookies.insert(cookieName, c.value()); } - uniqueCookies.insert(_shibCookie.name(), _shibCookie.value()); + if (!_shibCookie.name().isEmpty()) { + uniqueCookies.insert(_shibCookie.name(), _shibCookie.value()); + } foreach(const QString& cookieName, uniqueCookies.keys()) { cookiesAsString += cookieName; cookiesAsString += '='; @@ -166,6 +168,8 @@ void ShibbolethCredentials::fetch() _browser = new ShibbolethWebView(QUrl(cfg.ownCloudUrl())); connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + connect(_browser, SIGNAL(viewHidden()), + this, SLOT(slotBrowserHidden())); _browser->show (); } } @@ -175,19 +179,34 @@ void ShibbolethCredentials::persistForUrl(const QString& /*url*/) // nothing to do here, we don't store session cookies. } -void ShibbolethCredentials::onShibbolethCookieReceived(const QNetworkCookie& cookie) +void ShibbolethCredentials::disposeBrowser() { - _browser->hide(); + disconnect(_browser, SIGNAL(viewHidden()), + this, SLOT(slotBrowserHidden())); disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)), this, SLOT(onShibbolethCookieReceived(QNetworkCookie))); + _browser->hide(); _browser->deleteLater(); _browser = 0; +} + +void ShibbolethCredentials::onShibbolethCookieReceived(const QNetworkCookie& cookie) +{ + disposeBrowser(); _ready = true; _shibCookie = cookie; Q_EMIT newCookie(_shibCookie); Q_EMIT fetched(); } +void ShibbolethCredentials::slotBrowserHidden() +{ + disposeBrowser(); + _ready = false; + _shibCookie = QNetworkCookie(); + Q_EMIT fetched(); +} + void ShibbolethCredentials::invalidateAndFetch() { _ready = false; diff --git a/src/creds/shibbolethcredentials.h b/src/creds/shibbolethcredentials.h index 27c4692ba..77084d7f1 100644 --- a/src/creds/shibbolethcredentials.h +++ b/src/creds/shibbolethcredentials.h @@ -47,6 +47,7 @@ public Q_SLOTS: private Q_SLOTS: void onShibbolethCookieReceived(const QNetworkCookie& cookie); + void slotBrowserHidden(); void onFetched(); Q_SIGNALS: @@ -55,6 +56,7 @@ Q_SIGNALS: private: QByteArray prepareCookieData() const; + void disposeBrowser(); QNetworkCookie _shibCookie; bool _ready;