MythTV  master
mythsession.h
Go to the documentation of this file.
1 #ifndef _MYTHSESSION_H_
2 #define _MYTHSESSION_H_
3 
4 #include "mythbaseexp.h"
5 
6 #include <QString>
7 #include <QDateTime>
8 #include <QMap>
9 
14 };
15 
17 {
18  public :
19  MythUserSession() = default;
20  ~MythUserSession() { m_sessionToken.fill('0'); m_sessionToken.clear(); }
21 
33  bool IsValid(void) const;
34 
35  const QString GetUserName(void) const { return m_name; }
36  uint GetUserId(void) const { return m_userId; }
37 
38  const QString GetSessionToken(void) const { return m_sessionToken; }
39  const QString GetSessionClient(void) const { return m_sessionClient; }
40 
41  const QDateTime GetSessionCreated() const { return m_sessionCreated; }
42  const QDateTime GetSessionLastActive() const { return m_sessionLastActive; }
43  const QDateTime GetSessionExpires() const { return m_sessionExpires; }
44 
53  bool CheckPermission( const QString &context, uint permission);
54 
55  protected:
63  bool Save(void);
64 
68  bool Update(void);
69 
70  uint m_userId {0};
71  QString m_name;
72 
73  QString m_sessionToken;
74  QDateTime m_sessionCreated;
75  QDateTime m_sessionLastActive; // For informational purposes
76  QDateTime m_sessionExpires;
77  QString m_sessionClient;
78 
79  QMap<QString, uint> m_permissionsList; // Context, flags
80 
81  friend class MythSessionManager;
82 };
83 
99 {
100  public :
102  ~MythSessionManager() = default;
103 
109  bool IsValidUser(const QString &username);
110 
115  bool IsValidSession(const QString &sessionToken);
116 
123  MythUserSession GetSession(const QString &sessionToken);
124 
131  QString GetPasswordDigest(const QString &username);
132 
141  MythUserSession LoginUser(const QString &username,
142  const QByteArray &digest,
143  const QString &client = "");
144 
153  MythUserSession LoginUser(const QString &username,
154  const QString &password,
155  const QString &client = "");
156 
162  static QByteArray CreateDigest(const QString &username,
163  const QString &password);
164 
173  bool ManageDigestUser(DigestUserActions action,
174  const QString &username,
175  const QString &password,
176  const QString &newPassword,
177  const QString &adminPassword);
178 
179  private:
183  void LoadSessions(void);
184 
188  void UpdateSession(const QString &sessionToken);
189 
197  MythUserSession GetSession(const QString &username, const QString &client);
198 
202  MythUserSession CreateUserSession(uint userId, const QString &username,
203  const QString &client);
204 
208  void DestroyUserSession(const QString &sessionToken);
209 
210  bool AddDigestUser(const QString &username,
211  const QString &password,
212  const QString &adminPassword);
213 
214  bool RemoveDigestUser(const QString &username,
215  const QString &password);
216 
217  bool ChangeDigestUserPassword(const QString &username,
218  const QString &oldPassword,
219  const QString &newPassword);
220 
221  QMap<QString, MythUserSession> m_sessionList;
222 };
223 
224 #endif
QDateTime m_sessionLastActive
Definition: mythsession.h:75
QString m_sessionClient
Definition: mythsession.h:77
unsigned int uint
Definition: compat.h:140
const QString GetSessionClient(void) const
Definition: mythsession.h:39
QMap< QString, uint > m_permissionsList
Definition: mythsession.h:79
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
We use digest authentication because it protects the password over unprotected networks.
Definition: mythsession.h:98
const QDateTime GetSessionCreated() const
Definition: mythsession.h:41
const QString GetSessionToken(void) const
Definition: mythsession.h:38
uint GetUserId(void) const
Definition: mythsession.h:36
const QDateTime GetSessionLastActive() const
Definition: mythsession.h:42
QString m_name
Definition: mythsession.h:71
const QDateTime GetSessionExpires() const
Definition: mythsession.h:43
QDateTime m_sessionCreated
Definition: mythsession.h:74
DigestUserActions
Definition: mythsession.h:10
QString m_sessionToken
Definition: mythsession.h:73
QMap< QString, MythUserSession > m_sessionList
Definition: mythsession.h:221
const QString GetUserName(void) const
Definition: mythsession.h:35
QDateTime m_sessionExpires
Definition: mythsession.h:76