1 #ifndef SEAFILE_CLIENT_SHIB_LOGIN_DIALOG_H
2 #define SEAFILE_CLIENT_SHIB_LOGIN_DIALOG_H
3 
4 #include <QDialog>
5 #include <QUrl>
6 #include <QNetworkCookieJar>
7 
8 #include "account.h"
9 
10 template<typename T> class QList;
11 
12 #if defined(SEAFILE_USE_WEBKIT)
13 class QWebView;
14 #else
15 class QWebEngineView;
16 class QWebEngineProfile;
17 class QWebEnginePage;
18 #endif
19 
20 class QSslError;
21 class QNetworkReply;
22 class QLineEdit;
23 
24 /**
25  * Login with Shibboleth SSO.
26  *
27  * This dialog use a webview to let the user login seahub configured with
28  * Shibboleth SSO auth. When the login succeeded, seahub would set the
29  * username and api token in the cookie.
30  */
31 class ShibLoginDialog : public QDialog {
32     Q_OBJECT
33 public:
34     ShibLoginDialog(const QUrl& url,
35                     const QString& computer_name,
36                     QWidget *parent=0);
37 #if !defined(SEAFILE_USE_WEBKIT)
38 ~ShibLoginDialog();
39 #endif
40 
41 private slots:
42     void sslErrorHandler(QNetworkReply* reply, const QList<QSslError> & ssl_errors);
43     void onNewCookieCreated(const QUrl& url, const QNetworkCookie& cookie);
44     void onWebEngineCookieAdded(const QNetworkCookie& cookie);
45     void updateAddressBar(const QUrl& url);
46 
47 private:
48     Account parseAccount(const QString& txt);
49 
50 #if defined(SEAFILE_USE_WEBKIT)
51     QWebView *webview_;
52 #else
53     QWebEngineView *webview_;
54     QWebEngineProfile *web_engine_profile_;
55     QWebEnginePage *web_engine_page_;
56 #endif
57     QUrl url_;
58     QLineEdit *address_text_;
59     bool cookie_seen_;
60 };
61 
62 
63 /**
64  * Wraps the standard Qt cookie jar to emit a signal when new cookies created.
65  */
66 class CustomCookieJar : public QNetworkCookieJar
67 {
68     Q_OBJECT
69 public:
70     explicit CustomCookieJar(QObject *parent = 0);
71     bool setCookiesFromUrl(const QList<QNetworkCookie>& cookies, const QUrl& url);
72 
73 signals:
74     void newCookieCreated(const QUrl& url, const QNetworkCookie& cookie);
75 };
76 
77 #endif /* SEAFILE_CLIENT_SHIB_LOGIN_DIALOG_H */
78