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));
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
std::shared_ptr< AuthenticationStore > store() const noexcept
void removePersistedUser(Context *c)
virtual AuthenticationUser authenticate(Context *c, const ParamsMultiMap &authinfo)
QVariant userIsRestorable(Context *c)
AuthenticationRealm(std::shared_ptr< AuthenticationStore > store, std::shared_ptr< AuthenticationCredential > credential, const QString &name=QLatin1String(defaultRealm), QObject *parent=nullptr)
AuthenticationUser persistUser(Context *c, const AuthenticationUser &user)
virtual AuthenticationUser findUser(Context *c, const ParamsMultiMap &userinfo)
AuthenticationUser restoreUser(Context *c, const QVariant &frozenUser)
Container for user data retrieved from an AuthenticationStore.
void setAuthRealm(const QString &authRealm)
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.
void setObjectName(QAnyStringView name)
bool isNull() const const