18 #include "authentication_p.h"
20 #include "authenticationstore.h"
21 #include "authenticationrealm.h"
24 #include "application.h"
26 #include <Cutelyst/Plugins/Session/session.h>
28 #include <QLoggingCategory>
30 Q_LOGGING_CATEGORY(CUTELYST_UTILS_AUTH,
"cutelyst.utils.auth", QtWarningMsg)
31 Q_LOGGING_CATEGORY(C_AUTHENTICATION,
"cutelyst.plugin.authentication", QtWarningMsg)
40 #define AUTHENTICATION_USER QStringLiteral("_c_authentication_user")
41 #define AUTHENTICATION_USER_REALM QStringLiteral("_c_authentication_user_realm")
44 , d_ptr(new AuthenticationPrivate)
46 qRegisterMetaType<AuthenticationUser>();
47 qRegisterMetaTypeStreamOperators<AuthenticationUser>();
50 Authentication::~Authentication()
71 return d->realms.value(name);
77 qCCritical(C_AUTHENTICATION) <<
"Authentication plugin not registered";
85 AuthenticationPrivate::setAuthenticated(c,
user,
realm, realmPtr);
91 qCWarning(C_AUTHENTICATION) <<
"Could not find realm" <<
realm;
99 qCCritical(C_AUTHENTICATION) <<
"Authentication plugin not registered";
105 qCWarning(C_AUTHENTICATION) <<
"Could not find realm" <<
realm;
109 ret = realmPtr->
findUser(c, userinfo);
127 if (!c->
stash(AUTHENTICATION_USER).isNull()) {
131 if (AuthenticationPrivate::findRealmForPersistedUser(c, auth->d_ptr->realms, auth->d_ptr->realmsOrder)) {
135 qCCritical(C_AUTHENTICATION,
"Authentication plugin not registered!");
148 qCCritical(C_AUTHENTICATION,
"Authentication plugin not registered!");
152 AuthenticationRealm *
realm = AuthenticationPrivate::findRealmForPersistedUser(c, auth->d_ptr->realms, auth->d_ptr->realmsOrder);
166 AuthenticationRealm *
realm = AuthenticationPrivate::findRealmForPersistedUser(c, auth->d_ptr->realms, auth->d_ptr->realmsOrder);
171 qCCritical(C_AUTHENTICATION) <<
"Authentication plugin not registered";
184 return realms.value(realmName.
isNull() ? defaultRealm : realmName);
191 qCCritical(C_AUTHENTICATION) <<
"Authentication plugin not registered";
197 realmPtr = AuthenticationPrivate::findRealmForPersistedUser(c, auth->d_ptr->realms, auth->d_ptr->realmsOrder);
206 AuthenticationPrivate::setUser(c, ret);
214 if (!realmVariant.
isNull()) {
221 for (
const QString &realmName : realmsOrder) {
234 AuthenticationPrivate::setUser(c, user, realmName);
237 qCWarning(C_AUTHENTICATION) <<
"Called with invalid realm" << realmName;
240 AuthenticationPrivate::persistUser(c, user, realmName, realm);
250 c->
setStash(AUTHENTICATION_USER_REALM, realmName);
270 Cutelyst::AuthenticationCredential::~AuthenticationCredential()
275 #include "moc_authentication.cpp"