[Pkg-owncloud-commits] [owncloud-client] 02/30: Try to handle auth requests by a Shibboleth IdP

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Mar 15 21:28:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 33ae2eb19f7609ff29e034f671174aa426a7c67f
Author: Daniel Molkentin <danimo at owncloud.com>
Date:   Thu Feb 27 13:18:42 2014 +0100

    Try to handle auth requests by a Shibboleth IdP
---
 src/CMakeLists.txt                            |  2 +
 src/creds/shibboleth/authenticationdialog.cpp | 54 +++++++++++++++++++++++++++
 src/creds/shibboleth/authenticationdialog.h   | 41 ++++++++++++++++++++
 src/creds/shibboleth/shibbolethwebview.cpp    | 22 +++++++++++
 src/creds/shibboleth/shibbolethwebview.h      |  1 +
 5 files changed, 120 insertions(+)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f9eea20..59c482f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -94,6 +94,7 @@ set(libsync_SRCS
     creds/shibboleth/shibbolethwebview.cpp
     creds/shibboleth/shibbolethrefresher.cpp
     creds/shibboleth/shibbolethconfigfile.cpp
+    creds/shibboleth/authenticationdialog.cpp
     creds/credentialscommon.cpp
     3rdparty/qjson/json.cpp
 )
@@ -127,6 +128,7 @@ set(libsync_HEADERS
     creds/shibboleth/shibbolethwebview.h
     creds/shibboleth/shibbolethrefresher.h
     creds/shibboleth/shibbolethconfigfile.h
+    creds/shibboleth/authenticationdialog.h
     creds/credentialscommon.h
     3rdparty/qjson/json.h
 )
diff --git a/src/creds/shibboleth/authenticationdialog.cpp b/src/creds/shibboleth/authenticationdialog.cpp
new file mode 100644
index 0000000..5ad84e3
--- /dev/null
+++ b/src/creds/shibboleth/authenticationdialog.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2014 by Daniel Molkentin <danimo at owncloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "authenticationdialog.h"
+
+#include <QLabel>
+#include <QLineEdit>
+#include <QVBoxLayout>
+#include <QFormLayout>
+#include <QDialogButtonBox>
+
+namespace Mirall {
+
+AuthenticationDialog::AuthenticationDialog(const QString &realm, const QString &domain, QWidget *parent)
+    : QDialog(parent)
+    , _user(new QLineEdit)
+    , _password(new QLineEdit)
+{
+    setWindowTitle(tr("Authentication Required"));
+    QVBoxLayout *lay = new QVBoxLayout(this);
+    QLabel *label = new QLabel(tr("Enter username and password for '%1' at %2.").arg(realm, domain));
+    lay->addWidget(label);
+
+    QFormLayout *form = new QFormLayout;
+    form->addRow(tr("&User:"), _user);
+    form->addRow(tr("&Password:"), _password);
+    lay->addLayout(form);
+    QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal);
+    connect(box, SIGNAL(accepted()), this, SLOT(accept()));
+    connect(box, SIGNAL(rejected()), this, SLOT(reject()));
+    lay->addWidget(box);
+}
+
+QString AuthenticationDialog::user() const
+{
+    return _user->text();
+}
+
+QString AuthenticationDialog::password() const
+{
+    return _password->text();
+}
+
+} // namespace Mirall
diff --git a/src/creds/shibboleth/authenticationdialog.h b/src/creds/shibboleth/authenticationdialog.h
new file mode 100644
index 0000000..adcd5ca
--- /dev/null
+++ b/src/creds/shibboleth/authenticationdialog.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 by Daniel Molkentin <danimo at owncloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef MIRALL_AUTHENTICATIONDIALOG_H
+#define MIRALL_AUTHENTICATIONDIALOG_H
+
+#include <QDialog>
+
+class QLineEdit;
+
+namespace Mirall {
+
+/** @brief Authenticate a user for a specific credential given his credentials */
+class AuthenticationDialog : public QDialog {
+    Q_OBJECT
+public:
+    AuthenticationDialog(const QString &realm, const QString &domain, QWidget *parent = 0);
+
+    QString user() const;
+    QString password() const;
+
+private:
+    QLineEdit *_user;
+    QLineEdit *_password;
+
+};
+
+
+} // namespace Mirall
+
+#endif // MIRALL_AUTHENTICATIONDIALOG_H
diff --git a/src/creds/shibboleth/shibbolethwebview.cpp b/src/creds/shibboleth/shibbolethwebview.cpp
index 825c1a5..8991dcb 100644
--- a/src/creds/shibboleth/shibbolethwebview.cpp
+++ b/src/creds/shibboleth/shibbolethwebview.cpp
@@ -17,9 +17,12 @@
 #include <QWebFrame>
 #include <QWebPage>
 #include <QMessageBox>
+#include <QAuthenticator>
+#include <QNetworkReply>
 
 #include "creds/shibboleth/shibbolethcookiejar.h"
 #include "creds/shibboleth/shibbolethwebview.h"
+#include "creds/shibboleth/authenticationdialog.h"
 #include "mirall/account.h"
 #include "mirall/mirallaccessmanager.h"
 #include "mirall/theme.h"
@@ -35,6 +38,8 @@ void ShibbolethWebView::setup(Account *account, ShibbolethCookieJar* jar)
     // the account object, which already can do this
     connect(nm, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
             account, SLOT(slotHandleErrors(QNetworkReply*,QList<QSslError>)));
+    connect(nm, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+            SLOT(slotHandleAuthentication(QNetworkReply*,QAuthenticator*)));
 
     QWebPage* page = new QWebPage(this);
 
@@ -122,4 +127,21 @@ void ShibbolethWebView::slotLoadFinished(bool success)
     }
 }
 
+void ShibbolethWebView::slotHandleAuthentication(QNetworkReply *reply, QAuthenticator *authenticator)
+{
+    Q_UNUSED(reply)
+    QUrl url = reply->url();
+    // show only scheme, host and port
+    QUrl reducedUrl;
+    reducedUrl.setScheme(url.scheme());
+    reducedUrl.setHost(url.host());
+    reducedUrl.setPort(url.port());
+
+    AuthenticationDialog dialog(authenticator->realm(), reducedUrl.toString(), this);
+    if (dialog.exec() == QDialog::Accepted) {
+        authenticator->setUser(dialog.user());
+        authenticator->setPassword(dialog.password());
+    }
+}
+
 } // ns Mirall
diff --git a/src/creds/shibboleth/shibbolethwebview.h b/src/creds/shibboleth/shibbolethwebview.h
index 53a5b03..9624fed 100644
--- a/src/creds/shibboleth/shibbolethwebview.h
+++ b/src/creds/shibboleth/shibbolethwebview.h
@@ -48,6 +48,7 @@ private Q_SLOTS:
   void onNewCookiesForUrl(const QList<QNetworkCookie>& cookieList, const QUrl& url);
   void slotLoadStarted();
   void slotLoadFinished(bool success = true);
+  void slotHandleAuthentication(QNetworkReply*,QAuthenticator*);
 
 private:
   void setup(Account *account, ShibbolethCookieJar* jar);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list