![]() |
cutelyst 4.8.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Main class to manage user authentication. More...
#include <Cutelyst/Plugins/Authentication/authentication.h>

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, const QString &name=QLatin1String(defaultRealm)) |
| std::shared_ptr< AuthenticationRealm > | realm (const QString &name=QLatin1String(defaultRealm)) const |
Public Member Functions inherited from Cutelyst::Plugin | |
| Plugin (Application *parent) | |
| virtual bool | setup (Application *app) |
Static Public Member Functions | |
| static bool | authenticate (Context *c, const ParamsMultiMap &userinfo, const QString &realm=QLatin1String(defaultRealm)) |
| static bool | authenticate (Context *c, const QString &realm=QLatin1String(defaultRealm)) |
| static AuthenticationUser | findUser (Context *c, const ParamsMultiMap &userinfo, const QString &realm=QLatin1String(defaultRealm)) |
| static void | logout (Context *c) |
| static AuthenticationUser | user (Context *c) |
| static bool | userExists (Context *c) |
| static bool | userInRealm (Context *c, const QString &realmName=QLatin1String(defaultRealm)) |
Static Public Attributes | |
| static char * | defaultRealm |
Protected Member Functions | |
| virtual bool | setup (Application *app) override |
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.
Definition at line 75 of file authentication.h.
| Authentication::Authentication | ( | Application * | parent | ) |
Constructs a new Authentication object with the given parent.
Definition at line 28 of file authentication.cpp.
|
overridevirtual |
Destroys the Authentication object.
Definition at line 35 of file authentication.cpp.
| void Authentication::addRealm | ( | std::shared_ptr< AuthenticationRealm > | realm | ) |
| void Cutelyst::Authentication::addRealm | ( | std::shared_ptr< AuthenticationStore > | store, |
| std::shared_ptr< AuthenticationCredential > | credential, | ||
| const QString & | name = QLatin1String(defaultRealm) |
||
| ) |
Creates a new AuthenticationRealm using store, credential and name.
Definition at line 48 of file authentication.cpp.
|
static |
Returns true if the userinfo could be validated against realm.
Definition at line 62 of file authentication.cpp.
References Cutelyst::AuthenticationUser::isNull(), realm(), and user().
Referenced by authenticate().
|
inlinestatic |
Returns true if the request information could be validated against realm.
Definition at line 170 of file authentication.h.
References authenticate(), and realm().
|
static |
Tries to find the user with userinfo using the realm, returning a non null AuthenticationUser on success
Definition at line 85 of file authentication.cpp.
References realm().
|
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 155 of file authentication.cpp.
References realm().
| std::shared_ptr< Cutelyst::AuthenticationRealm > Authentication::realm | ( | const QString & | name = QLatin1String(defaultRealm) | ) | const |
Returns an AuthenticationRealm object that was registered with name.
Definition at line 56 of file authentication.cpp.
Referenced by addRealm(), authenticate(), authenticate(), findUser(), logout(), and userInRealm().
|
overrideprotectedvirtual |
Reimplement this if you need to connect to the signals emitted from Cutelyst::Application.
Reimplemented from Cutelyst::Plugin.
Definition at line 170 of file authentication.cpp.
References Cutelyst::Application::postForked().
|
static |
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 105 of file authentication.cpp.
References Cutelyst::AuthenticationUser::isNull(), Cutelyst::Context::stash(), user(), and Cutelyst::AuthenticationUser::value().
Referenced by authenticate(), Cutelyst::RoleACL::canVisit(), user(), and userInRealm().
|
static |
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 117 of file authentication.cpp.
References Cutelyst::Context::stash().
|
static |
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 134 of file authentication.cpp.
References Cutelyst::AuthenticationUser::isNull(), realm(), Cutelyst::Context::stash(), user(), and Cutelyst::AuthenticationUser::value().
|
static |
Default realm name.
Definition at line 83 of file authentication.h.