5#include "authenticationrealm.h"
7#include "authenticationstore.h"
11#include <Cutelyst/Plugins/Session/session.h>
15Q_LOGGING_CATEGORY(C_AUTH_REALM,
"cutelyst.plugin.authentication.realm", QtWarningMsg)
17#define SESSION_AUTHENTICATION_USER "__authentication_user"
18#define SESSION_AUTHENTICATION_USER_REALM "__authentication_user_realm"
21 std::shared_ptr<AuthenticationCredential> credential,
26 , m_credential(credential)
28 m_credential->setParent(
this);
33AuthenticationRealm::~AuthenticationRealm()
52 if (m_store->canAutoCreateUser()) {
53 ret = m_store->autoCreateUser(c, userinfo);
56 if (m_store->canAutoUpdateUser()) {
57 ret = m_store->autoUpdateUser(c, userinfo);
70 return m_credential->authenticate(c,
this, authinfo);
76 {QStringLiteral(SESSION_AUTHENTICATION_USER),
77 QStringLiteral(SESSION_AUTHENTICATION_USER_REALM)});
82 Session::setValue(c, QStringLiteral(SESSION_AUTHENTICATION_USER), m_store->forSession(c, user));
83 Session::setValue(c, QStringLiteral(SESSION_AUTHENTICATION_USER_REALM), objectName());
91 QVariant _frozenUser = frozenUser;
92 if (_frozenUser.isNull()) {
96 if (_frozenUser.isNull()) {
100 user = m_store->fromSession(c, _frozenUser);
106 qCWarning(C_AUTH_REALM) <<
"Store claimed to have a restorable user, but restoration "
107 "failed. Did you change the user's id_field?";
117 return Session::value(c, QStringLiteral(SESSION_AUTHENTICATION_USER));
120#include "moc_authenticationrealm.cpp"
std::shared_ptr< AuthenticationCredential > credential() const noexcept
Returns the authentication credential object.
std::shared_ptr< AuthenticationStore > store() const noexcept
Returns the authentication store object.
void removePersistedUser(Context *c)
Removes the user from the session.
virtual AuthenticationUser authenticate(Context *c, const ParamsMultiMap &authinfo)
Tries to authenticate the user with authinfo returning a non null AuthenticationUser on success.
QVariant userIsRestorable(Context *c)
Checks if user can be retrieved.
AuthenticationRealm(std::shared_ptr< AuthenticationStore > store, std::shared_ptr< AuthenticationCredential > credential, const QString &name=QLatin1String(defaultRealm), QObject *parent=nullptr)
Constructs a new AuthenticationRealm object with the given parent.
AuthenticationUser persistUser(Context *c, const AuthenticationUser &user)
Stores the user on the session.
virtual AuthenticationUser findUser(Context *c, const ParamsMultiMap &userinfo)
Tries to find the user with authinfo returning a non null AuthenticationUser on success.
AuthenticationUser restoreUser(Context *c, const QVariant &frozenUser)
Retrieves the user from the store.
QString authRealm()
Returns the authentication realm from which this user was retrieved.
void setAuthRealm(const QString &authRealm)
Sets the authentication realm from which this user was retrieved.
bool isNull() const
Returns true if the object is null.
The Cutelyst Component base class.
QString name() const noexcept
void setName(const QString &name)
static QVariant value(Context *c, const QString &key, const QVariant &defaultValue=QVariant())
static void setValue(Context *c, const QString &key, const QVariant &value)
static void deleteValues(Context *c, const QStringList &keys)
The Cutelyst namespace holds all public Cutelyst API.
QMultiMap< QString, QString > ParamsMultiMap