cutelyst 5.0.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::Authentication Class Reference

Main class to manage user authentication. More...

#include <Cutelyst/Plugins/Authentication/authentication.h>

Inheritance diagram for Cutelyst::Authentication:

Public Member Functions

 Authentication (Application *parent)
virtual ~Authentication () override
void addRealm (std::shared_ptr< AuthenticationRealm > realm)
void addRealm (std::shared_ptr< AuthenticationStore > store, std::shared_ptr< AuthenticationCredential > credential, QStringView name=defaultRealm)
std::shared_ptr< AuthenticationRealmrealm (QStringView name=defaultRealm) const
Public Member Functions inherited from Cutelyst::Plugin
 Plugin (Application *parent)
Public Member Functions inherited from QObject
 QObject (QObject *parent)
QBindable< QStringbindableObjectName ()
bool blockSignals (bool block)
const QObjectListchildren () const const
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
void deleteLater ()
void destroyed (QObject *obj)
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
bool disconnect (const QObject *receiver, const char *method) const const
void dumpObjectInfo () const const
void dumpObjectTree () const const
QList< QByteArraydynamicPropertyNames () const const
virtual bool event (QEvent *e)
virtual bool eventFilter (QObject *watched, QEvent *event)
findChild (QAnyStringView name, Qt::FindChildOptions options) const const
findChild (Qt::FindChildOptions options) const const
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
QList< T > findChildren (QAnyStringView name, Qt::FindChildOptions options) const const
QList< T > findChildren (Qt::FindChildOptions options) const const
bool inherits (const char *className) const const
void installEventFilter (QObject *filterObj)
bool isQmlExposed () const const
bool isQuickItemType () const const
bool isWidgetType () const const
bool isWindowType () const const
void killTimer (int id)
void killTimer (Qt::TimerId id)
virtual const QMetaObjectmetaObject () const const
bool moveToThread (QThread *targetThread)
QString objectName () const const
void objectNameChanged (const QString &objectName)
QObjectparent () const const
QVariant property (const char *name) const const
 Q_CLASSINFO (Name, Value)
 Q_EMIT Q_EMIT
 Q_ENUM (...)
 Q_ENUM_NS (...)
 Q_ENUMS (...)
 Q_FLAG (...)
 Q_FLAG_NS (...)
 Q_FLAGS (...)
 Q_GADGET Q_GADGET
 Q_GADGET_EXPORT (EXPORT_MACRO)
 Q_INTERFACES (...)
 Q_INVOKABLE Q_INVOKABLE
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 Q_NAMESPACE Q_NAMESPACE
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 Q_OBJECT Q_OBJECT
 Q_PROPERTY (...)
 Q_REVISION Q_REVISION
 Q_SET_OBJECT_NAME (Object)
 Q_SIGNAL Q_SIGNAL
 Q_SIGNALS Q_SIGNALS
 Q_SLOT Q_SLOT
 Q_SLOTS Q_SLOTS
qobject_cast (const QObject *object)
qobject_cast (QObject *object)
 QT_NO_CONTEXTLESS_CONNECT QT_NO_CONTEXTLESS_CONNECT
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
void removeEventFilter (QObject *obj)
void setObjectName (const QString &name)
void setObjectName (QAnyStringView name)
void setParent (QObject *parent)
bool setProperty (const char *name, const QVariant &value)
bool setProperty (const char *name, QVariant &&value)
bool signalsBlocked () const const
int startTimer (int interval, Qt::TimerType timerType)
int startTimer (std::chrono::nanoseconds interval, Qt::TimerType timerType)
QThreadthread () const const

Static Public Member Functions

static bool authenticate (Context *c, const ParamsMultiMap &userinfo, QStringView realm=defaultRealm)
static bool authenticate (Context *c, QStringView realm=defaultRealm)
static AuthenticationUser findUser (Context *c, const ParamsMultiMap &userinfo, QStringView realm=defaultRealm)
static void logout (Context *c)
static AuthenticationUser user (Context *c)
static bool userExists (Context *c)
static bool userInRealm (Context *c, QStringView realmName=defaultRealm)
Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect (const QMetaObject::Connection &connection)
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
QString tr (const char *sourceText, const char *disambiguation, int n)

Static Public Attributes

static const QStringView defaultRealm

Protected Member Functions

virtual bool setup (Application *app) override
Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
virtual void connectNotify (const QMetaMethod &signal)
virtual void customEvent (QEvent *event)
virtual void disconnectNotify (const QMetaMethod &signal)
bool isSignalConnected (const QMetaMethod &signal) const const
int receivers (const char *signal) const const
QObjectsender () const const
int senderSignalIndex () const const
virtual void timerEvent (QTimerEvent *event)

Additional Inherited Members

Public Types inherited from QObject
enum  TimerId
Public Attributes inherited from QObject
 Invalid
typedef QObjectList
Properties inherited from QObject
 objectName

Detailed Description

The Authentication class authenticates users against user data found in a specific realm. You can add multiple AuthenticationRealms identified by name that consist of different AuthenticationStore and AuthenticationCredential providers. You could for example add one realm for login on the website using a HTML formular and another one using HTTP basic authentication to authenticate with your API routes.

For an example implementation see Authentication overview.

Logging category
cutelyst.plugin.authentication
Logging with Cutelyst

Definition at line 75 of file authentication.h.

Constructor & Destructor Documentation

◆ Authentication()

Authentication::Authentication ( Application * parent)
explicit

Constructs a new Authentication object with the given parent.

Definition at line 30 of file authentication.cpp.

References Cutelyst::Plugin::Plugin(), and QObject::parent().

Referenced by addRealm(), and realm().

◆ ~Authentication()

Authentication::~Authentication ( )
overridevirtual

Destroys the Authentication object.

Definition at line 37 of file authentication.cpp.

Member Function Documentation

◆ addRealm() [1/2]

void Authentication::addRealm ( std::shared_ptr< AuthenticationRealm > realm)

Adds the realm.

Definition at line 42 of file authentication.cpp.

References Authentication(), and realm().

Referenced by addRealm().

◆ addRealm() [2/2]

void Cutelyst::Authentication::addRealm ( std::shared_ptr< AuthenticationStore > store,
std::shared_ptr< AuthenticationCredential > credential,
QStringView name = defaultRealm )

Creates a new AuthenticationRealm using store, credential and name.

Definition at line 50 of file authentication.cpp.

References addRealm().

◆ authenticate() [1/2]

bool Authentication::authenticate ( Cutelyst::Context * c,
const ParamsMultiMap & userinfo,
QStringView realm = defaultRealm )
staticnodiscard

Returns true if the userinfo could be validated against realm.

Definition at line 64 of file authentication.cpp.

References Cutelyst::AuthenticationUser::isNull(), and realm().

Referenced by authenticate().

◆ authenticate() [2/2]

bool Cutelyst::Authentication::authenticate ( Context * c,
QStringView realm = defaultRealm )
inlinestaticnodiscard

Returns true if the request information could be validated against realm.

Definition at line 164 of file authentication.h.

References authenticate(), and realm().

◆ findUser()

AuthenticationUser Authentication::findUser ( Cutelyst::Context * c,
const ParamsMultiMap & userinfo,
QStringView realm = defaultRealm )
staticnodiscard

Tries to find the user with userinfo using the realm, returning a non null AuthenticationUser on success

Definition at line 87 of file authentication.cpp.

References realm().

◆ logout()

void Authentication::logout ( Context * c)
static

Logs the user out. Deletes the currently logged in user from the Context and the session. It does not delete the session.

Definition at line 157 of file authentication.cpp.

◆ realm()

std::shared_ptr< Cutelyst::AuthenticationRealm > Authentication::realm ( QStringView name = defaultRealm) const
nodiscard

Returns an AuthenticationRealm object that was registered with name.

Definition at line 58 of file authentication.cpp.

References Authentication(), and QStringView::toString().

Referenced by addRealm(), authenticate(), authenticate(), and findUser().

◆ setup()

bool Authentication::setup ( Application * app)
overrideprotectedvirtual

Reimplement this if you need to connect to the signals emitted from Cutelyst::Application.

Reimplemented from Cutelyst::Plugin.

Definition at line 172 of file authentication.cpp.

References QObject::connect(), and Cutelyst::Application::postForked().

◆ user()

Cutelyst::AuthenticationUser Authentication::user ( Cutelyst::Context * c)
staticnodiscard

Returns the authenticated user if any, if you only need to know if the user is authenticated (rather than retrieving it's ID) use userExists() instead which is faster.

Definition at line 107 of file authentication.cpp.

References Cutelyst::Context::stash(), and user().

Referenced by Cutelyst::RoleACL::canVisit(), and user().

◆ userExists()

bool Authentication::userExists ( Cutelyst::Context * c)
staticnodiscard

Returns true if a user is logged in right now. The difference between userExists() and user() is that userExists() will return true if a user is logged in, even if it has not been yet retrieved from the storage backend. If you only need to know if the user is logged in, depending on the storage mechanism this can be much more efficient. userExists() only looks into the session while user() is trying to restore the user.

Definition at line 119 of file authentication.cpp.

References Cutelyst::Context::stash().

◆ userInRealm()

bool Authentication::userInRealm ( Cutelyst::Context * c,
QStringView realmName = defaultRealm )
staticnodiscard

Works like userExists(), except that it only returns true if a user is both logged in right now and was retrieved from the realm provided.

Definition at line 136 of file authentication.cpp.

References QVariant::isNull(), Cutelyst::Context::stash(), and QVariant::value().

Member Data Documentation

◆ defaultRealm

const QStringView Authentication::defaultRealm
static

Default realm name.

Definition at line 83 of file authentication.h.