Cutelyst  1.5.0
authentication.h
1 /*
2  * Copyright (C) 2013-2015 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef AUTHENTICATION_H
21 #define AUTHENTICATION_H
22 
23 #include <Cutelyst/cutelyst_global.h>
24 #include <Cutelyst/plugin.h>
25 #include <Cutelyst/paramsmultimap.h>
26 #include <Cutelyst/Plugins/Authentication/authenticationuser.h>
27 
28 namespace Cutelyst {
29 
30 class Context;
31 class AuthenticationStore;
32 class AuthenticationRealm;
33 class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT AuthenticationCredential : public QObject
34 {
35  Q_OBJECT
36 public:
37  explicit AuthenticationCredential(QObject *parent = nullptr);
38  virtual ~AuthenticationCredential();
39 
40  virtual AuthenticationUser authenticate(Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo) = 0;
41 };
42 
43 class AuthenticationPrivate;
44 class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT Authentication : public Plugin
45 {
46  Q_OBJECT
47  Q_DECLARE_PRIVATE(Authentication)
48 public:
49  static char *defaultRealm;
50 
51  Authentication(Application *parent);
52  virtual ~Authentication();
53 
54  void addRealm(AuthenticationRealm *realm, const QString &name = QLatin1String(defaultRealm));
55  void addRealm(AuthenticationStore *store, AuthenticationCredential *credential, const QString &name = QLatin1String(defaultRealm));
56 
57  AuthenticationRealm *realm(const QString &name = QLatin1String(defaultRealm)) const;
58 
62  static bool authenticate(Context *c, const ParamsMultiMap &userinfo, const QString &realm = QLatin1String(defaultRealm));
63 
67  inline static bool authenticate(Context *c, const QString &realm = QLatin1String(defaultRealm));
68 
69  static AuthenticationUser findUser(Context *c, const ParamsMultiMap &userinfo, const QString &realm = QLatin1String(defaultRealm));
70 
75  static AuthenticationUser user(Context *c);
76 
85  static bool userExists(Context *c);
86 
91  static bool userInRealm(Context *c, const QString &realmName = QLatin1String(defaultRealm));
92 
97  static void logout(Context *c);
98 
99 protected:
100  AuthenticationPrivate *d_ptr;
101 };
102 
103 inline bool Authentication::authenticate(Context *c, const QString &realm) {
104  return Authentication::authenticate(c, ParamsMultiMap(), realm);
105 }
106 
107 }
108 
109 #endif // AUTHENTICATION_H
QMap< QString, QString > ParamsMultiMap
The Cutelyst Context.
Definition: context.h:52
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
static bool authenticate(Context *c, const ParamsMultiMap &userinfo, const QString &realm=QLatin1String(defaultRealm))
The Cutelyst Application.
Definition: application.h:55