cutelyst  4.4.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
authentication.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2013-2022 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef AUTHENTICATION_H
6 #define AUTHENTICATION_H
7 
8 #include <Cutelyst/Plugins/Authentication/authenticationuser.h>
9 #include <Cutelyst/Plugins/authentication_export.h>
10 #include <Cutelyst/paramsmultimap.h>
11 #include <Cutelyst/plugin.h>
12 
13 namespace Cutelyst {
14 
15 class Context;
16 class AuthenticationStore;
17 class AuthenticationRealm;
18 
33 class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT AuthenticationCredential : public QObject
34 {
35  Q_OBJECT
36 public:
40  explicit AuthenticationCredential(QObject *parent = nullptr);
41 
45  virtual ~AuthenticationCredential();
46 
54  virtual AuthenticationUser
55  authenticate(Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo) = 0;
56 };
57 
58 class AuthenticationPrivate;
59 
75 class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT Authentication : public Plugin
76 {
77  Q_OBJECT
78  Q_DECLARE_PRIVATE(Authentication)
79 public:
83  static char *defaultRealm;
84 
88  Authentication(Application *parent);
89 
93  virtual ~Authentication() override;
94 
98  void addRealm(std::shared_ptr<AuthenticationRealm> realm);
99 
103  void addRealm(std::shared_ptr<AuthenticationStore> store,
104  std::shared_ptr<AuthenticationCredential> credential,
105  const QString &name = QLatin1String(defaultRealm));
106 
110  [[nodiscard]] std::shared_ptr<AuthenticationRealm>
111  realm(const QString &name = QLatin1String(defaultRealm)) const;
112 
116  [[nodiscard]] static bool authenticate(Context *c,
117  const ParamsMultiMap &userinfo,
118  const QString &realm = QLatin1String(defaultRealm));
119 
123  [[nodiscard]] inline static bool
124  authenticate(Context *c, const QString &realm = QLatin1String(defaultRealm));
125 
130  [[nodiscard]] static AuthenticationUser
131  findUser(Context *c,
132  const ParamsMultiMap &userinfo,
133  const QString &realm = QLatin1String(defaultRealm));
134 
139  [[nodiscard]] static AuthenticationUser user(Context *c);
140 
149  [[nodiscard]] static bool userExists(Context *c);
150 
155  [[nodiscard]] static bool userInRealm(Context *c,
156  const QString &realmName = QLatin1String(defaultRealm));
157 
162  static void logout(Context *c);
163 
164 protected:
165  virtual bool setup(Application *app) override;
166 
167  AuthenticationPrivate *d_ptr;
168 };
169 
170 inline bool Authentication::authenticate(Context *c, const QString &realm)
171 {
173 }
174 
175 } // namespace Cutelyst
176 
177 #endif // AUTHENTICATION_H
The Cutelyst application.
Definition: application.h:66
Abstract class to validate authentication credentials like user name and password.
virtual AuthenticationUser authenticate(Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo)=0
Combines user store and credential validation into a named realm.
Container for user data retrieved from an AuthenticationStore.
Main class to manage user authentication.
std::shared_ptr< AuthenticationRealm > realm(const QString &name=QLatin1String(defaultRealm)) const
static bool authenticate(Context *c, const ParamsMultiMap &userinfo, const QString &realm=QLatin1String(defaultRealm))
static char * defaultRealm
The Cutelyst Context.
Definition: context.h:42
Base class for Cutelyst Plugins.
Definition: plugin.h:25
QMultiMap< QString, QString > ParamsMultiMap
The Cutelyst namespace holds all public Cutelyst API.