Skip to content

Commit

Permalink
Logout existing sessions after a username or password change
Browse files Browse the repository at this point in the history
Closes #18443
  • Loading branch information
Func86 committed Sep 15, 2024
1 parent 0ea35c5 commit f0ccfa3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/webui/api/authcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ AuthController::AuthController(ISessionManager *sessionManager, IApplication *ap

void AuthController::setUsername(const QString &username)
{
if (!m_username.isEmpty() && m_username != username)
m_sessionManager->logoutAllSessions();
m_username = username;
}

void AuthController::setPasswordHash(const QByteArray &passwordHash)
{
if (!m_passwordHash.isEmpty() && m_passwordHash != passwordHash)
m_sessionManager->logoutAllSessions();
m_passwordHash = passwordHash;
}

Expand Down
1 change: 1 addition & 0 deletions src/webui/api/isessionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ struct ISessionManager
virtual ISession *session() = 0;
virtual void sessionStart() = 0;
virtual void sessionEnd() = 0;
virtual void logoutAllSessions() = 0;
};
6 changes: 6 additions & 0 deletions src/webui/webapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ const Http::Environment &WebApplication::env() const
return m_env;
}

void WebApplication::logoutAllSessions()
{
qDeleteAll(m_sessions);
m_sessions.clear();
}

void WebApplication::setUsername(const QString &username)
{
m_authController->setUsername(username);
Expand Down
1 change: 1 addition & 0 deletions src/webui/webapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class WebApplication final : public ApplicationComponent<QObject>
WebSession *session() override;
void sessionStart() override;
void sessionEnd() override;
void logoutAllSessions() override;

void doProcessRequest();
void configure();
Expand Down

0 comments on commit f0ccfa3

Please sign in to comment.