cutelyst 5.0.1
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 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 ()

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().