Fix shibboleth syncing after client restart.

We needed to notify shibboleth-specific QNAM about new cookie and then
stop cramming that cookie into request via setHeader, but rather put
it to cookie jar and let Qt handle the cookie insertion into requests.
This commit is contained in:
Krzesimir Nowak 2013-07-30 12:56:27 +02:00
parent 78b6f4df01
commit 6a9a2559d2
4 changed files with 39 additions and 10 deletions

View file

@ -11,6 +11,7 @@
* for more details.
*/
#include <QDebug>
#include <QNetworkRequest>
#include "creds/shibboleth/shibbolethaccessmanager.h"
@ -18,20 +19,37 @@
namespace Mirall
{
ShibbolethAccessManager::ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent)
ShibbolethAccessManager::ShibbolethAccessManager(const QNetworkCookie& cookie, QObject* parent)
: QNetworkAccessManager (parent),
_cookie(cookie)
{}
QNetworkReply* ShibbolethAccessManager::createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData)
QNetworkReply* ShibbolethAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData)
{
QNetworkRequest newRequest(request);
QList<QNetworkCookie> cookies(request.header(QNetworkRequest::CookieHeader).value< QList< QNetworkCookie > >());
if (!_cookie.name().isEmpty()) {
QNetworkCookieJar* jar(cookieJar());
QUrl url(request.url());
QList<QNetworkCookie> cookies;
cookies << _cookie;
newRequest.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue (cookies));
Q_FOREACH(const QNetworkCookie& cookie, jar->cookiesForUrl(url)) {
if (!cookie.name().startsWith("_shibsession_")) {
cookies << cookie;
}
}
return QNetworkAccessManager::createRequest (op, newRequest, outgoingData);
cookies << _cookie;
jar->setCookiesFromUrl(cookies, url);
}
qDebug() << "Creating a request to " << request.url().toString() << " with shibboleth cookie:" << _cookie.name();
return QNetworkAccessManager::createRequest (op, request, outgoingData);
}
void ShibbolethAccessManager::setCookie(const QNetworkCookie& cookie)
{
qDebug() << "Got new shibboleth cookie:" << cookie.name();
_cookie = cookie;
}
} // ns Mirall

View file

@ -25,10 +25,13 @@ class ShibbolethAccessManager : public QNetworkAccessManager
Q_OBJECT
public:
ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent = 0);
ShibbolethAccessManager(const QNetworkCookie& cookie, QObject* parent = 0);
public Q_SLOTS:
void setCookie(const QNetworkCookie& cookie);
protected:
QNetworkReply* createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0);
QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0);
private:
QNetworkCookie _cookie;

View file

@ -81,7 +81,11 @@ QNetworkCookie ShibbolethCredentials::cookie() const
QNetworkAccessManager* ShibbolethCredentials::getQNAM() const
{
return new ShibbolethAccessManager(_shibCookie);
ShibbolethAccessManager* qnam(new ShibbolethAccessManager(_shibCookie));
connect(this, SIGNAL(newCookie(QNetworkCookie)),
qnam, SLOT(setCookie(QNetworkCookie)));
return qnam;
}
bool ShibbolethCredentials::ready() const
@ -117,6 +121,7 @@ void ShibbolethCredentials::onShibbolethCookieReceived(const QNetworkCookie& coo
_browser = 0;
_ready = true;
_shibCookie = cookie;
Q_EMIT newCookie(_shibCookie);
Q_EMIT fetched();
}

View file

@ -45,6 +45,9 @@ public:
private Q_SLOTS:
void onShibbolethCookieReceived(const QNetworkCookie& cookie);
Q_SIGNALS:
void newCookie(const QNetworkCookie& cookie);
private:
QNetworkCookie _shibCookie;
bool _ready;