cutelyst 5.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/Plugins/authentication_export.h>
10#include <Cutelyst/paramsmultimap.h>
11#include <Cutelyst/plugin.h>
12
13namespace Cutelyst {
14
15class Context;
16class AuthenticationStore;
17class AuthenticationRealm;
18
33class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT AuthenticationCredential : public QObject
34{
35 Q_OBJECT
36public:
40 explicit AuthenticationCredential(QObject *parent = nullptr);
41
46
54 virtual AuthenticationUser
55 authenticate(Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo) = 0;
56};
57
58class AuthenticationPrivate;
59
75class CUTELYST_PLUGIN_AUTHENTICATION_EXPORT Authentication : public Plugin
76{
77 Q_OBJECT
78 Q_DECLARE_PRIVATE(Authentication)
79public:
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
158protected:
159 virtual bool setup(Application *app) override;
160
161 AuthenticationPrivate *d_ptr;
162};
163
168
169} // namespace Cutelyst
170
171#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.
static bool authenticate(Context *c, const ParamsMultiMap &userinfo, QStringView realm=defaultRealm)
std::shared_ptr< AuthenticationRealm > realm(QStringView name=defaultRealm) const
static const QStringView 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.