[Shib] Ensure only one fetch job can open the browser

This commit is contained in:
Daniel Molkentin 2014-06-02 17:41:32 +02:00
parent a50e7c1b48
commit 7e65c9741e
2 changed files with 14 additions and 0 deletions

View file

@ -88,6 +88,7 @@ ShibbolethCredentials::ShibbolethCredentials()
_url(), _url(),
_ready(false), _ready(false),
_stillValid(false), _stillValid(false),
_fetchJobInProgress(false),
_browser(0) _browser(0)
{} {}
@ -178,10 +179,16 @@ bool ShibbolethCredentials::ready() const
void ShibbolethCredentials::fetch(Account *account) void ShibbolethCredentials::fetch(Account *account)
{ {
if(_fetchJobInProgress) {
return;
}
if (_user.isEmpty()) { if (_user.isEmpty()) {
_user = account->credentialSetting(QLatin1String(userC)).toString(); _user = account->credentialSetting(QLatin1String(userC)).toString();
} }
if (_ready) { if (_ready) {
_fetchJobInProgress = false;
Q_EMIT fetched(); Q_EMIT fetched();
} else { } else {
if (account) { if (account) {
@ -194,6 +201,7 @@ void ShibbolethCredentials::fetch(Account *account)
job->setProperty("account", QVariant::fromValue(account)); job->setProperty("account", QVariant::fromValue(account));
connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotReadJobDone(QKeychain::Job*))); connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotReadJobDone(QKeychain::Job*)));
job->start(); job->start();
_fetchJobInProgress = true;
} }
} }
@ -264,6 +272,7 @@ void ShibbolethCredentials::slotUserFetched(const QString &user)
_stillValid = true; _stillValid = true;
_ready = true; _ready = true;
_fetchJobInProgress = false;
Q_EMIT fetched(); Q_EMIT fetched();
} }
@ -271,12 +280,14 @@ void ShibbolethCredentials::slotUserFetched(const QString &user)
void ShibbolethCredentials::slotBrowserRejected() void ShibbolethCredentials::slotBrowserRejected()
{ {
_ready = false; _ready = false;
_fetchJobInProgress = false;
Q_EMIT fetched(); Q_EMIT fetched();
} }
void ShibbolethCredentials::invalidateAndFetch(Account* account) void ShibbolethCredentials::invalidateAndFetch(Account* account)
{ {
_ready = false; _ready = false;
_fetchJobInProgress = true;
// delete the credentials, then in the slot fetch them again (which will trigger browser) // delete the credentials, then in the slot fetch them again (which will trigger browser)
DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName()); DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
@ -293,6 +304,7 @@ void ShibbolethCredentials::slotInvalidateAndFetchInvalidateDone(QKeychain::Job*
connect (this, SIGNAL(fetched()), connect (this, SIGNAL(fetched()),
this, SLOT(onFetched())); this, SLOT(onFetched()));
_fetchJobInProgress = false;
// small hack to support the ShibbolethRefresher hack // small hack to support the ShibbolethRefresher hack
// we already rand fetch() with a valid account object, // we already rand fetch() with a valid account object,
// and hence know the url on refresh // and hence know the url on refresh
@ -323,6 +335,7 @@ void ShibbolethCredentials::slotReadJobDone(QKeychain::Job *job)
_ready = true; _ready = true;
_stillValid = true; _stillValid = true;
_fetchJobInProgress = false;
Q_EMIT fetched(); Q_EMIT fetched();
} else { } else {
showLoginWindow(account); showLoginWindow(account);

View file

@ -82,6 +82,7 @@ private:
bool _ready; bool _ready;
bool _stillValid; bool _stillValid;
bool _fetchJobInProgress;
QPointer<ShibbolethWebView> _browser; QPointer<ShibbolethWebView> _browser;
QNetworkCookie _shibCookie; QNetworkCookie _shibCookie;
QString _user; QString _user;