1/*
2 * Copyright (C) by Krzesimir Nowak <krzesimir@endocode.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15#ifndef MIRALL_CREDS_SHIBBOLETH_CREDENTIALS_H
16#define MIRALL_CREDS_SHIBBOLETH_CREDENTIALS_H
17
18#include <QList>
19#include <QLoggingCategory>
20#include <QMap>
21#include <QNetworkCookie>
22#include <QUrl>
23#include <QPointer>
24
25#include "creds/abstractcredentials.h"
26
27namespace QKeychain {
28class Job;
29}
30
31class QAuthenticator;
32
33namespace OCC {
34
35Q_DECLARE_LOGGING_CATEGORY(lcShibboleth)
36
37class ShibbolethWebView;
38
39/**
40 * @brief The ShibbolethCredentials class
41 * @ingroup gui
42 */
43class ShibbolethCredentials : public AbstractCredentials
44{
45 Q_OBJECT
46
47public:
48 ShibbolethCredentials();
49
50 /* create credentials for an already connected account */
51 ShibbolethCredentials(const QNetworkCookie &cookie);
52
53 void setAccount(Account *account) Q_DECL_OVERRIDE;
54 QString authType() const Q_DECL_OVERRIDE;
55 QString user() const Q_DECL_OVERRIDE;
56 QNetworkAccessManager *createQNAM() const Q_DECL_OVERRIDE;
57 bool ready() const Q_DECL_OVERRIDE;
58 void fetchFromKeychain() Q_DECL_OVERRIDE;
59 void askFromUser() Q_DECL_OVERRIDE;
60 bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE;
61 void persist() Q_DECL_OVERRIDE;
62 void invalidateToken() Q_DECL_OVERRIDE;
63 void forgetSensitiveData() Q_DECL_OVERRIDE;
64
65 void showLoginWindow();
66
67 static QList<QNetworkCookie> accountCookies(Account *);
68 static QNetworkCookie findShibCookie(Account *, QList<QNetworkCookie> cookies = QList<QNetworkCookie>());
69 static QByteArray shibCookieName();
70
71private Q_SLOTS:
72 void onShibbolethCookieReceived(const QNetworkCookie &);
73 void slotBrowserRejected();
74 void slotReadJobDone(QKeychain::Job *);
75 void slotReplyFinished(QNetworkReply *);
76 void slotUserFetched(const QString &user);
77 void slotFetchUser();
78 void slotFetchUserHelper();
79
80Q_SIGNALS:
81 void newCookie(const QNetworkCookie &cookie);
82
83private:
84 void storeShibCookie(const QNetworkCookie &cookie);
85 void removeShibCookie();
86 void addToCookieJar(const QNetworkCookie &cookie);
87
88 /// Reads data from keychain, progressing to slotReadJobDone
89 void fetchFromKeychainHelper();
90
91 QUrl _url;
92 QByteArray prepareCookieData() const;
93
94 bool _ready;
95 bool _stillValid;
96 QPointer<ShibbolethWebView> _browser;
97 QNetworkCookie _shibCookie;
98 QString _user;
99 bool _keychainMigration;
100};
101
102} // namespace OCC
103
104#endif
105