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"
28 m_store->setParent(
this);
29 m_credential->setParent(
this);
34AuthenticationRealm::~AuthenticationRealm()
53 if (m_store->canAutoCreateUser()) {
54 ret = m_store->autoCreateUser(c, userinfo);
57 if (m_store->canAutoUpdateUser()) {
58 ret = m_store->autoUpdateUser(c, userinfo);
71 return m_credential->authenticate(c,
this, authinfo);
77 {QStringLiteral(SESSION_AUTHENTICATION_USER),
78 QStringLiteral(SESSION_AUTHENTICATION_USER_REALM)});
83 Session::setValue(c, QStringLiteral(SESSION_AUTHENTICATION_USER), m_store->forSession(c, user));
93 if (_frozenUser.
isNull()) {
97 if (_frozenUser.
isNull()) {
101 user = m_store->fromSession(c, _frozenUser);
107 qCWarning(C_AUTH_REALM) <<
"Store claimed to have a restorable user, but restoration "
108 "failed. Did you change the user's id_field?";
118 return Session::value(c, QStringLiteral(SESSION_AUTHENTICATION_USER));
121#include "moc_authenticationrealm.cpp"
AuthenticationCredential * credential() const
Returns the authentication credential object.
AuthenticationRealm(AuthenticationStore *store, AuthenticationCredential *credential, const QString &name=QLatin1String(defaultRealm), QObject *parent=nullptr)
Constructs a new AuthenticationRealm object with the given parent.
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.
AuthenticationStore * store() const
Returns the authentication store object.
QVariant userIsRestorable(Context *c)
Checks if user can be retrieved.
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.
Component(QObject *parent=nullptr)
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
void setObjectName(const QString &name)
QObject * parent() const const
bool isNull() const const