cutelyst 4.0.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/cutelyst_global.h>
10#include <Cutelyst/paramsmultimap.h>
11#include <Cutelyst/plugin.h>
12
13namespace Cutelyst {
14
15class Context;
16class AuthenticationStore;
17class AuthenticationRealm;
18class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT AuthenticationCredential : public QObject
19{
20 Q_OBJECT
21public:
25 explicit AuthenticationCredential(QObject *parent = nullptr);
27
32 virtual AuthenticationUser
33 authenticate(Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo) = 0;
34};
35
36class AuthenticationPrivate;
37class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT Authentication : public Plugin
38{
39 Q_OBJECT
40 Q_DECLARE_PRIVATE(Authentication)
41public:
43 static char *defaultRealm;
44
49 virtual ~Authentication() override;
50
55 void addRealm(std::shared_ptr<AuthenticationRealm> realm);
56
61 void addRealm(std::shared_ptr<AuthenticationStore> store,
62 std::shared_ptr<AuthenticationCredential> credential,
63 const QString &name = QLatin1String(defaultRealm));
64
68 [[nodiscard]] std::shared_ptr<AuthenticationRealm>
69 realm(const QString &name = QLatin1String(defaultRealm)) const;
70
74 [[nodiscard]] static bool authenticate(Context *c,
75 const ParamsMultiMap &userinfo,
76 const QString &realm = QLatin1String(defaultRealm));
77
81 [[nodiscard]] inline static bool
82 authenticate(Context *c, const QString &realm = QLatin1String(defaultRealm));
83
88 [[nodiscard]] static AuthenticationUser
89 findUser(Context *c,
90 const ParamsMultiMap &userinfo,
91 const QString &realm = QLatin1String(defaultRealm));
92
97 [[nodiscard]] static AuthenticationUser user(Context *c);
98
107 [[nodiscard]] static bool userExists(Context *c);
108
113 [[nodiscard]] static bool userInRealm(Context *c,
114 const QString &realmName = QLatin1String(defaultRealm));
115
120 static void logout(Context *c);
121
122protected:
123 virtual bool setup(Application *app) override;
124
125 AuthenticationPrivate *d_ptr;
126};
127
128inline bool Authentication::authenticate(Context *c, const QString &realm)
129{
131}
132
133} // namespace Cutelyst
134
135#endif // AUTHENTICATION_H
The Cutelyst Application.
Definition: application.h:43
virtual AuthenticationUser authenticate(Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo)=0
Tries to authenticate the authinfo using the give realm.
std::shared_ptr< AuthenticationRealm > realm(const QString &name=QLatin1String(defaultRealm)) const
Returns an AuthenticationRealm object that was registered with name.
static bool authenticate(Context *c, const ParamsMultiMap &userinfo, const QString &realm=QLatin1String(defaultRealm))
static char * defaultRealm
default realm name
The Cutelyst Context.
Definition: context.h:38
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:8
QMultiMap< QString, QString > ParamsMultiMap