Skip to content

Commit

Permalink
Merge pull request #11 from nemomobile-packages/vdv-devel
Browse files Browse the repository at this point in the history
[qmf] Don't call signon-ui from background process.
  • Loading branch information
VDVsx committed Nov 11, 2013
2 parents 389852a + 7181001 commit 3a12985
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 37 deletions.
4 changes: 2 additions & 2 deletions qmf/src/libraries/qmfclient/ssoauthplugin.h
Expand Up @@ -59,8 +59,8 @@ class QMF_EXPORT SSOAuthService : public QObject
virtual QString key() const = 0;
virtual QList<QByteArray> authentication(const SignOn::SessionData &sessionData,
const QString &serviceType, const QString &userName, int serviceAuthentication) const = 0;
virtual SignOn::SessionData sessionData(const QString &accountProvider, QVariantMap authParameters,
bool setUiPolicy) const = 0;
virtual void credentialsNeedUpdate(int accountId) = 0;
virtual SignOn::SessionData sessionData(const QString &accountProvider, QVariantMap authParameters) const = 0;
virtual SSOAuthService *createService() = 0;
};

Expand Down
30 changes: 22 additions & 8 deletions qmf/src/libraries/qmfclient/ssosessionmanager.cpp
Expand Up @@ -127,9 +127,10 @@ bool SSOSessionManager::createSsoIdentity(const QMailAccountId &id, const QStrin
deleteSsoIdentity();
_serviceAuthentication = serviceAuthentication;
_serviceType = serviceType;
_accountId = id.toULongLong();

SSOAccountManager manager;
Accounts::Account* account = manager->account(static_cast<Accounts::AccountId>(id.toULongLong()));
Accounts::Account* account = manager->account(static_cast<Accounts::AccountId>(_accountId));
if (!account)
return false;

Expand Down Expand Up @@ -185,14 +186,26 @@ bool SSOSessionManager::createSsoIdentity(const QMailAccountId &id, const QStrin
this, SLOT(ssoSessionError(SignOn::Error))));
_waitForSso = true;
_authService = SSOAuthFactory::createService(_authMethod);
_session->process(_authService->sessionData(_accountProvider, _authParameters, false), _authMechanism);
_session->process(_authService->sessionData(_accountProvider, _authParameters), _authMechanism);
return true;
} else {
_session = 0;
return false;
}
}

/*!
Set credentials need update if the plugin supports it.
*/

void SSOSessionManager::credentialsNeedUpdate()
{
qMailLog(Messaging) << Q_FUNC_INFO << "Setting credentials need update for the service " << _serviceType
<< " from account " << _accountId
<< " using authentication method " << _authMethod;
_authService->credentialsNeedUpdate(_accountId);
}

/*!
Deletes the SSO identity.
*/
Expand All @@ -213,12 +226,9 @@ void SSOSessionManager::deleteSsoIdentity()
Recreates the SSO identity.
This function should be used when stored authentication details
are no longer valid. By default \a setUiPolicy is set to true,
in this case if the authentication plugin in use has a UI policy
defined this function can trigger additional processes that will request
actions from the user.
are no longer valid.
*/
void SSOSessionManager::recreateSsoIdentity(bool setUiPolicy)
void SSOSessionManager::recreateSsoIdentity()
{
qMailLog(Messaging) << Q_FUNC_INFO << "Recreating SSO identity using auth method "
<< _authMethod;
Expand All @@ -227,7 +237,7 @@ void SSOSessionManager::recreateSsoIdentity(bool setUiPolicy)
_authService = SSOAuthFactory::createService(_authMethod);

_waitForSso = true;
_session->process(_authService->sessionData(_accountProvider, _authParameters, setUiPolicy), _authMechanism);
_session->process(_authService->sessionData(_accountProvider, _authParameters), _authMechanism);
} else {
_waitForSso = true;
emit ssoSessionError("SSO error: Identity is not valid, can't recreate session.");
Expand Down Expand Up @@ -262,6 +272,10 @@ void SSOSessionManager::ssoResponse(const SignOn::SessionData &sessionData)

void SSOSessionManager::ssoSessionError(const SignOn::Error &code)
{
if (code.type() == SignOn::Error::InvalidCredentials || code.type() == SignOn::Error:: UserInteraction) {
credentialsNeedUpdate();
}

if (_waitForSso) {
_waitForSso = false;
_ssoLogin = QByteArray();
Expand Down
5 changes: 4 additions & 1 deletion qmf/src/libraries/qmfclient/ssosessionmanager.h
Expand Up @@ -49,6 +49,7 @@
#include <qglobal.h>

// Accounts
#include <Accounts/Account>
#include <SignOn/Identity>
#include <SignOn/SessionData>

Expand All @@ -64,8 +65,9 @@ class QMF_EXPORT SSOSessionManager : public QObject
void cancel();
bool createSsoIdentity(const QMailAccountId &id,
const QString &serviceType, int serviceAuthentication);
void credentialsNeedUpdate();
void deleteSsoIdentity();
void recreateSsoIdentity(bool setUiPolicy = true);
void recreateSsoIdentity();
void removeSsoIdentity();
bool waitForSso();

Expand All @@ -82,6 +84,7 @@ protected slots:
QString serviceCredentialsId(const QString &serviceType) const;

int _serviceAuthentication;
int _accountId;
bool _waitForSso;
QByteArray _ssoLogin;
QString _authMethod;
Expand Down
23 changes: 15 additions & 8 deletions qmf/src/plugins/messageservices/imap/imapclient.cpp
Expand Up @@ -589,8 +589,7 @@ ImapClient::ImapClient(QObject* parent)
_ssoSessionManager(0),
_loginFailed(false),
_sendLogin(false),
_recreateIdentity(true),
_accountUpdated(false)
_recreateIdentity(true)
{
static int count(0);
++count;
Expand Down Expand Up @@ -801,6 +800,7 @@ void ImapClient::checkCommandResponse(ImapCommand command, OperationStatus statu
return;
} else {
_recreateIdentity = true;
ssoCredentialsNeedUpdate();
operationFailed(QMailServiceAction::Status::ErrLoginFailed, _protocol.lastError());
return;
}
Expand Down Expand Up @@ -2000,23 +2000,33 @@ void ImapClient::ssoProcessLogin()
// identity without asking the user for new
// credentials
if (_ssoSessionManager)
_ssoSessionManager->recreateSsoIdentity(!_accountUpdated);
_ssoSessionManager->recreateSsoIdentity();
else
operationFailed(QMailServiceAction::Status::ErrLoginFailed, "SSO Error: can't recreate identity.");
} else {
if (_sendLogin && !_ssoSessionManager->waitForSso()) {
_sendLogin = false;
_protocol.sendLogin(_config, _ssoLogin);
} else {
qMailLog(IMAP) << Q_FUNC_INFO << "Waiting for SSO...";
}
}
}

void ImapClient::ssoCredentialsNeedUpdate()
{
if (_ssoSessionManager) {
_ssoSessionManager->credentialsNeedUpdate();
} else {
qMailLog(IMAP) << Q_FUNC_INFO << "SSO Error: can't set credentials need update.";
}
}

void ImapClient::onSsoSessionResponse(const QList<QByteArray> &ssoLogin)
{
qMailLog(IMAP) << "Got SSO response";
if (!ssoLogin.isEmpty()) {
if (_accountUpdated && _ssoLogin != ssoLogin[0]) {
_accountUpdated = false;
if (_ssoLogin != ssoLogin[0]) {
_ssoLogin = ssoLogin[0];
} else {
_ssoLogin = ssoLogin[0];
Expand Down Expand Up @@ -2062,9 +2072,6 @@ void ImapClient::onAccountsUpdated(const QMailAccountIdList &list)
return;
}

if (_ssoSessionManager)
_accountUpdated = true;

qMailLog(IMAP) << Q_FUNC_INFO << imapCfg1.mailUserName() ;
// compare config modified by the User
const bool& notEqual = (imapCfg1.mailUserName() != imapCfg2.mailUserName()) ||
Expand Down
2 changes: 1 addition & 1 deletion qmf/src/plugins/messageservices/imap/imapclient.h
Expand Up @@ -168,6 +168,7 @@ protected slots:

#ifdef USE_ACCOUNTS_QT
void ssoProcessLogin();
void ssoCredentialsNeedUpdate();
#endif
void deactivateConnection();
void retrieveOperationCompleted();
Expand Down Expand Up @@ -208,7 +209,6 @@ protected slots:
bool _loginFailed;
bool _sendLogin;
bool _recreateIdentity;
bool _accountUpdated;
QByteArray _ssoLogin;
#endif
};
Expand Down
16 changes: 12 additions & 4 deletions qmf/src/plugins/messageservices/pop/popclient.cpp
Expand Up @@ -87,8 +87,7 @@ PopClient::PopClient(QObject* parent)
pendingDeletes(false),
ssoSessionManager(0),
loginFailed(false),
sendLogin(false),
accountUpdated(false)
sendLogin(false)
{
inactiveTimer.setSingleShot(true);
connect(&inactiveTimer, SIGNAL(timeout()), this, SLOT(connectionInactive()));
Expand Down Expand Up @@ -539,6 +538,7 @@ void PopClient::processResponse(const QString &response)
loginFailed = true;
ssoProcessLogin();
} else {
ssoCredentialsNeedUpdate();
operationFailed(QMailServiceAction::Status::ErrLoginFailed, "");
}
#else
Expand Down Expand Up @@ -1393,12 +1393,21 @@ void PopClient::onSsoSessionError(const QString &error)
operationFailed(QMailSearchAction::Status::ErrLoginFailed, error);
}

void PopClient::ssoCredentialsNeedUpdate()
{
if (ssoSessionManager) {
ssoSessionManager->credentialsNeedUpdate();
} else {
qMailLog(POP) << Q_FUNC_INFO << "SSO Error: can't set credentials need update.";
}
}

void PopClient::ssoProcessLogin()
{
if (loginFailed) {
if (ssoSessionManager) {
sendLogin = true;
ssoSessionManager->recreateSsoIdentity(!accountUpdated);
ssoSessionManager->recreateSsoIdentity();
} else
operationFailed(QMailServiceAction::Status::ErrLoginFailed, "SSO Error: can't recreate identity.");
} else {
Expand All @@ -1416,7 +1425,6 @@ void PopClient::onAccountsUpdated(const QMailAccountIdList &list)
bool isEnabled(acc.status() & QMailAccount::Enabled);
if (!isEnabled)
return;
accountUpdated = true;
setAccount(accountId());
}

Expand Down
2 changes: 1 addition & 1 deletion qmf/src/plugins/messageservices/pop/popclient.h
Expand Up @@ -126,6 +126,7 @@ protected slots:

private:
#ifdef USE_ACCOUNTS_QT
void ssoCredentialsNeedUpdate();
void ssoProcessLogin();
#endif
void deactivateConnection();
Expand Down Expand Up @@ -211,7 +212,6 @@ protected slots:
SSOSessionManager* ssoSessionManager;
bool loginFailed;
bool sendLogin;
bool accountUpdated;
QList<QByteArray> ssoLogin;
#endif
};
Expand Down
16 changes: 11 additions & 5 deletions qmf/src/plugins/messageservices/smtp/smtpclient.cpp
Expand Up @@ -114,7 +114,6 @@ SmtpClient::SmtpClient(QObject* parent)
, ssoSessionManager(0)
, loginFailed(false)
, sendLogin(false)
, accountUpdated(false)
{
connect(QMailStore::instance(), SIGNAL(accountsUpdated(const QMailAccountIdList&)),
this, SLOT(accountsUpdated(const QMailAccountIdList&)));
Expand Down Expand Up @@ -156,7 +155,6 @@ void SmtpClient::accountsUpdated(const QMailAccountIdList &ids)
bool isEnabled(acc.status() & QMailAccount::Enabled);
if (!isEnabled)
return;
accountUpdated = true;
setAccount(account());
}

Expand Down Expand Up @@ -614,7 +612,7 @@ void SmtpClient::nextAction(const QString &response)
if (loginFailed) {
if (ssoSessionManager) {
sendLogin = true;
ssoSessionManager->recreateSsoIdentity(!accountUpdated);
ssoSessionManager->recreateSsoIdentity();
} else
operationFailed(QMailServiceAction::Status::ErrLoginFailed, response);
} else {
Expand Down Expand Up @@ -659,6 +657,7 @@ void SmtpClient::nextAction(const QString &response)
status = SignOnSession;
nextAction(QString());
} else {
ssoCredentialsNeedUpdate();
operationFailed(QMailServiceAction::Status::ErrLoginFailed, response);
}
#else
Expand Down Expand Up @@ -1086,6 +1085,15 @@ void SmtpClient::stopTransferring()
}

#ifdef USE_ACCOUNTS_QT
void SmtpClient::ssoCredentialsNeedUpdate()
{
if (ssoSessionManager) {
ssoSessionManager->credentialsNeedUpdate();
} else {
qMailLog(SMTP) << Q_FUNC_INFO << "SSO Error: can't set credentials need update.";
}
}

void SmtpClient::removeSsoIdentity(const QMailAccountId &accountId)
{
if (config.id() == accountId) {
Expand All @@ -1102,8 +1110,6 @@ void SmtpClient::onSsoSessionResponse(const QList<QByteArray> &ssoCredentials)
qMailLog(SMTP) << "Got SSO response";
if(!ssoCredentials.isEmpty()) {
ssoLogin = ssoCredentials;
if (accountUpdated)
accountUpdated = false;
if (sendLogin) {
sendLogin = false;
QByteArray authCmd(SmtpAuthenticator::getAuthentication(config.serviceConfiguration("smtp"), capabilities, ssoLogin));
Expand Down
2 changes: 1 addition & 1 deletion qmf/src/plugins/messageservices/smtp/smtpclient.h
Expand Up @@ -78,6 +78,7 @@ class SmtpClient : public QObject
QMailAccountId account() const;

#ifdef USE_ACCOUNTS_QT
void ssoCredentialsNeedUpdate();
void removeSsoIdentity(const QMailAccountId &accountId);
#endif

Expand Down Expand Up @@ -174,7 +175,6 @@ private slots:
SSOSessionManager* ssoSessionManager;
bool loginFailed;
bool sendLogin;
bool accountUpdated;
QList<QByteArray> ssoLogin;
#endif
};
Expand Down
13 changes: 9 additions & 4 deletions qmf/src/plugins/ssoauth/password/passwordplugin.cpp
Expand Up @@ -160,15 +160,20 @@ QList<QByteArray> SSOPasswordPlugin::authentication(const SignOn::SessionData &s
}
}

SignOn::SessionData SSOPasswordPlugin::sessionData(const QString &accountProvider, QVariantMap authParameters,
bool setUiPolicy) const
void SSOPasswordPlugin::credentialsNeedUpdate(int accountId)
{
// For the password method we don't do anything, messageserver
// already informs the clients about login failed.
Q_UNUSED(accountId);
}

SignOn::SessionData SSOPasswordPlugin::sessionData(const QString &accountProvider, QVariantMap authParameters) const
{
Q_UNUSED(accountProvider);
Q_UNUSED(authParameters);

SignOn::SessionData data;
if (setUiPolicy)
data.setUiPolicy(SignOn::RequestPasswordPolicy);
data.setUiPolicy(SignOn::NoUserInteractionPolicy);
return data;
}

Expand Down
4 changes: 2 additions & 2 deletions qmf/src/plugins/ssoauth/password/passwordplugin.h
Expand Up @@ -61,8 +61,8 @@ class SSOPasswordPlugin : public SSOAuthService
virtual QString key() const;
virtual QList<QByteArray> authentication(const SignOn::SessionData &sessionData,
const QString &serviceType, const QString &userName, int serviceAuthentication) const;
virtual SignOn::SessionData sessionData(const QString &accountProvider, QVariantMap authParameters,
bool setUiPolicy) const;
virtual void credentialsNeedUpdate(int accountId);
virtual SignOn::SessionData sessionData(const QString &accountProvider, QVariantMap authParameters) const;
virtual SSOAuthService* createService();

private:
Expand Down

0 comments on commit 3a12985

Please sign in to comment.