_connectionStatus = ConnectionValidator::Undefined;
_connectionErrors.clear();
} else if (oldState == SignedOut && _state == Disconnected) {
- checkConnectivity();
+ checkConnectivity(AbstractCredentials::Interactive);
}
}
return isConnected() || _state == ServiceUnavailable;
}
-void AccountState::checkConnectivity()
+void AccountState::checkConnectivity(AbstractCredentials::FetchMode credentialsFetchMode)
{
if (isSignedOut() || _waitingForNewCredentials) {
return;
qDebug() << "ConnectionValidator already running, ignoring";
return;
}
- ConnectionValidator * conValidator = new ConnectionValidator(account());
+ ConnectionValidator * conValidator = new ConnectionValidator(account(), credentialsFetchMode);
_connectionValidator = conValidator;
connect(conValidator, SIGNAL(connectionResult(ConnectionValidator::Status,QStringList)),
SLOT(slotConnectionValidatorResult(ConnectionValidator::Status,QStringList)));
delete _connectionValidator;
}
- checkConnectivity();
+ // If we made it this far, it means that we either fetched credentials
+ // interactively, or that we already aborted for missing/invalid credentials.
+ Q_ASSERT(credentials->ready());
+ checkConnectivity(AbstractCredentials::Interactive);
}
std::unique_ptr<QSettings> AccountState::settings()
/// Triggers a ping to the server to update state and
/// connection status and errors.
- void checkConnectivity();
+ void checkConnectivity(AbstractCredentials::FetchMode credentialsFetchMode);
/** Returns a new settings object for this account, already in the right groups. */
std::unique_ptr<QSettings> settings();
// when the error is permanent.
if (state != AccountState::SignedOut
&& state != AccountState::ConfigurationError) {
- accountState->checkConnectivity();
+ accountState->checkConnectivity(AbstractCredentials::NonInteractive);
}
}
#include "accessmanager.h"
#include "account.h"
+#include "logger.h"
#include "theme.h"
#include "cookiejar.h"
#include "syncengine.h"
: _ready(true),
_stillValid(true),
_fetchJobInProgress(false),
+ _interactiveFetch(true),
_browser(0),
_shibCookie(cookie)
{
return _ready;
}
-void ShibbolethCredentials::fetch()
+void ShibbolethCredentials::fetch(FetchMode mode)
{
if(_fetchJobInProgress) {
return;
}
+ _interactiveFetch = mode == Interactive;
if (_user.isEmpty()) {
_user = _account->credentialSetting(QLatin1String(userC)).toString();
_stillValid = true;
_fetchJobInProgress = false;
Q_EMIT fetched();
- } else {
+ } else if (_interactiveFetch) {
showLoginWindow();
+ } else {
+ Logger::instance()->postOptionalGuiLog(tr("Reauthentication required"), tr("You need to re-login to continue using the account %1.").arg(_account->displayName()));
+ _ready = false;
+ _fetchJobInProgress = false;
+ Q_EMIT fetched();
}
}
QString user() const Q_DECL_OVERRIDE;
QNetworkAccessManager* getQNAM() const Q_DECL_OVERRIDE;
bool ready() const Q_DECL_OVERRIDE;
- void fetch() Q_DECL_OVERRIDE;
+ void fetch(FetchMode mode = Interactive) Q_DECL_OVERRIDE;
bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE;
void persist() Q_DECL_OVERRIDE;
void invalidateToken() Q_DECL_OVERRIDE;
bool _ready;
bool _stillValid;
bool _fetchJobInProgress;
+ bool _interactiveFetch;
QPointer<ShibbolethWebView> _browser;
QNetworkCookie _shibCookie;
QString _user;
namespace OCC {
-ConnectionValidator::ConnectionValidator(AccountPtr account, QObject *parent)
+ConnectionValidator::ConnectionValidator(AccountPtr account, AbstractCredentials::FetchMode credentialsFetchMode, QObject *parent)
: QObject(parent),
_account(account),
+ _credentialsFetchMode(credentialsFetchMode),
_isCheckingServerAndAuth(false)
{
}
// We can't proceed with the auth check because we don't have credentials.
// Fetch them now! Once fetched, a new connectivity check will be
// initiated anyway.
- creds->fetch();
+ creds->fetch(_credentialsFetchMode);
// no result is reported
deleteLater();
#include <QVariantMap>
#include <QNetworkReply>
#include "accountfwd.h"
+#include "creds/abstractcredentials.h"
namespace OCC {
{
Q_OBJECT
public:
- explicit ConnectionValidator(AccountPtr account, QObject *parent = 0);
+ explicit ConnectionValidator(AccountPtr account, AbstractCredentials::FetchMode credentialsFetchMode, QObject *parent = 0);
enum Status {
Undefined,
QStringList _errors;
AccountPtr _account;
+ AbstractCredentials::FetchMode _credentialsFetchMode;
bool _isCheckingServerAndAuth;
};
Q_OBJECT
public:
+ enum FetchMode { Interactive, NonInteractive };
AbstractCredentials();
// No need for virtual destructor - QObject already has one.
virtual QString user() const = 0;
virtual QNetworkAccessManager* getQNAM() const = 0;
virtual bool ready() const = 0;
- virtual void fetch() = 0;
+ virtual void fetch(FetchMode mode = Interactive) = 0;
virtual bool stillValid(QNetworkReply *reply) = 0;
virtual void persist() = 0;
/** Invalidates auth token, or password for basic auth */
return true;
}
-void DummyCredentials::fetch()
+void DummyCredentials::fetch(FetchMode)
{
Q_EMIT(fetched());
}
QNetworkAccessManager* getQNAM() const Q_DECL_OVERRIDE;
bool ready() const Q_DECL_OVERRIDE;
bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE;
- void fetch() Q_DECL_OVERRIDE;
+ void fetch(FetchMode mode = Interactive) Q_DECL_OVERRIDE;
void persist() Q_DECL_OVERRIDE;
void invalidateToken() Q_DECL_OVERRIDE {}
};
#include "account.h"
#include "accessmanager.h"
+#include "logger.h"
#include "utility.h"
#include "theme.h"
#include "syncengine.h"
_certificatePath(),
_certificatePasswd(),
_ready(false),
- _fetchJobInProgress(false)
+ _fetchJobInProgress(false),
+ _interactiveFetch(true)
{
}
_certificatePath(certificatePath),
_certificatePasswd(certificatePasswd),
_ready(true),
- _fetchJobInProgress(false)
+ _fetchJobInProgress(false),
+ _interactiveFetch(true)
{
}
return _user;
}
-void HttpCredentials::fetch()
+void HttpCredentials::fetch(FetchMode mode)
{
if (_fetchJobInProgress) {
return;
}
+ _interactiveFetch = mode == Interactive;
// User must be fetched from config file
fetchUser();
job->errorString());
}
- bool ok;
- QString pwd = queryPassword(&ok, hint);
+ bool ok = false;
+ QString pwd;
+ if (_interactiveFetch)
+ pwd = queryPassword(&ok, hint);
+ else
+ Logger::instance()->postOptionalGuiLog(tr("Reauthentication required"), tr("You need to re-login to continue using the account %1.").arg(_account->displayName()));
_fetchJobInProgress = false;
if (ok) {
_password = pwd;
QString authType() const Q_DECL_OVERRIDE;
QNetworkAccessManager* getQNAM() const Q_DECL_OVERRIDE;
bool ready() const Q_DECL_OVERRIDE;
- void fetch() Q_DECL_OVERRIDE;
+ void fetch(FetchMode mode = Interactive) Q_DECL_OVERRIDE;
bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE;
void persist() Q_DECL_OVERRIDE;
QString user() const Q_DECL_OVERRIDE;
QString _certificatePasswd;
bool _ready;
bool _fetchJobInProgress; //True if the keychain job is in progress or the input dialog visible
+ bool _interactiveFetch;
};
} // namespace OCC
return _ready;
}
-void TokenCredentials::fetch()
+void TokenCredentials::fetch(FetchMode)
{
Q_EMIT fetched();
}
QString authType() const Q_DECL_OVERRIDE;
QNetworkAccessManager* getQNAM() const Q_DECL_OVERRIDE;
bool ready() const Q_DECL_OVERRIDE;
- void fetch() Q_DECL_OVERRIDE;
+ void fetch(FetchMode mode = Interactive) Q_DECL_OVERRIDE;
bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE;
void persist() Q_DECL_OVERRIDE;
QString user() const Q_DECL_OVERRIDE;