5 #include "authenticationrealm.h" 7 #include "authenticationstore.h" 10 #include "credentialpassword.h" 11 #include "storeldap.h" 13 #include <Cutelyst/Plugins/Session/session.h> 17 Q_LOGGING_CATEGORY(C_AUTH_REALM,
"cutelyst.plugin.authentication.realm", QtWarningMsg)
19 #define SESSION_AUTHENTICATION_USER "__authentication_user" 20 #define SESSION_AUTHENTICATION_USER_REALM "__authentication_user_realm" // in authentication.cpp 23 std::shared_ptr<AuthenticationCredential> credential,
28 , m_credential(credential)
30 m_credential->setParent(
this);
37 AuthenticationRealm::~AuthenticationRealm()
56 if (m_store->canAutoCreateUser()) {
57 ret = m_store->autoCreateUser(c, userinfo);
60 if (m_store->canAutoUpdateUser()) {
61 ret = m_store->autoUpdateUser(c, userinfo);
74 return m_credential->authenticate(c,
this, authinfo);
80 {QStringLiteral(SESSION_AUTHENTICATION_USER),
81 QStringLiteral(SESSION_AUTHENTICATION_USER_REALM)});
86 Session::setValue(c, QStringLiteral(SESSION_AUTHENTICATION_USER), m_store->forSession(c, user));
96 if (_frozenUser.
isNull()) {
100 if (_frozenUser.
isNull()) {
104 user = m_store->fromSession(c, _frozenUser);
110 qCWarning(C_AUTH_REALM) <<
"Store claimed to have a restorable user, but restoration " 111 "failed. Did you change the user's id_field?";
121 return Session::value(c, QStringLiteral(SESSION_AUTHENTICATION_USER));
133 credPassword->passwordType() == CredentialPassword::PasswordType::SelfCheck) {
135 return m_store->validatePassword(c, user, password);
143 #include "moc_authenticationrealm.cpp" void setName(const QString &name)
AuthenticationUser restoreUser(Context *c, const QVariant &frozenUser)
virtual AuthenticationUser findUser(Context *c, const ParamsMultiMap &userinfo)
AuthenticationUser persistUser(Context *c, const AuthenticationUser &user)
virtual AuthenticationUser authenticate(Context *c, const ParamsMultiMap &authinfo)
Use password based authentication to authenticate a user.
The Cutelyst Component base class.
QVariant userIsRestorable(Context *c)
bool isNull() const const
QString objectName() const const
QString name() const noexcept
void setObjectName(QAnyStringView name)
static void setValue(Context *c, const QString &key, const QVariant &value)
The Cutelyst namespace holds all public Cutelyst API.
Container for user data retrieved from an AuthenticationStore.
std::shared_ptr< AuthenticationStore > store() const noexcept
static void deleteValues(Context *c, const QStringList &keys)
static QVariant value(Context *c, const QString &key, const QVariant &defaultValue=QVariant())
std::shared_ptr< AuthenticationCredential > credential() const noexcept
void setAuthRealm(const QString &authRealm)
AuthenticationRealm(std::shared_ptr< AuthenticationStore > store, std::shared_ptr< AuthenticationCredential > credential, QStringView name=defaultRealm, QObject *parent=nullptr)
bool checkPassword(Context *c, const AuthenticationUser &user, const QString &password, const QString &passwordField=QStringLiteral("password"))
void removePersistedUser(Context *c)