cutelyst  5.0.1
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 const QStringView defaultRealm;
84 
88  explicit 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  QStringView name = defaultRealm);
106 
110  [[nodiscard]] std::shared_ptr<AuthenticationRealm> realm(QStringView name = defaultRealm) const;
111 
115  [[nodiscard]] static bool
116  authenticate(Context *c, const ParamsMultiMap &userinfo, QStringView realm = defaultRealm);
117 
121  [[nodiscard]] inline static bool authenticate(Context *c, QStringView realm = defaultRealm);
122 
127  [[nodiscard]] static AuthenticationUser
128  findUser(Context *c, const ParamsMultiMap &userinfo, QStringView realm = defaultRealm);
129 
134  [[nodiscard]] static AuthenticationUser user(Context *c);
135 
144  [[nodiscard]] static bool userExists(Context *c);
145 
150  [[nodiscard]] static bool userInRealm(Context *c, QStringView realmName = defaultRealm);
151 
156  static void logout(Context *c);
157 
158 protected:
159  virtual bool setup(Application *app) override;
160 
161  AuthenticationPrivate *d_ptr;
162 };
163 
164 inline bool Authentication::authenticate(Context *c, QStringView realm)
165 {
167 }
168 
169 } // namespace Cutelyst
170 
171 #endif // AUTHENTICATION_H
std::shared_ptr< AuthenticationRealm > realm(QStringView name=defaultRealm) const
Main class to manage user authentication.
Abstract class to validate authentication credentials like user name and password.
Combines user store and credential validation into a named realm.
The Cutelyst Context.
Definition: context.h:42
static bool authenticate(Context *c, const ParamsMultiMap &userinfo, QStringView realm=defaultRealm)
The Cutelyst namespace holds all public Cutelyst API.
Container for user data retrieved from an AuthenticationStore.
QMultiMap< QString, QString > ParamsMultiMap
Base class for Cutelyst Plugins.
Definition: plugin.h:24
The Cutelyst application.
Definition: application.h:72