Cutelyst  2.13.0
authentication.h
1 /*
2  * Copyright (C) 2013-2017 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 Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef AUTHENTICATION_H
19 #define AUTHENTICATION_H
20 
21 #include <Cutelyst/cutelyst_global.h>
22 #include <Cutelyst/plugin.h>
23 #include <Cutelyst/paramsmultimap.h>
24 #include <Cutelyst/Plugins/Authentication/authenticationuser.h>
25 
26 namespace Cutelyst {
27 
28 class Context;
29 class AuthenticationStore;
30 class AuthenticationRealm;
31 class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT AuthenticationCredential : public QObject
32 {
33  Q_OBJECT
34 public:
38  explicit AuthenticationCredential(QObject *parent = nullptr);
39  virtual ~AuthenticationCredential();
40 
45  virtual AuthenticationUser authenticate(Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo) = 0;
46 };
47 
48 class AuthenticationPrivate;
49 class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT Authentication : public Plugin
50 {
51  Q_OBJECT
52  Q_DECLARE_PRIVATE(Authentication)
53 public:
55  static char *defaultRealm;
56 
60  Authentication(Application *parent);
61  virtual ~Authentication() override;
62 
67  void addRealm(AuthenticationRealm *realm);
68 
73  void addRealm(AuthenticationStore *store, AuthenticationCredential *credential, const QString &name = QLatin1String(defaultRealm));
74 
78  AuthenticationRealm *realm(const QString &name = QLatin1String(defaultRealm)) const;
79 
83  static bool authenticate(Context *c, const ParamsMultiMap &userinfo, const QString &realm = QLatin1String(defaultRealm));
84 
88  inline static bool authenticate(Context *c, const QString &realm = QLatin1String(defaultRealm));
89 
93  static AuthenticationUser findUser(Context *c, const ParamsMultiMap &userinfo, const QString &realm = QLatin1String(defaultRealm));
94 
99  static AuthenticationUser user(Context *c);
100 
109  static bool userExists(Context *c);
110 
115  static bool userInRealm(Context *c, const QString &realmName = QLatin1String(defaultRealm));
116 
121  static void logout(Context *c);
122 
123 protected:
124  virtual bool setup(Application *app) override;
125 
126  AuthenticationPrivate *d_ptr;
127 };
128 
129 inline bool Authentication::authenticate(Context *c, const QString &realm) {
131 }
132 
133 }
134 
135 #endif // AUTHENTICATION_H
Cutelyst::Authentication::authenticate
static bool authenticate(Context *c, const ParamsMultiMap &userinfo, const QString &realm=QLatin1String(defaultRealm))
Definition: authentication.cpp:74
Cutelyst::Plugin
Definition: plugin.h:30
Cutelyst::ParamsMultiMap
QMap< QString, QString > ParamsMultiMap
Definition: paramsmultimap.h:36
Cutelyst::Application
The Cutelyst Application.
Definition: application.h:55
Cutelyst::AuthenticationCredential
Definition: authentication.h:31
Cutelyst::Context
The Cutelyst Context.
Definition: context.h:50
Cutelyst::AuthenticationUser
Definition: authenticationuser.h:31
Cutelyst::Authentication::realm
AuthenticationRealm * realm(const QString &name=QLatin1String(defaultRealm)) const
Returns an AuthenticationRealm object that was registered with name.
Definition: authentication.cpp:68
Cutelyst::Authentication::defaultRealm
static char * defaultRealm
default realm name
Definition: authentication.h:55
Cutelyst::AuthenticationStore
Definition: authenticationstore.h:26
Cutelyst::AuthenticationRealm
Definition: authenticationrealm.h:30
Cutelyst::Authentication
Definition: authentication.h:49
Cutelyst
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7