[SCM] ktp-auth-handler packaging branch, master, updated. debian/15.12.1-2-282-g080758e

Maximiliano Curia maxy at moszumanska.debian.org
Fri May 27 23:58:32 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-auth-handler.git;a=commitdiff;h=a4df8a2

The following commit has been merged in the master branch:
commit a4df8a2fab9b722aaea3ba3aae6d6b73543ba852
Author: Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
Date:   Thu Dec 22 22:25:26 2011 +0100

    Refactor SaslAuthOp to support different authentication methods
---
 CMakeLists.txt                                     |   1 +
 sasl-auth-op.cpp                                   | 115 ++++-----------------
 sasl-auth-op.h                                     |  11 +-
 ....cpp => x-telepathy-password-auth-operation.cpp |  78 ++++----------
 ...h-op.h => x-telepathy-password-auth-operation.h |  35 +++----
 5 files changed, 60 insertions(+), 180 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1a263b6..413f14f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,6 +30,7 @@ set(ktp_auth_handler_SRCS
     tls-cert-verifier-op.cpp
     tls-handler.cpp
     types.cpp
+    x-telepathy-password-auth-operation.cpp
     ${ktp_common_internals_SRCS}
 )
 
diff --git a/sasl-auth-op.cpp b/sasl-auth-op.cpp
index 99df66d..4fdfa2d 100644
--- a/sasl-auth-op.cpp
+++ b/sasl-auth-op.cpp
@@ -19,23 +19,20 @@
  */
 
 #include "sasl-auth-op.h"
+#include "x-telepathy-password-auth-operation.h"
 
 #include <TelepathyQt/PendingVariantMap>
 
 #include <KDebug>
 #include <KLocalizedString>
 
-#include "password-prompt.h"
-
-#include <KTp/wallet-interface.h>
 
 SaslAuthOp::SaslAuthOp(const Tp::AccountPtr &account,
         const Tp::ChannelPtr &channel)
     : Tp::PendingOperation(channel),
       m_account(account),
       m_channel(channel),
-      m_saslIface(channel->interface<Tp::Client::ChannelInterfaceSASLAuthenticationInterface>()),
-      m_canTryAgain(false)
+      m_saslIface(channel->interface<Tp::Client::ChannelInterfaceSASLAuthenticationInterface>())
 {
     connect(m_saslIface->requestAllProperties(),
             SIGNAL(finished(Tp::PendingOperation*)),
@@ -57,106 +54,36 @@ void SaslAuthOp::gotProperties(Tp::PendingOperation *op)
 
     Tp::PendingVariantMap *pvm = qobject_cast<Tp::PendingVariantMap*>(op);
     QVariantMap props = qdbus_cast<QVariantMap>(pvm->result());
-    m_canTryAgain = qdbus_cast<bool>(props.value("CanTryAgain"));
     QStringList mechanisms = qdbus_cast<QStringList>(props.value("AvailableMechanisms"));
-    if (!mechanisms.contains(QLatin1String("X-TELEPATHY-PASSWORD"))) {
-        kWarning() << "X-TELEPATHY-PASSWORD is the only supported SASL mechanism and "
-            "is not available";
+    kDebug() << mechanisms;
+
+    if (mechanisms.contains(QLatin1String("X-TELEPATHY-PASSWORD"))) {
+        // everything ok, we can return from handleChannels now
+        emit ready(this);
+        XTelepathyPasswordAuthOperation *authop = new XTelepathyPasswordAuthOperation(m_account, m_saslIface, qdbus_cast<bool>(props.value("CanTryAgain")));
+        connect (authop, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onAuthOperationFinished(Tp::PendingOperation*)));
+        uint status = qdbus_cast<uint>(props.value("SASLStatus"));
+        QString error = qdbus_cast<QString>(props.value("SASLError"));
+        QVariantMap errorDetails = qdbus_cast<QVariantMap>(props.value("SASLErrorDetails"));
+        authop->onSASLStatusChanged(status, error, errorDetails);
+    } else {
+        kWarning() << "X-TELEPATHY-PASSWORD is the only supported SASL mechanism and is not available:" << mechanisms;
         m_channel->requestClose();
         setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED,
-                QLatin1String("X-TELEPATHY-PASSWORD is the only supported SASL mechanism and "
-                    " is not available"));
+                QLatin1String("X-TELEPATHY-PASSWORD is the only supported SASL mechanism and is not available"));
         return;
     }
 
-    // everything ok, we can return from handleChannels now
-    emit ready(this);
-
-    connect(m_saslIface,
-            SIGNAL(SASLStatusChanged(uint,QString,QVariantMap)),
-            SLOT(onSASLStatusChanged(uint,QString,QVariantMap)));
-    uint status = qdbus_cast<uint>(props.value("SASLStatus"));
-    QString error = qdbus_cast<QString>(props.value("SASLError"));
-    QVariantMap errorDetails = qdbus_cast<QVariantMap>(props.value("SASLErrorDetails"));
-    onSASLStatusChanged(status, error, errorDetails);
-}
-
-void SaslAuthOp::onSASLStatusChanged(uint status, const QString &reason,
-        const QVariantMap &details)
-{
-    KTp::WalletInterface wallet(0);
-    if (status == Tp::SASLStatusNotStarted) {
-        kDebug() << "Requesting password";
-        promptUser (m_canTryAgain || !wallet.hasEntry(m_account, QLatin1String("lastLoginFailed")));
-    } else if (status == Tp::SASLStatusServerSucceeded) {
-        kDebug() << "Authentication handshake";
-        m_saslIface->AcceptSASL();
-    } else if (status == Tp::SASLStatusSucceeded) {
-        kDebug() << "Authentication succeeded";
-        if (wallet.hasEntry(m_account, QLatin1String("lastLoginFailed"))) {
-            wallet.removeEntry(m_account, QLatin1String("lastLoginFailed"));
-        }
-        m_channel->requestClose();
-        setFinished();
-    } else if (status == Tp::SASLStatusInProgress) {
-        kDebug() << "Authenticating...";
-    } else if (status == Tp::SASLStatusServerFailed) {
-        kDebug() << "Error authenticating - reason:" << reason << "- details:" << details;
-
-        if (m_canTryAgain) {
-            kDebug() << "Retrying...";
-            promptUser(false);
-        } else {
-            kWarning() << "Authentication failed and cannot try again";
-            wallet.setEntry(m_account, QLatin1String("lastLoginFailed"), QLatin1String("true"));
-            // We cannot try again, but we can request again to set the account
-            // online. A new channel will be created, but since we set the
-            // lastLoginFailed entry, next time we will prompt for password
-            // and the user won't see any difference except for an
-            // authentication error notification
-            Tp::Presence requestedPresence = m_account->requestedPresence();
-            m_channel->requestClose();
-            QString errorMessage = details[QLatin1String("server-message")].toString();
-            m_account->setRequestedPresence(requestedPresence);
-
-            setFinishedWithError(reason, errorMessage.isEmpty() ? i18n("Authentication error") : errorMessage);
-        }
-    }
 }
 
-void SaslAuthOp::promptUser(bool isFirstRun)
+void SaslAuthOp::onAuthOperationFinished(Tp::PendingOperation *op)
 {
-    QString password;
-
-    kDebug() << "Trying to load from wallet";
-    KTp::WalletInterface wallet(0);
-    if (wallet.hasPassword(m_account) && isFirstRun) {
-        password = wallet.password(m_account);
+    m_channel->requestClose();
+    if(op->isError()) {
+        setFinishedWithError(op->errorName(), op->errorMessage());
     } else {
-        QWeakPointer<PasswordPrompt> dialog = new PasswordPrompt(m_account);
-        if (dialog.data()->exec() == QDialog::Rejected) {
-            kDebug() << "Authentication cancelled";
-            m_saslIface->AbortSASL(Tp::SASLAbortReasonUserAbort, "User cancelled auth");
-            m_channel->requestClose();
-            setFinished();
-            if (!dialog.isNull()) {
-                dialog.data()->deleteLater();
-            }
-            return;
-        }
-        password = dialog.data()->password();
-        // save password in kwallet if necessary...
-        if (dialog.data()->savePassword()) {
-            kDebug() << "Saving password in wallet";
-            wallet.setPassword(m_account, dialog.data()->password());
-        }
-
-        if (!dialog.isNull()) {
-            dialog.data()->deleteLater();
-        }
+        setFinished();
     }
-
-    m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"), password.toUtf8());
 }
 
 #include "sasl-auth-op.moc"
diff --git a/sasl-auth-op.h b/sasl-auth-op.h
index 4356904..aed300d 100644
--- a/sasl-auth-op.h
+++ b/sasl-auth-op.h
@@ -18,8 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef SASLAUTHOP_H
-#define SASLAUTHOP_H
+#ifndef SASL_AUTH_OP_H
+#define SASL_AUTH_OP_H
 
 #include <TelepathyQt/Account>
 #include <TelepathyQt/Channel>
@@ -41,15 +41,12 @@ Q_SIGNALS:
 
 private Q_SLOTS:
     void gotProperties(Tp::PendingOperation *op);
-    void onSASLStatusChanged(uint status, const QString &reason, const QVariantMap &details);
+    void onAuthOperationFinished(Tp::PendingOperation *op);
 
 private:
-    void promptUser(bool isFirstPrompt);
-
     Tp::AccountPtr m_account;
     Tp::ChannelPtr m_channel;
     Tp::Client::ChannelInterfaceSASLAuthenticationInterface *m_saslIface;
-    bool m_canTryAgain;
 };
 
-#endif
+#endif // SASL_AUTH_OP_H
diff --git a/sasl-auth-op.cpp b/x-telepathy-password-auth-operation.cpp
similarity index 66%
copy from sasl-auth-op.cpp
copy to x-telepathy-password-auth-operation.cpp
index 99df66d..b56a900 100644
--- a/sasl-auth-op.cpp
+++ b/x-telepathy-password-auth-operation.cpp
@@ -2,6 +2,7 @@
  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
  *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
  * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ * Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,70 +19,33 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "sasl-auth-op.h"
-
-#include <TelepathyQt/PendingVariantMap>
+#include "x-telepathy-password-auth-operation.h"
+#include "password-prompt.h"
 
 #include <KDebug>
 #include <KLocalizedString>
 
-#include "password-prompt.h"
-
 #include <KTp/wallet-interface.h>
 
-SaslAuthOp::SaslAuthOp(const Tp::AccountPtr &account,
-        const Tp::ChannelPtr &channel)
-    : Tp::PendingOperation(channel),
-      m_account(account),
-      m_channel(channel),
-      m_saslIface(channel->interface<Tp::Client::ChannelInterfaceSASLAuthenticationInterface>()),
-      m_canTryAgain(false)
+XTelepathyPasswordAuthOperation::XTelepathyPasswordAuthOperation(
+        const Tp::AccountPtr &account,
+        Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface,
+        bool canTryAgain) :
+    Tp::PendingOperation(account),
+    m_account(account),
+    m_saslIface(saslIface),
+    m_canTryAgain(canTryAgain)
 {
-    connect(m_saslIface->requestAllProperties(),
-            SIGNAL(finished(Tp::PendingOperation*)),
-            SLOT(gotProperties(Tp::PendingOperation*)));
-}
-
-SaslAuthOp::~SaslAuthOp()
-{
-}
-
-void SaslAuthOp::gotProperties(Tp::PendingOperation *op)
-{
-    if (op->isError()) {
-        kWarning() << "Unable to retrieve available SASL mechanisms";
-        m_channel->requestClose();
-        setFinishedWithError(op->errorName(), op->errorMessage());
-        return;
-    }
-
-    Tp::PendingVariantMap *pvm = qobject_cast<Tp::PendingVariantMap*>(op);
-    QVariantMap props = qdbus_cast<QVariantMap>(pvm->result());
-    m_canTryAgain = qdbus_cast<bool>(props.value("CanTryAgain"));
-    QStringList mechanisms = qdbus_cast<QStringList>(props.value("AvailableMechanisms"));
-    if (!mechanisms.contains(QLatin1String("X-TELEPATHY-PASSWORD"))) {
-        kWarning() << "X-TELEPATHY-PASSWORD is the only supported SASL mechanism and "
-            "is not available";
-        m_channel->requestClose();
-        setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED,
-                QLatin1String("X-TELEPATHY-PASSWORD is the only supported SASL mechanism and "
-                    " is not available"));
-        return;
-    }
-
-    // everything ok, we can return from handleChannels now
-    emit ready(this);
-
     connect(m_saslIface,
             SIGNAL(SASLStatusChanged(uint,QString,QVariantMap)),
             SLOT(onSASLStatusChanged(uint,QString,QVariantMap)));
-    uint status = qdbus_cast<uint>(props.value("SASLStatus"));
-    QString error = qdbus_cast<QString>(props.value("SASLError"));
-    QVariantMap errorDetails = qdbus_cast<QVariantMap>(props.value("SASLErrorDetails"));
-    onSASLStatusChanged(status, error, errorDetails);
 }
 
-void SaslAuthOp::onSASLStatusChanged(uint status, const QString &reason,
+XTelepathyPasswordAuthOperation::~XTelepathyPasswordAuthOperation()
+{
+}
+
+void XTelepathyPasswordAuthOperation::onSASLStatusChanged(uint status, const QString &reason,
         const QVariantMap &details)
 {
     KTp::WalletInterface wallet(0);
@@ -96,7 +60,6 @@ void SaslAuthOp::onSASLStatusChanged(uint status, const QString &reason,
         if (wallet.hasEntry(m_account, QLatin1String("lastLoginFailed"))) {
             wallet.removeEntry(m_account, QLatin1String("lastLoginFailed"));
         }
-        m_channel->requestClose();
         setFinished();
     } else if (status == Tp::SASLStatusInProgress) {
         kDebug() << "Authenticating...";
@@ -115,16 +78,14 @@ void SaslAuthOp::onSASLStatusChanged(uint status, const QString &reason,
             // and the user won't see any difference except for an
             // authentication error notification
             Tp::Presence requestedPresence = m_account->requestedPresence();
-            m_channel->requestClose();
-            QString errorMessage = details[QLatin1String("server-message")].toString();
             m_account->setRequestedPresence(requestedPresence);
-
+            QString errorMessage = details[QLatin1String("server-message")].toString();
             setFinishedWithError(reason, errorMessage.isEmpty() ? i18n("Authentication error") : errorMessage);
         }
     }
 }
 
-void SaslAuthOp::promptUser(bool isFirstRun)
+void XTelepathyPasswordAuthOperation::promptUser(bool isFirstRun)
 {
     QString password;
 
@@ -137,7 +98,6 @@ void SaslAuthOp::promptUser(bool isFirstRun)
         if (dialog.data()->exec() == QDialog::Rejected) {
             kDebug() << "Authentication cancelled";
             m_saslIface->AbortSASL(Tp::SASLAbortReasonUserAbort, "User cancelled auth");
-            m_channel->requestClose();
             setFinished();
             if (!dialog.isNull()) {
                 dialog.data()->deleteLater();
@@ -158,5 +118,3 @@ void SaslAuthOp::promptUser(bool isFirstRun)
 
     m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"), password.toUtf8());
 }
-
-#include "sasl-auth-op.moc"
diff --git a/sasl-auth-op.h b/x-telepathy-password-auth-operation.h
similarity index 64%
copy from sasl-auth-op.h
copy to x-telepathy-password-auth-operation.h
index 4356904..29dddfc 100644
--- a/sasl-auth-op.h
+++ b/x-telepathy-password-auth-operation.h
@@ -1,7 +1,5 @@
 /*
- * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
- *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
- * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ * Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,38 +16,37 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef SASLAUTHOP_H
-#define SASLAUTHOP_H
+#ifndef X_TELEPATHY_PASSWORD_AUTH_OPERATION_H
+#define X_TELEPATHY_PASSWORD_AUTH_OPERATION_H
 
-#include <TelepathyQt/Account>
-#include <TelepathyQt/Channel>
-#include <TelepathyQt/Connection>
 #include <TelepathyQt/PendingOperation>
+#include <TelepathyQt/Channel>
 #include <TelepathyQt/Types>
 
-class SaslAuthOp : public Tp::PendingOperation
+class XTelepathyPasswordAuthOperation : public Tp::PendingOperation
 {
     Q_OBJECT
+    Q_DISABLE_COPY(XTelepathyPasswordAuthOperation)
 
 public:
-    SaslAuthOp(const Tp::AccountPtr &account,
-            const Tp::ChannelPtr &channel);
-    ~SaslAuthOp();
-
-Q_SIGNALS:
-    void ready(Tp::PendingOperation *self);
+    explicit XTelepathyPasswordAuthOperation(
+            const Tp::AccountPtr &account,
+            Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface,
+            bool canTryAgain);
+    ~XTelepathyPasswordAuthOperation();
 
-private Q_SLOTS:
-    void gotProperties(Tp::PendingOperation *op);
+protected Q_SLOTS:
     void onSASLStatusChanged(uint status, const QString &reason, const QVariantMap &details);
 
 private:
     void promptUser(bool isFirstPrompt);
 
     Tp::AccountPtr m_account;
-    Tp::ChannelPtr m_channel;
     Tp::Client::ChannelInterfaceSASLAuthenticationInterface *m_saslIface;
     bool m_canTryAgain;
+
+    friend class SaslAuthOp;
 };
 
-#endif
+
+#endif // X_TELEPATHY_PASSWORD_AUTH_OPERATION_H

-- 
ktp-auth-handler packaging



More information about the pkg-kde-commits mailing list