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_ABSTRACT_CREDENTIALS_H |
16 | #define MIRALL_CREDS_ABSTRACT_CREDENTIALS_H |
17 | |
18 | #include <QObject> |
19 | |
20 | #include <csync.h> |
21 | #include "owncloudlib.h" |
22 | #include "accountfwd.h" |
23 | |
24 | class QNetworkAccessManager; |
25 | class QNetworkReply; |
26 | namespace OCC { |
27 | |
28 | class OWNCLOUDSYNC_EXPORT AbstractCredentials : public QObject |
29 | { |
30 | Q_OBJECT |
31 | |
32 | public: |
33 | AbstractCredentials(); |
34 | // No need for virtual destructor - QObject already has one. |
35 | |
36 | /** The bound account for the credentials instance. |
37 | * |
38 | * Credentials are always used in conjunction with an account. |
39 | * Calling Account::setCredentials() will call this function. |
40 | * Credentials only live as long as the underlying account object. |
41 | */ |
42 | virtual void setAccount(Account *account); |
43 | |
44 | virtual QString authType() const = 0; |
45 | virtual QString user() const = 0; |
46 | virtual QNetworkAccessManager *createQNAM() const = 0; |
47 | |
48 | /** Whether there are credentials that can be used for a connection attempt. */ |
49 | virtual bool ready() const = 0; |
50 | |
51 | /** Whether fetchFromKeychain() was called before. */ |
52 | bool wasFetched() const { return _wasFetched; } |
53 | |
54 | /** Trigger (async) fetching of credential information |
55 | * |
56 | * Should set _wasFetched = true, and later emit fetched() when done. |
57 | */ |
58 | virtual void fetchFromKeychain() = 0; |
59 | |
60 | /** Ask credentials from the user (typically async) |
61 | * |
62 | * Should emit asked() when done. |
63 | */ |
64 | virtual void askFromUser() = 0; |
65 | |
66 | virtual bool stillValid(QNetworkReply *reply) = 0; |
67 | virtual void persist() = 0; |
68 | |
69 | /** Invalidates token used to authorize requests, it will no longer be used. |
70 | * |
71 | * For http auth, this would be the session cookie. |
72 | * |
73 | * Note that sensitive data (like the password used to acquire the |
74 | * session cookie) may be retained. See forgetSensitiveData(). |
75 | * |
76 | * ready() must return false afterwards. |
77 | */ |
78 | virtual void invalidateToken() = 0; |
79 | |
80 | /** Clears out all sensitive data; used for fully signing out users. |
81 | * |
82 | * This should always imply invalidateToken() but may go beyond it. |
83 | * |
84 | * For http auth, this would clear the session cookie and password. |
85 | */ |
86 | virtual void forgetSensitiveData() = 0; |
87 | |
88 | static QString keychainKey(const QString &url, const QString &user, const QString &accountId); |
89 | |
90 | Q_SIGNALS: |
91 | /** Emitted when fetchFromKeychain() is done. |
92 | * |
93 | * Note that ready() can be true or false, depending on whether there was useful |
94 | * data in the keychain. |
95 | */ |
96 | void fetched(); |
97 | |
98 | /** Emitted when askFromUser() is done. |
99 | * |
100 | * Note that ready() can be true or false, depending on whether the user provided |
101 | * data or not. |
102 | */ |
103 | void asked(); |
104 | |
105 | protected: |
106 | Account *_account; |
107 | bool _wasFetched; |
108 | }; |
109 | |
110 | } // namespace OCC |
111 | |
112 | #endif |
113 | |