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

Use HTTP basic authentication to authenticate a user. More...

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

Inheritance diagram for Cutelyst::CredentialHttp:

Public Types

enum  AuthType { Any , Basic }
enum  PasswordType { None , Clear , Hashed }
Public Types inherited from QObject
enum  TimerId

Public Member Functions

 CredentialHttp (QObject *parent=nullptr)
virtual ~CredentialHttp ()
AuthenticationUser authenticate (Context *c, AuthenticationRealm *realm, const ParamsMultiMap &authinfo) final
QString passwordField () const
QString passwordPostSalt () const
QString passwordPreSalt () const
PasswordType passwordType () const
void setAuthorizationRequiredMessage (const QString &message)
void setPasswordField (const QString &fieldName)
void setPasswordPostSalt (const QString &passwordPostSalt)
void setPasswordPreSalt (const QString &passwordPreSalt)
void setPasswordType (PasswordType type)
void setRequireSsl (bool require)
void setType (CredentialHttp::AuthType type)
void setUsernameField (const QString &fieldName)
QString usernameField () const
Public Member Functions inherited from Cutelyst::AuthenticationCredential
 AuthenticationCredential (QObject *parent=nullptr)
virtual ~AuthenticationCredential ()
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

Additional Inherited Members

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)
Public Attributes inherited from QObject
 Invalid
typedef QObjectList
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)
Properties inherited from QObject
 objectName

Detailed Description

This credential provider authenticates a user using HTTP basic authentication as described in RFC 76147. It tries to read the user name and the password from the Authorization header send by the user agent. If the authorization fails or if no Authorization header is available, it will respond with a 401 Unauthorized status code and will set the WWW-Authenticate header requesting basic authentication with the used realm.

For an example implementation see Authentication overview.

Logging category
cutelyst.plugin.credentialhttp
Logging with Cutelyst

Definition at line 32 of file credentialhttp.h.

Member Enumeration Documentation

◆ AuthType

The authentication type.

Definition at line 51 of file credentialhttp.h.

◆ PasswordType

The used password type.

Enumerator
None 

Ignore password check.

Clear 

Clear text password.

Hashed 

Derived password hash using PBKDF2 method.

Definition at line 40 of file credentialhttp.h.

Constructor & Destructor Documentation

◆ CredentialHttp()

◆ ~CredentialHttp()

CredentialHttp::~CredentialHttp ( )
virtual

Destroys the CredentialHttp object.

Definition at line 26 of file credentialhttp.cpp.

Member Function Documentation

◆ authenticate()

AuthenticationUser CredentialHttp::authenticate ( Cutelyst::Context * c,
AuthenticationRealm * realm,
const ParamsMultiMap & authinfo )
nodiscardfinalvirtual

Gets the user data from the Authorization HTTP header field and tries to find it in the realm. On success, this returns a not null AuthenticationUser object. If authentication fails, the HTTP response status code will be set to 401 Unauthorized and the WWW-Authenticate header will be set with the required authentication method and realm name while a null AuthenticationUser object is returned.

Implements Cutelyst::AuthenticationCredential.

Definition at line 109 of file credentialhttp.cpp.

References CredentialHttp(), Cutelyst::AuthenticationUser::isNull(), and Cutelyst::Context::request.

◆ passwordField()

QString CredentialHttp::passwordField ( ) const
nodiscard

Returns the field to look for when authenticating the user.

See also
authenticate().

Definition at line 43 of file credentialhttp.cpp.

References CredentialHttp().

◆ passwordPostSalt()

QString CredentialHttp::passwordPostSalt ( ) const
nodiscard

Returns the salt string to be appended to the password

Definition at line 79 of file credentialhttp.cpp.

References CredentialHttp().

Referenced by setPasswordPostSalt().

◆ passwordPreSalt()

QString CredentialHttp::passwordPreSalt ( ) const
nodiscard

Returns the salt string to be prepended to the password

Definition at line 67 of file credentialhttp.cpp.

References CredentialHttp().

Referenced by setPasswordPreSalt().

◆ passwordType()

CredentialHttp::PasswordType CredentialHttp::passwordType ( ) const
nodiscard

Returns the type of password this class will be dealing with.

Definition at line 55 of file credentialhttp.cpp.

References CredentialHttp().

◆ setAuthorizationRequiredMessage()

void CredentialHttp::setAuthorizationRequiredMessage ( const QString & message)

Set this to a string to override the default body content "Authorization required.", or set to undef to suppress body content being generated.

Definition at line 37 of file credentialhttp.cpp.

References CredentialHttp().

◆ setPasswordField()

void CredentialHttp::setPasswordField ( const QString & fieldName)

Sets the field to look for when authenticating the user.

See also
authenticate().

Definition at line 49 of file credentialhttp.cpp.

References CredentialHttp().

◆ setPasswordPostSalt()

void CredentialHttp::setPasswordPostSalt ( const QString & passwordPostSalt)

Sets the salt string to be appended to the password

Definition at line 85 of file credentialhttp.cpp.

References CredentialHttp(), and passwordPostSalt().

◆ setPasswordPreSalt()

void CredentialHttp::setPasswordPreSalt ( const QString & passwordPreSalt)

Sets the salt string to be prepended to the password

Definition at line 73 of file credentialhttp.cpp.

References CredentialHttp(), and passwordPreSalt().

◆ setPasswordType()

void CredentialHttp::setPasswordType ( CredentialHttp::PasswordType type)

Sets the type of password this class will be dealing with.

Definition at line 61 of file credentialhttp.cpp.

References CredentialHttp().

◆ setRequireSsl()

void CredentialHttp::setRequireSsl ( bool require)

If this configuration is true then authentication will be denied (and a 401 issued in normal circumstances) unless the request is via https.

Definition at line 103 of file credentialhttp.cpp.

References CredentialHttp().

◆ setType()

void CredentialHttp::setType ( CredentialHttp::AuthType type)

Can be either any (the default), basic.

This controls authorization_required_response and authenticate, but not the "manual" methods.

Definition at line 31 of file credentialhttp.cpp.

References CredentialHttp().

◆ setUsernameField()

void CredentialHttp::setUsernameField ( const QString & fieldName)

Sets the field to look for when authenticating the user.

See also
authenticate().

Definition at line 97 of file credentialhttp.cpp.

References CredentialHttp().

◆ usernameField()

QString CredentialHttp::usernameField ( ) const
nodiscard

Returns the field to look for when authenticating the user.

See also
authenticate().

Definition at line 91 of file credentialhttp.cpp.

References CredentialHttp().