[Pkg-owncloud-commits] [owncloud-client] 160/175: Shibboleth: Let the webview use its own QNAM #3359

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Aug 8 10:36:39 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 9a9897ea1e429cf95f6cc86ed22ecec3e2b9f57e
Author: Jocelyn Turcotte <jturcotte at woboq.com>
Date:   Thu Jun 18 20:41:00 2015 +0200

    Shibboleth: Let the webview use its own QNAM #3359
    
    Since we periodically recreatet the QNAM owned by the Account,
    the web view could end up holding a dangling pointer to it.
    
    Let the web view use its own QNAM, but make sure that the cookie
    jars are shared so that we can grab the session token given
    by the server.
---
 src/libsync/account.cpp                            | 14 +++++++++++++-
 src/libsync/account.h                              |  1 +
 src/libsync/creds/shibboleth/shibbolethwebview.cpp |  3 ++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp
index d3e0c76..4579ebd 100644
--- a/src/libsync/account.cpp
+++ b/src/libsync/account.cpp
@@ -279,7 +279,19 @@ QList<QNetworkCookie> Account::lastAuthCookies() const
 
 void Account::clearCookieJar()
 {
-    _am->setCookieJar(new CookieJar);
+    Q_ASSERT(qobject_cast<CookieJar*>(_am->cookieJar()));
+    static_cast<CookieJar*>(_am->cookieJar())->clearSessionCookies();
+}
+
+/*! This shares our official cookie jar (containing all the tasty
+    authentication cookies) with another QNAM while making sure
+    of not loosing its ownership. */
+void Account::lendCookieJarTo(QNetworkAccessManager *guest)
+{
+    auto jar = _am->cookieJar();
+    auto oldParent = jar->parent();
+    guest->setCookieJar(jar); // takes ownership of our precious cookie jar
+    jar->setParent(oldParent); // takes it back
 }
 
 void Account::resetNetworkAccessManager()
diff --git a/src/libsync/account.h b/src/libsync/account.h
index 3b8f07c..9209d2d 100644
--- a/src/libsync/account.h
+++ b/src/libsync/account.h
@@ -160,6 +160,7 @@ public:
     QString serverVersion();
 
     void clearCookieJar();
+    void lendCookieJarTo(QNetworkAccessManager *guest);
 
     void resetNetworkAccessManager();
     QNetworkAccessManager* networkAccessManager();
diff --git a/src/libsync/creds/shibboleth/shibbolethwebview.cpp b/src/libsync/creds/shibboleth/shibbolethwebview.cpp
index 8901885..efae1ad 100644
--- a/src/libsync/creds/shibboleth/shibbolethwebview.cpp
+++ b/src/libsync/creds/shibboleth/shibbolethwebview.cpp
@@ -47,13 +47,14 @@ ShibbolethWebView::ShibbolethWebView(AccountPtr account, QWidget* parent)
     setAttribute(Qt::WA_DeleteOnClose);
 
     QWebPage* page = new QWebPage(this);
-    page->setNetworkAccessManager(account->networkAccessManager());
     connect(page, SIGNAL(loadStarted()),
             this, SLOT(slotLoadStarted()));
     connect(page, SIGNAL(loadFinished(bool)),
             this, SLOT(slotLoadFinished(bool)));
 
 
+    // The Account keeps ownership of the cookie jar, it must outlive this webview.
+    account->lendCookieJarTo(page->networkAccessManager());
     connect(page->networkAccessManager()->cookieJar(),
             SIGNAL(newCookiesForUrl (QList<QNetworkCookie>, QUrl)),
             this, SLOT(onNewCookiesForUrl (QList<QNetworkCookie>, QUrl)));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list