summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-10-02 18:29:01 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-10-02 18:29:01 (GMT)
commit143f8b8ecb35118c7ed19564dc36b2f7918be61f (patch)
treefb556493a0adddac1b83d8c7f340aa6bfc0acece
parent1d544eb3af8fbb26611cfc3023ab90709760c9bc (diff)
downloadkolab-utils-143f8b8ecb35118c7ed19564dc36b2f7918be61f.tar.gz
Moved the whole authentication to the SourceServer class, cleanup, preparations for proxy authentication.
-rw-r--r--migrationutility/main.cpp4
-rw-r--r--migrationutility/sourceaccount.cpp39
-rw-r--r--migrationutility/sourceaccount.h9
-rw-r--r--migrationutility/sourceserver.cpp73
-rw-r--r--migrationutility/sourceserver.h7
5 files changed, 51 insertions, 81 deletions
diff --git a/migrationutility/main.cpp b/migrationutility/main.cpp
index d6f0235..7eea659 100644
--- a/migrationutility/main.cpp
+++ b/migrationutility/main.cpp
@@ -60,7 +60,9 @@ int main(int argc, char *argv[])
KolabSourceServer *sourceServer = new KolabSourceServer(&app);
sourceServer->setHost(args->getOption("from"), args->getOption("from-port").toInt());
sourceServer->setAdminCredentials(args->getOption("from-proxyauth"), args->getOption("from-password"));
- sourceServer->setSingleUser(args->getOption("from-user"));
+ if (args->isSet("from-user")) {
+ sourceServer->setSingleUser(args->getOption("from-user"));
+ }
KolabServer *kolabServer = new KolabServer(&app);
kolabServer->setHost(args->getOption("to"), args->getOption("to-port").toInt());
diff --git a/migrationutility/sourceaccount.cpp b/migrationutility/sourceaccount.cpp
index 5d8a20c..e239b17 100644
--- a/migrationutility/sourceaccount.cpp
+++ b/migrationutility/sourceaccount.cpp
@@ -77,47 +77,16 @@ QList<Object> TestAccount::getObjects(const QString& folder)
//--------------------------------------------------------------
-KolabSourceAccount::KolabSourceAccount(QObject* parent)
+KolabSourceAccount::KolabSourceAccount(KIMAP::Session *session, QObject* parent)
: SourceAccount(parent),
- mSession(0),
- mEncryptionMode(KIMAP::LoginJob::TlsV1),
- mAuthenticationMode(KIMAP::LoginJob::Plain)
+ mSession(session)
{
}
-void KolabSourceAccount::setHost(const QString& host, qint16 port)
-{
- mHost = host;
- mPort = port;
-}
-
-void KolabSourceAccount::setCredentials(const QString& username, const QString& pw)
-{
- mUsername = username;
- mPw = pw;
-}
-
void KolabSourceAccount::init()
{
-
- if (mSession) {
- return;
- }
- mSession = new KIMAP::Session( mHost, mPort, this );
- mSession->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) );
- KIMAP::LoginJob *loginJob = new KIMAP::LoginJob( mSession );
- loginJob->setUserName( mUsername );
- loginJob->setPassword( mPw );
- loginJob->setEncryptionMode( mEncryptionMode );
- loginJob->setAuthenticationMode( mAuthenticationMode );
- loginJob->exec();
-
- if ( loginJob->error() ) {
- Warning() << "Failed to login: " << loginJob->errorString();
- } else {
- Debug() << "authentication successful";
- }
+ Q_ASSERT(mSession);
ProbeKolabServerJob *probeJob = new ProbeKolabServerJob(mSession, this);
probeJob->exec();
@@ -140,7 +109,7 @@ QPair<Kolab::FolderType, QString> KolabSourceAccount::translateFolder(const QStr
QStringList KolabSourceAccount::lookupFolderList()
{
- Debug() << "lookupFolderList" << mHost << mPort << mUsername << mPw;
+// Debug() << "lookupFolderList" << mHost << mPort << mUsername << mPw;
init();
KIMAP::ListJob *listJob = new KIMAP::ListJob(mSession);
diff --git a/migrationutility/sourceaccount.h b/migrationutility/sourceaccount.h
index 51ec3fa..bbe1a0b 100644
--- a/migrationutility/sourceaccount.h
+++ b/migrationutility/sourceaccount.h
@@ -59,13 +59,10 @@ class KolabSourceAccount: public SourceAccount
{
Q_OBJECT
public:
- explicit KolabSourceAccount(QObject* parent = 0);
+ explicit KolabSourceAccount(KIMAP::Session *session, QObject* parent = 0);
virtual QStringList lookupFolderList();
virtual QList<Object> getObjects(const QString &folder);
virtual QPair<Kolab::FolderType, QString> translateFolder(const QString& folder);
-
- void setHost(const QString &host, qint16 port);
- void setCredentials(const QString &username, const QString &pw);
void logout();
@@ -75,10 +72,6 @@ private:
void init();
Kolab::FolderType getFolderType(const QString &folder);
KIMAP::Session *mSession;
- QString mHost;
- int mPort;
- QString mUsername;
- QString mPw;
KIMAP::LoginJob::EncryptionMode mEncryptionMode;
KIMAP::LoginJob::AuthenticationMode mAuthenticationMode;
QList<KIMAP::MailBoxDescriptor> mMailboxes;
diff --git a/migrationutility/sourceserver.cpp b/migrationutility/sourceserver.cpp
index 23f0913..5cd7d51 100644
--- a/migrationutility/sourceserver.cpp
+++ b/migrationutility/sourceserver.cpp
@@ -17,9 +17,10 @@
#include "sourceserver.h"
#include "uiproxy.h"
-#include <commonconversion.h>
+#include <jobs/getuserlistjob.h>
#include <kimap/listjob.h>
#include <kimap/logoutjob.h>
+#include <kolab/commonconversion.h>
#include <kolab/errorhandler.h>
@@ -36,7 +37,10 @@ SourceAccount* SourceServer::getSourceAccount(const QString& user)
QStringList SourceServer::getUserList()
{
- return QStringList();
+ if (!mExplicitUsers.isEmpty()) {
+ return mExplicitUsers;
+ }
+ return retrieveUserList();
}
void SourceServer::setSingleUser(const QString &user)
@@ -44,6 +48,12 @@ void SourceServer::setSingleUser(const QString &user)
mExplicitUsers.append(user);
}
+QStringList SourceServer::retrieveUserList()
+{
+ return QStringList();
+}
+
+
TestServer::TestServer(QObject* parent)
@@ -54,7 +64,7 @@ TestServer::TestServer(QObject* parent)
mUsers << QLatin1String("user3");
}
-QStringList TestServer::getUserList()
+QStringList TestServer::retrieveUserList()
{
return mUsers;
}
@@ -91,42 +101,39 @@ void KolabSourceServer::setAdminCredentials(const QString& username, const QStri
SourceAccount* KolabSourceServer::getSourceAccount(const QString& user)
{
- KolabSourceAccount *account = new KolabSourceAccount(this);
- account->setHost(mHost, mPort);
- account->setCredentials(mUsername, mPw);
- return account;
-}
+ KIMAP::Session *session = new KIMAP::Session( mHost, mPort, this );
+ session->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) );
+ KIMAP::LoginJob *loginJob = new KIMAP::LoginJob( session );
+ if (user != mUsername) {
+ loginJob->setAuthorizationName(mUsername);
+ }
+ loginJob->setUserName( user );
+ loginJob->setPassword( mPw );
+ loginJob->setEncryptionMode( mEncryptionMode );
+ loginJob->setAuthenticationMode( mAuthenticationMode );
+ loginJob->exec();
-QStringList KolabSourceServer::getUserList()
-{
- if (!mExplicitUsers.isEmpty()) {
- return mExplicitUsers;
+ if ( loginJob->error() ) {
+ Error() << "Failed to login: " << loginJob->errorString();
+ return 0;
+ } else {
+ Debug() << "authentication successful";
}
- //TODO split into retrieve user list
+ return new KolabSourceAccount(session, this);
+}
+
+QStringList KolabSourceServer::retrieveUserList()
+{
mSession = new KIMAP::Session( mHost, mPort, this );
mSession->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) );
-// QObject::connect( mSession, SIGNAL(stateChanged(KIMAP::Session::State,KIMAP::Session::State)),
-// this, SLOT(onSessionStateChanged(KIMAP::Session::State,KIMAP::Session::State)) );
KIMAP::LoginJob *loginJob = new KIMAP::LoginJob( mSession );
-// if (!proxyauth.isEmpty()) {
-// loginJob->setAuthorizationName(proxyauth);
-// }
loginJob->setUserName( mUsername );
loginJob->setPassword( mPw );
loginJob->setEncryptionMode( mEncryptionMode );
-// if (encryptionMode != KIMAP::LoginJob::Unencrypted) {
-// m_requireEncryption = true;
-// } else {
-// m_requireEncryption = false;
-// }
loginJob->setAuthenticationMode( mAuthenticationMode );
-/* Object::connect( loginJob, SIGNAL(result(KJob*)),
- this, SLOT(onLoginDone(KJob*)) );
- loginJob->start(); */
loginJob->exec();
-
if ( loginJob->error() ) {
Warning() << "Failed to login: " << loginJob->errorString();
@@ -134,14 +141,12 @@ QStringList KolabSourceServer::getUserList()
Debug() << "authentication successful";
}
-// KIMAP::ListJob *listJob = new KIMAP::ListJob(mSession);
-// listJob->setOption(KIMAP::ListJob::IncludeUnsubscribed);
-// listJob->exec();
-// listJob->mailBoxes();
-
+ GetUserListJob *userListJob = new GetUserListJob(mSession, this);
+ userListJob->exec();
+ const QStringList userList = userListJob->getUserList();
logout();
-
- return QStringList();
+
+ return userList;
}
diff --git a/migrationutility/sourceserver.h b/migrationutility/sourceserver.h
index 5fe381c..8a484e5 100644
--- a/migrationutility/sourceserver.h
+++ b/migrationutility/sourceserver.h
@@ -31,7 +31,8 @@ public:
explicit SourceServer(QObject* parent = 0);
// void setAdminCredentials(const QString &username, const QString &pw);
virtual SourceAccount *getSourceAccount(const QString &user);
- virtual QStringList getUserList();
+ QStringList getUserList();
+ virtual QStringList retrieveUserList();
void setSingleUser(const QString &);
protected:
QStringList mExplicitUsers;
@@ -45,7 +46,7 @@ public:
explicit TestServer(QObject* parent = 0);
virtual SourceAccount *getSourceAccount(const QString &user);
- virtual QStringList getUserList();
+ virtual QStringList retrieveUserList();
QStringList mUsers;
};
@@ -56,7 +57,7 @@ public:
explicit KolabSourceServer(QObject* parent = 0);
virtual SourceAccount *getSourceAccount(const QString &user);
- virtual QStringList getUserList();
+ virtual QStringList retrieveUserList();
void setHost(const QString &host, qint16 port);
void setAdminCredentials(const QString &username, const QString &pw);