mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-25 05:45:42 +03:00
Try to handle auth requests by a Shibboleth IdP
This commit is contained in:
parent
d4fa955950
commit
33ae2eb19f
5 changed files with 120 additions and 0 deletions
|
@ -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
|
||||
)
|
||||
|
|
54
src/creds/shibboleth/authenticationdialog.cpp
Normal file
54
src/creds/shibboleth/authenticationdialog.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2014 by Daniel Molkentin <danimo@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
|
41
src/creds/shibboleth/authenticationdialog.h
Normal file
41
src/creds/shibboleth/authenticationdialog.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2014 by Daniel Molkentin <danimo@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
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue