mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 22:46:04 +03:00
Add Shibboleth credentials implementation.
This commit is contained in:
parent
92af3ea725
commit
367bc401ee
19 changed files with 809 additions and 18 deletions
|
@ -62,7 +62,7 @@ endif()
|
|||
####
|
||||
|
||||
#### find libs
|
||||
find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui QtXml QtNetwork QtTest REQUIRED )
|
||||
find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui QtXml QtNetwork QtTest QtWebkit REQUIRED )
|
||||
if( UNIX AND NOT APPLE ) # Fdo notifications
|
||||
find_package(Qt4 4.7.0 COMPONENTS QtDBus REQUIRED )
|
||||
endif()
|
||||
|
|
|
@ -26,6 +26,7 @@ mirall/fileitemdialog.ui
|
|||
mirall/owncloudsetupnocredspage.ui
|
||||
mirall/owncloudhttpcredspage.ui
|
||||
mirall/owncloudwizardresultpage.ui
|
||||
mirall/owncloudshibbolethcredspage.ui
|
||||
)
|
||||
|
||||
set(3rdparty_SRC
|
||||
|
@ -82,7 +83,12 @@ set(libsync_SRCS
|
|||
mirall/creds/httpcredentials.cpp
|
||||
mirall/creds/credentialsfactory.cpp
|
||||
mirall/creds/httpconfigfile.cpp
|
||||
mirall/creds/shibbolethcredentials.cpp
|
||||
mirall/creds/shibbolethaccessmanager.cpp
|
||||
mirall/creds/shibbolethcookiejar.cpp
|
||||
mirall/creds/shibbolethwebview.cpp
|
||||
)
|
||||
|
||||
set(libsync_HEADERS
|
||||
mirall/folderman.h
|
||||
mirall/folder.h
|
||||
|
@ -100,6 +106,10 @@ set(libsync_HEADERS
|
|||
mirall/creds/httpcredentials.h
|
||||
mirall/creds/credentialsfactory.h
|
||||
mirall/creds/httpconfigfile.h
|
||||
mirall/creds/shibbolethcredentials.h
|
||||
mirall/creds/shibbolethaccessmanager.h
|
||||
mirall/creds/shibbolethcookiejar.h
|
||||
mirall/creds/shibbolethwebview.h
|
||||
)
|
||||
|
||||
IF( INOTIFY_FOUND )
|
||||
|
@ -167,6 +177,7 @@ set(mirall_SRCS
|
|||
mirall/wizard/owncloudhttpcredspage.cpp
|
||||
mirall/wizard/owncloudwizardresultpage.cpp
|
||||
mirall/wizard/owncloudwizardcommon.cpp
|
||||
mirall/wizard/owncloudshibbolethcredspage.cpp
|
||||
mirall/owncloudsetupwizard.cpp
|
||||
mirall/updatedetector.cpp
|
||||
mirall/occinfo.cpp
|
||||
|
@ -190,6 +201,7 @@ set(mirall_HEADERS
|
|||
mirall/wizard/owncloudhttpcredspage.h
|
||||
mirall/wizard/owncloudwizardresultpage.h
|
||||
mirall/wizard/owncloudwizardcommon.h
|
||||
mirall/wizard/owncloudshibbolethcredspage.h
|
||||
mirall/folderstatusmodel.h
|
||||
mirall/updatedetector.h
|
||||
mirall/sslerrordialog.h
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "mirall/creds/httpcredentials.h"
|
||||
#include "mirall/creds/dummycredentials.h"
|
||||
#include "mirall/creds/shibbolethcredentials.h"
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
@ -31,8 +32,10 @@ AbstractCredentials* create(const QString& type)
|
|||
return new HttpCredentials;
|
||||
} else if (type == "dummy") {
|
||||
return new DummyCredentials;
|
||||
} else if (type == "shibboleth") {
|
||||
return new ShibbolethCredentials;
|
||||
} else {
|
||||
// TODO: warn!
|
||||
qWarning("Unknown credentials type: %d", qPrintable(type));
|
||||
return new DummyCredentials;
|
||||
}
|
||||
}
|
||||
|
|
38
src/mirall/creds/shibbolethaccessmanager.cpp
Normal file
38
src/mirall/creds/shibbolethaccessmanager.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <QNetworkRequest>
|
||||
|
||||
#include "mirall/creds/shibbolethaccessmanager.h"
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
||||
ShibbolethAccessManager::ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent)
|
||||
: QNetworkAccessManager (parent),
|
||||
_cookie(cookie)
|
||||
{}
|
||||
|
||||
QNetworkReply* ShibbolethAccessManager::createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData)
|
||||
{
|
||||
QNetworkRequest newRequest(request);
|
||||
QList<QNetworkCookie> cookies(request.header(QNetworkRequest::CookieHeader).value< QList< QNetworkCookie > >());
|
||||
|
||||
cookies << _cookie;
|
||||
newRequest.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue (cookies));
|
||||
|
||||
return QNetworkAccessManager::createRequest (op, newRequest, outgoingData);
|
||||
}
|
||||
|
||||
} // ns Mirall
|
40
src/mirall/creds/shibbolethaccessmanager.h
Normal file
40
src/mirall/creds/shibbolethaccessmanager.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H
|
||||
#define MIRALL_WIZARD_SHIBBOLETH_ACCESS_MANAGER_H
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkCookie>
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
||||
class ShibbolethAccessManager : public QNetworkAccessManager
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ShibbolethAccessManager (const QNetworkCookie& cookie, QObject* parent = 0);
|
||||
|
||||
protected:
|
||||
QNetworkReply* createRequest (QNetworkAccessManager::Operation op, const QNetworkRequest& request, QIODevice* outgoingData = 0);
|
||||
|
||||
private:
|
||||
QNetworkCookie _cookie;
|
||||
};
|
||||
|
||||
} // ns Mirall
|
||||
|
||||
#endif
|
35
src/mirall/creds/shibbolethcookiejar.cpp
Normal file
35
src/mirall/creds/shibbolethcookiejar.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 "mirall/creds/shibbolethcookiejar.h"
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
||||
ShibbolethCookieJar::ShibbolethCookieJar (QObject* parent)
|
||||
: QNetworkCookieJar (parent)
|
||||
{}
|
||||
|
||||
bool ShibbolethCookieJar::setCookiesFromUrl (const QList<QNetworkCookie>& cookieList, const QUrl& url)
|
||||
{
|
||||
if (QNetworkCookieJar::setCookiesFromUrl (cookieList, url)) {
|
||||
Q_EMIT newCookiesForUrl (cookieList, url);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // ns Mirall
|
42
src/mirall/creds/shibbolethcookiejar.h
Normal file
42
src/mirall/creds/shibbolethcookiejar.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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_WIZARD_SHIBBOLETH_COOKIE_JAR_H
|
||||
#define MIRALL_WIZARD_SHIBBOLETH_COOKIE_JAR_H
|
||||
|
||||
#include <QNetworkCookieJar>
|
||||
#include <QList>
|
||||
|
||||
class QUrl;
|
||||
class QNetworkCookie;
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
||||
class ShibbolethCookieJar : public QNetworkCookieJar
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ShibbolethCookieJar (QObject* parent = 0);
|
||||
|
||||
virtual bool setCookiesFromUrl (const QList<QNetworkCookie>& cookieList, const QUrl& url);
|
||||
|
||||
Q_SIGNALS:
|
||||
void newCookiesForUrl (const QList<QNetworkCookie>& cookieList, const QUrl& url);
|
||||
};
|
||||
|
||||
} // ns Mirall
|
||||
|
||||
#endif
|
122
src/mirall/creds/shibbolethcredentials.cpp
Normal file
122
src/mirall/creds/shibbolethcredentials.cpp
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
||||
* Copyright (C) by Klaas Freitag <freitag@kde.org>
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 "mirall/creds/shibbolethcredentials.h"
|
||||
#include "mirall/creds/shibbolethaccessmanager.h"
|
||||
#include "mirall/creds/shibbolethwebview.h"
|
||||
#include "mirall/owncloudinfo.h"
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
||||
ShibbolethCredentials::ShibbolethCredentials()
|
||||
: _shibCookie(),
|
||||
_ready(false),
|
||||
_browser(0)
|
||||
{}
|
||||
|
||||
ShibbolethCredentials::ShibbolethCredentials(const QNetworkCookie& cookie)
|
||||
: _shibCookie(cookie),
|
||||
_ready(true),
|
||||
_browser(0)
|
||||
{}
|
||||
|
||||
void ShibbolethCredentials::prepareSyncContext (CSYNC* ctx)
|
||||
{
|
||||
QString cookiesAsString;
|
||||
// TODO: This should not be a part of this method, but we don't
|
||||
// have any way to get "session_key" module property from
|
||||
// csync. Had we have it, then we could just append shibboleth
|
||||
// cookies to the "session_key" value and set it in csync module.
|
||||
QList<QNetworkCookie> cookies(ownCloudInfo::instance()->getLastAuthCookies());
|
||||
|
||||
cookies << _shibCookie;
|
||||
// Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply
|
||||
// when https://github.com/owncloud/core/pull/4042 is merged.
|
||||
foreach(QNetworkCookie c, cookies) {
|
||||
cookiesAsString += c.name();
|
||||
cookiesAsString += '=';
|
||||
cookiesAsString += c.value();
|
||||
cookiesAsString += "; ";
|
||||
}
|
||||
|
||||
csync_set_module_property(ctx, "session_key", cookiesAsString.toLatin1().data());
|
||||
}
|
||||
|
||||
bool ShibbolethCredentials::changed(AbstractCredentials* credentials) const
|
||||
{
|
||||
ShibbolethCredentials* other(dynamic_cast< ShibbolethCredentials* >(credentials));
|
||||
|
||||
if (!other || other->cookie() != this->cookie()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QString ShibbolethCredentials::authType() const
|
||||
{
|
||||
return QString::fromLatin1("shibboleth");
|
||||
}
|
||||
|
||||
QNetworkCookie ShibbolethCredentials::cookie() const
|
||||
{
|
||||
return _shibCookie;
|
||||
}
|
||||
|
||||
QNetworkAccessManager* ShibbolethCredentials::getQNAM() const
|
||||
{
|
||||
return new ShibbolethAccessManager(_shibCookie);
|
||||
}
|
||||
|
||||
bool ShibbolethCredentials::ready() const
|
||||
{
|
||||
return _ready;
|
||||
}
|
||||
|
||||
void ShibbolethCredentials::fetch()
|
||||
{
|
||||
if (_ready) {
|
||||
Q_EMIT fetched();
|
||||
} else {
|
||||
MirallConfigFile cfg;
|
||||
|
||||
_browser = new ShibbolethWebView(QUrl(cfg.ownCloudUrl()));
|
||||
connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)),
|
||||
this, SLOT(onShibbolethCookieReceived(QNetworkCookie)));
|
||||
_browser->show ();
|
||||
}
|
||||
}
|
||||
|
||||
void ShibbolethCredentials::persistForUrl(const QString& url)
|
||||
{
|
||||
// nothing to do here, we don't store session cookies.
|
||||
}
|
||||
|
||||
void ShibbolethCredentials::onShibbolethCookieReceived(const QNetworkCookie& cookie)
|
||||
{
|
||||
_browser->hide();
|
||||
disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)),
|
||||
this, SLOT(onShibbolethCookieReceived(QNetworkCookie)));
|
||||
_browser->deleteLater();
|
||||
_browser = 0;
|
||||
_ready = true;
|
||||
_shibCookie = cookie;
|
||||
Q_EMIT fetched();
|
||||
}
|
||||
|
||||
} // ns Mirall
|
58
src/mirall/creds/shibbolethcredentials.h
Normal file
58
src/mirall/creds/shibbolethcredentials.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
||||
* Copyright (C) by Klaas Freitag <freitag@kde.org>
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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_CREDS_SHIBBOLETH_CREDENTIALS_H
|
||||
#define MIRALL_CREDS_SHIBBOLETH_CREDENTIALS_H
|
||||
|
||||
#include <QNetworkCookie>
|
||||
|
||||
#include "mirall/creds/abstractcredentials.h"
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
||||
class ShibbolethWebView;
|
||||
|
||||
class ShibbolethCredentials : public AbstractCredentials
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ShibbolethCredentials();
|
||||
ShibbolethCredentials(const QNetworkCookie& cookie);
|
||||
|
||||
void prepareSyncContext (CSYNC* ctx);
|
||||
bool changed(AbstractCredentials* credentials) const;
|
||||
QString authType() const;
|
||||
QNetworkAccessManager* getQNAM() const;
|
||||
bool ready() const;
|
||||
void fetch();
|
||||
void persistForUrl(const QString& url);
|
||||
|
||||
QNetworkCookie cookie() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onShibbolethCookieReceived(const QNetworkCookie& cookie);
|
||||
|
||||
private:
|
||||
QNetworkCookie _shibCookie;
|
||||
bool _ready;
|
||||
ShibbolethWebView* _browser;
|
||||
};
|
||||
|
||||
} // ns Mirall
|
||||
|
||||
#endif
|
50
src/mirall/creds/shibbolethwebview.cpp
Normal file
50
src/mirall/creds/shibbolethwebview.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <QNetworkCookie>
|
||||
#include <QWebFrame>
|
||||
#include <QWebPage>
|
||||
|
||||
#include "mirall/creds/shibbolethcookiejar.h"
|
||||
#include "mirall/creds/shibbolethwebview.h"
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
||||
ShibbolethWebView::ShibbolethWebView(const QUrl& url, QWidget* parent)
|
||||
: QWebView(parent)
|
||||
{
|
||||
ShibbolethCookieJar* jar = new ShibbolethCookieJar(this);
|
||||
QWebPage* page = new QWebPage(this);
|
||||
|
||||
connect (jar, SIGNAL (newCookiesForUrl (QList<QNetworkCookie>, QUrl)),
|
||||
this, SLOT (onNewCookiesForUrl (QList<QNetworkCookie>, QUrl)));
|
||||
|
||||
page->networkAccessManager()->setCookieJar(jar);
|
||||
page->mainFrame ()->load (url);
|
||||
this->setPage (page);
|
||||
}
|
||||
|
||||
void ShibbolethWebView::onNewCookiesForUrl (const QList<QNetworkCookie>& cookieList, const QUrl& url)
|
||||
{
|
||||
Q_FOREACH (const QNetworkCookie& cookie, cookieList) {
|
||||
if (cookie.name().startsWith ("_shibsession_")) {
|
||||
Q_EMIT shibbolethCookieReceived (cookie);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // ns Mirall
|
43
src/mirall/creds/shibbolethwebview.h
Normal file
43
src/mirall/creds/shibbolethwebview.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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_WIZARD_SHIBBOLETH_WEB_VIEW_H
|
||||
#define MIRALL_WIZARD_SHIBBOLETH_WEB_VIEW_H
|
||||
|
||||
#include <QList>
|
||||
#include <QWebView>
|
||||
|
||||
class QNetworkCookie;
|
||||
class QUrl;
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
||||
class ShibbolethWebView : public QWebView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ShibbolethWebView(const QUrl& url, QWidget* parent = 0);
|
||||
|
||||
Q_SIGNALS:
|
||||
void shibbolethCookieReceived (const QNetworkCookie& cookie);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onNewCookiesForUrl (const QList<QNetworkCookie>& cookieList, const QUrl& url);
|
||||
};
|
||||
|
||||
} // ns Mirall
|
||||
|
||||
#endif
|
|
@ -456,12 +456,6 @@ void OwncloudSetupWizard::slotDetermineAuthType(const QString& serverUrl)
|
|||
// FIXME: give a hint about the auto completion
|
||||
_ocWizard->setOCUrl(url);
|
||||
}
|
||||
// FIXME: Create AbstractUserCreds class and maybe three subclasses:
|
||||
// DummyCreds (empty), ShibbolethCreds and HttpCreds
|
||||
// writeOwnCloudConfig could then take AbstractUserCreds instead.
|
||||
// no user and no password - we are trying to determine whether
|
||||
// the auth type is the old HTTPS headers one or rather a
|
||||
// shibboleth one.
|
||||
cfgFile.writeOwncloudConfig( Theme::instance()->appName(),
|
||||
url,
|
||||
new DummyCredentials);
|
||||
|
|
121
src/mirall/owncloudshibbolethcredspage.ui
Normal file
121
src/mirall/owncloudshibbolethcredspage.ui
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OwncloudShibbolethCredsPage</class>
|
||||
<widget class="QWidget" name="OwncloudShibbolethCredsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>451</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMaximumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="topLabel">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>45</width>
|
||||
<height>17</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="contentLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="errorLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Error Label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="infoLabel">
|
||||
<property name="text">
|
||||
<string>info label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>48</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>17</width>
|
||||
<height>38</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="bottomLabel">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>horizontalSpacer</zorder>
|
||||
<zorder>verticalSpacer</zorder>
|
||||
<zorder>horizontalSpacer_2</zorder>
|
||||
<zorder>topLabel</zorder>
|
||||
<zorder>bottomLabel</zorder>
|
||||
<zorder>errorLabel_2</zorder>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -238,12 +238,11 @@ void OwncloudSetupPage::slotHandleUserInput()
|
|||
|
||||
int OwncloudSetupPage::nextId() const
|
||||
{
|
||||
if (_authType == WizardCommon::HttpCreds) {
|
||||
return WizardCommon::Page_HttpCreds;
|
||||
} else {
|
||||
// TODO: rather display some browser component. maybe different page.
|
||||
return WizardCommon::Page_Result;
|
||||
}
|
||||
if (_authType == WizardCommon::HttpCreds) {
|
||||
return WizardCommon::Page_HttpCreds;
|
||||
} else {
|
||||
return WizardCommon::Page_ShibbolethCreds;
|
||||
}
|
||||
}
|
||||
|
||||
QString OwncloudSetupPage::url() const
|
||||
|
|
154
src/mirall/wizard/owncloudshibbolethcredspage.cpp
Normal file
154
src/mirall/wizard/owncloudshibbolethcredspage.cpp
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
||||
* Copyright (C) by Klaas Freitag <freitag@kde.org>
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 "mirall/wizard/owncloudshibbolethcredspage.h"
|
||||
#include "mirall/theme.h"
|
||||
#include "mirall/wizard/owncloudwizardcommon.h"
|
||||
#include "mirall/creds/shibbolethcredentials.h"
|
||||
#include "mirall/creds/shibbolethwebview.h"
|
||||
|
||||
namespace Mirall
|
||||
{
|
||||
|
||||
OwncloudShibbolethCredsPage::OwncloudShibbolethCredsPage()
|
||||
: AbstractCredentialsWizardPage(),
|
||||
_ui(),
|
||||
_stage(INITIAL_STEP),
|
||||
_browser(0),
|
||||
_cookie()
|
||||
{
|
||||
_ui.setupUi(this);
|
||||
|
||||
setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI())));
|
||||
setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Process through Shibboleth form")));
|
||||
|
||||
setupCustomization();
|
||||
}
|
||||
|
||||
void OwncloudShibbolethCredsPage::setupCustomization()
|
||||
{
|
||||
// set defaults for the customize labels.
|
||||
_ui.topLabel->hide();
|
||||
_ui.bottomLabel->hide();
|
||||
|
||||
Theme *theme = Theme::instance();
|
||||
QVariant variant = theme->customMedia( Theme::oCSetupTop );
|
||||
if( !variant.isNull() ) {
|
||||
WizardCommon::setupCustomMedia( variant, _ui.topLabel );
|
||||
}
|
||||
|
||||
variant = theme->customMedia( Theme::oCSetupBottom );
|
||||
WizardCommon::setupCustomMedia( variant, _ui.bottomLabel );
|
||||
}
|
||||
|
||||
void OwncloudShibbolethCredsPage::initializePage()
|
||||
{
|
||||
WizardCommon::initErrorLabel(_ui.errorLabel);
|
||||
_browser = new ShibbolethWebView(QUrl(field("OCUrl").toString().simplified()), this);
|
||||
|
||||
connect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)),
|
||||
this, SLOT(onShibbolethCookieReceived(QNetworkCookie)));
|
||||
|
||||
_ui.contentLayout->insertWidget(0, _browser);
|
||||
_browser->show();
|
||||
_browser->setFocus();
|
||||
_ui.infoLabel->show();
|
||||
_ui.infoLabel->setText(tr("Please follow the steps on displayed page above"));
|
||||
_stage = INITIAL_STEP;
|
||||
_cookie = QNetworkCookie();
|
||||
}
|
||||
|
||||
void OwncloudShibbolethCredsPage::disposeBrowser(bool later)
|
||||
{
|
||||
_browser->hide();
|
||||
disconnect(_browser, SIGNAL(shibbolethCookieReceived(QNetworkCookie)),
|
||||
this, SLOT(onShibbolethCookieReceived(QNetworkCookie)));
|
||||
if (later) {
|
||||
_browser->deleteLater();
|
||||
} else {
|
||||
delete _browser;
|
||||
}
|
||||
_browser = 0;
|
||||
}
|
||||
|
||||
void OwncloudShibbolethCredsPage::cleanupPage()
|
||||
{
|
||||
disposeBrowser(false);
|
||||
}
|
||||
|
||||
bool OwncloudShibbolethCredsPage::validatePage()
|
||||
{
|
||||
switch (_stage) {
|
||||
case INITIAL_STEP:
|
||||
return false;
|
||||
|
||||
case GOT_COOKIE:
|
||||
_stage = CHECKING;
|
||||
emit completeChanged();
|
||||
emit connectToOCUrl(field("OCUrl").toString().simplified());
|
||||
return false;
|
||||
|
||||
case CHECKING:
|
||||
return false;
|
||||
|
||||
case CONNECTED:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int OwncloudShibbolethCredsPage::nextId() const
|
||||
{
|
||||
return WizardCommon::Page_Result;
|
||||
}
|
||||
|
||||
void OwncloudShibbolethCredsPage::setConnected( bool comp )
|
||||
{
|
||||
if (comp) {
|
||||
_stage = CONNECTED;
|
||||
} else {
|
||||
// sets stage to INITIAL
|
||||
initializePage();
|
||||
}
|
||||
}
|
||||
|
||||
void OwncloudShibbolethCredsPage::setErrorString(const QString& err)
|
||||
{
|
||||
if( err.isEmpty()) {
|
||||
_ui.errorLabel->setVisible(false);
|
||||
} else {
|
||||
initializePage();
|
||||
_ui.errorLabel->setVisible(true);
|
||||
_ui.errorLabel->setText(err);
|
||||
}
|
||||
emit completeChanged();
|
||||
}
|
||||
|
||||
AbstractCredentials* OwncloudShibbolethCredsPage::getCredentials() const
|
||||
{
|
||||
return new ShibbolethCredentials(_cookie);
|
||||
}
|
||||
|
||||
void OwncloudShibbolethCredsPage::onShibbolethCookieReceived(const QNetworkCookie& cookie)
|
||||
{
|
||||
disposeBrowser(true);
|
||||
_stage = GOT_COOKIE;
|
||||
_cookie = cookie;
|
||||
_ui.infoLabel->setText("Please click \"Connect\" to check received Shibboleth session.");
|
||||
}
|
||||
|
||||
} // ns Mirall
|
70
src/mirall/wizard/owncloudshibbolethcredspage.h
Normal file
70
src/mirall/wizard/owncloudshibbolethcredspage.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
|
||||
* Copyright (C) by Klaas Freitag <freitag@kde.org>
|
||||
* Copyright (C) by Krzesimir Nowak <krzesimir@endocode.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; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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_OWNCLOUD_SHIBBOLETH_CREDS_PAGE_H
|
||||
#define MIRALL_OWNCLOUD_SHIBBOLETH_CREDS_PAGE_H
|
||||
|
||||
#include <QNetworkCookie>
|
||||
|
||||
#include "mirall/wizard/abstractcredswizardpage.h"
|
||||
|
||||
#include "ui_owncloudshibbolethcredspage.h"
|
||||
|
||||
namespace Mirall {
|
||||
|
||||
class ShibbolethWebView;
|
||||
|
||||
class OwncloudShibbolethCredsPage : public AbstractCredentialsWizardPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OwncloudShibbolethCredsPage();
|
||||
|
||||
AbstractCredentials* getCredentials() const;
|
||||
|
||||
void initializePage();
|
||||
void cleanupPage();
|
||||
bool validatePage();
|
||||
int nextId() const;
|
||||
void setConnected(bool connected);
|
||||
void setErrorString(const QString& err);
|
||||
|
||||
Q_SIGNALS:
|
||||
void connectToOCUrl(const QString&);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onShibbolethCookieReceived(const QNetworkCookie& cookie);
|
||||
|
||||
private:
|
||||
enum Stage {
|
||||
INITIAL_STEP,
|
||||
GOT_COOKIE,
|
||||
CHECKING,
|
||||
CONNECTED
|
||||
};
|
||||
|
||||
void setupCustomization();
|
||||
void disposeBrowser(bool later);
|
||||
|
||||
Ui_OwncloudShibbolethCredsPage _ui;
|
||||
Stage _stage;
|
||||
ShibbolethWebView* _browser;
|
||||
QNetworkCookie _cookie;
|
||||
};
|
||||
|
||||
} // ns Mirall
|
||||
|
||||
#endif
|
|
@ -19,6 +19,7 @@
|
|||
#include "mirall/theme.h"
|
||||
#include "mirall/wizard/owncloudsetuppage.h"
|
||||
#include "mirall/wizard/owncloudhttpcredspage.h"
|
||||
#include "mirall/wizard/owncloudshibbolethcredspage.h"
|
||||
#include "mirall/wizard/owncloudwizardresultpage.h"
|
||||
|
||||
#include "QProgressIndicator.h"
|
||||
|
@ -35,6 +36,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
|
|||
: QWizard(parent),
|
||||
_setupPage(new OwncloudSetupPage),
|
||||
_httpCredsPage(new OwncloudHttpCredsPage),
|
||||
_shibbolethCredsPage(new OwncloudShibbolethCredsPage),
|
||||
_resultPage(new OwncloudWizardResultPage),
|
||||
_credentialsPage(0),
|
||||
_configFile(),
|
||||
|
@ -44,6 +46,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
|
|||
{
|
||||
setPage(WizardCommon::Page_oCSetup, _setupPage );
|
||||
setPage(WizardCommon::Page_HttpCreds, _httpCredsPage);
|
||||
setPage(WizardCommon::Page_ShibbolethCreds, _shibbolethCredsPage);
|
||||
setPage(WizardCommon::Page_Result, _resultPage );
|
||||
|
||||
// note: start Id is set by the calling class depending on if the
|
||||
|
@ -53,7 +56,7 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
|
|||
connect( this, SIGNAL(currentIdChanged(int)), SLOT(slotCurrentPageChanged(int)));
|
||||
connect( _setupPage, SIGNAL(determineAuthType(QString)), SIGNAL(determineAuthType(QString)));
|
||||
connect( _httpCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString)));
|
||||
|
||||
connect( _shibbolethCredsPage, SIGNAL(connectToOCUrl(QString)), SIGNAL(connectToOCUrl(QString)));
|
||||
|
||||
Theme *theme = Theme::instance();
|
||||
setWizardStyle(QWizard::ModernStyle);
|
||||
|
@ -119,7 +122,7 @@ void OwncloudWizard::setAuthType(WizardCommon::AuthType type)
|
|||
{
|
||||
_setupPage->setAuthType(type);
|
||||
if (type == WizardCommon::Shibboleth) {
|
||||
_credentialsPage = 0;
|
||||
_credentialsPage = _shibbolethCredsPage;
|
||||
} else {
|
||||
_credentialsPage = _httpCredsPage;
|
||||
}
|
||||
|
@ -144,10 +147,14 @@ void OwncloudWizard::slotCurrentPageChanged( int id )
|
|||
|
||||
void OwncloudWizard::displayError( const QString& msg )
|
||||
{
|
||||
if (currentId() == WizardCommon::Page_oCSetup) {
|
||||
int id(currentId());
|
||||
|
||||
if (id == WizardCommon::Page_oCSetup) {
|
||||
_setupPage->setErrorString( msg );
|
||||
} else {
|
||||
} else if (id == WizardCommon::Page_HttpCreds) {
|
||||
_httpCredsPage->setErrorString(msg);
|
||||
} else if (id == WizardCommon::Page_ShibbolethCreds) {
|
||||
_shibbolethCredsPage->setErrorString(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace Mirall {
|
|||
|
||||
class OwncloudSetupPage;
|
||||
class OwncloudHttpCredsPage;
|
||||
class OwncloudShibbolethCredsPage;
|
||||
class OwncloudWizardResultPage;
|
||||
class AbstractCredentials;
|
||||
class AbstractCredentialsWizardPage;
|
||||
|
@ -74,6 +75,7 @@ signals:
|
|||
private:
|
||||
OwncloudSetupPage* _setupPage;
|
||||
OwncloudHttpCredsPage* _httpCredsPage;
|
||||
OwncloudShibbolethCredsPage* _shibbolethCredsPage;
|
||||
OwncloudWizardResultPage* _resultPage;
|
||||
AbstractCredentialsWizardPage* _credentialsPage;
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ enum SyncMode {
|
|||
enum Pages {
|
||||
Page_oCSetup,
|
||||
Page_HttpCreds,
|
||||
Page_ShibbolethCreds,
|
||||
Page_Result
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue