blob: 2c9613a2180da6303ce132b9a4e9e591cab2ad45 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +01003#pragma once
4
Ed Tanousd7857202025-01-28 15:32:26 -08005#include "bmcweb_config.h"
6
Ed Tanous04e438c2020-10-03 08:06:26 -07007#include "logging.hpp"
Ed Tanous2c6ffdb2023-06-28 11:28:38 -07008#include "ossl_random.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08009#include "utils/ip_utils.hpp"
Ed Tanousfc76b8a2020-09-28 17:21:52 -070010
Ed Tanousd7857202025-01-28 15:32:26 -080011#include <boost/asio/ip/address.hpp>
Ed Tanous1abe55e2018-09-05 08:30:59 -070012#include <nlohmann/json.hpp>
Ratan Gupta12c04ef2019-04-03 10:08:11 +053013
Ed Tanousd7857202025-01-28 15:32:26 -080014#include <chrono>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050015#include <csignal>
Ed Tanousd7857202025-01-28 15:32:26 -080016#include <cstddef>
17#include <cstdint>
18#include <functional>
Ed Tanous89cda632024-04-16 08:45:54 -070019#include <memory>
Ed Tanousbb759e32022-08-02 17:07:54 -070020#include <optional>
Ed Tanousb7f3a822024-06-05 08:45:25 -070021#include <string>
Ed Tanousd7857202025-01-28 15:32:26 -080022#include <string_view>
23#include <unordered_map>
Ed Tanous89cda632024-04-16 08:45:54 -070024#include <vector>
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +010025
Ed Tanous1abe55e2018-09-05 08:30:59 -070026namespace persistent_data
27{
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +010028
Ed Tanous51dae672018-09-05 16:07:32 -070029// entropy: 20 characters, 62 possibilities. log2(62^20) = 119 bits of
30// entropy. OWASP recommends at least 64
31// https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#session-id-entropy
32constexpr std::size_t sessionTokenSize = 20;
33
Ed Tanous89cda632024-04-16 08:45:54 -070034enum class SessionType
Ed Tanous1abe55e2018-09-05 08:30:59 -070035{
Ed Tanous89cda632024-04-16 08:45:54 -070036 None,
37 Basic,
38 Session,
39 Cookie,
40 MutualTLS
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +010041};
42
Ed Tanous1abe55e2018-09-05 08:30:59 -070043struct UserSession
44{
45 std::string uniqueId;
46 std::string sessionToken;
47 std::string username;
48 std::string csrfToken;
Ed Tanousbb759e32022-08-02 17:07:54 -070049 std::optional<std::string> clientId;
Sunitha Harish92f68222020-05-28 05:09:09 -050050 std::string clientIp;
Ed Tanous1abe55e2018-09-05 08:30:59 -070051 std::chrono::time_point<std::chrono::steady_clock> lastUpdated;
Ed Tanous89cda632024-04-16 08:45:54 -070052 SessionType sessionType{SessionType::None};
Ed Tanous7e9c08e2023-06-16 11:29:37 -070053 bool cookieAuth = false;
Joseph Reynolds3bf4e632020-02-06 14:44:32 -060054 bool isConfigureSelfOnly = false;
Ed Tanous47f29342024-03-19 12:18:06 -070055 std::string userRole;
56 std::vector<std::string> userGroups;
Joseph Reynolds3bf4e632020-02-06 14:44:32 -060057
58 // There are two sources of truth for isConfigureSelfOnly:
59 // 1. When pamAuthenticateUser() returns PAM_NEW_AUTHTOK_REQD.
60 // 2. D-Bus User.Manager.GetUserInfo property UserPasswordExpired.
61 // These should be in sync, but the underlying condition can change at any
62 // time. For example, a password can expire or be changed outside of
63 // bmcweb. The value stored here is updated at the start of each
64 // operation and used as the truth within bmcweb.
Kowalski, Kamil5cef0f72018-02-15 15:26:51 +010065
Ed Tanous1abe55e2018-09-05 08:30:59 -070066 /**
67 * @brief Fills object with data from UserSession's JSON representation
68 *
69 * This replaces nlohmann's from_json to ensure no-throw approach
70 *
71 * @param[in] j JSON object from which data should be loaded
72 *
73 * @return a shared pointer if data has been loaded properly, nullptr
74 * otherwise
75 */
Patrick Williams504af5a2025-02-03 14:29:03 -050076 static std::shared_ptr<UserSession> fromJson(
77 const nlohmann::json::object_t& j)
Ed Tanous1abe55e2018-09-05 08:30:59 -070078 {
79 std::shared_ptr<UserSession> userSession =
80 std::make_shared<UserSession>();
Ed Tanous0bdda662023-08-03 17:27:34 -070081 for (const auto& element : j)
Ed Tanous1abe55e2018-09-05 08:30:59 -070082 {
83 const std::string* thisValue =
Ed Tanous0bdda662023-08-03 17:27:34 -070084 element.second.get_ptr<const std::string*>();
Ed Tanous1abe55e2018-09-05 08:30:59 -070085 if (thisValue == nullptr)
86 {
Ed Tanous62598e32023-07-17 17:06:25 -070087 BMCWEB_LOG_ERROR(
88 "Error reading persistent store. Property {} was not of type string",
Ed Tanous0bdda662023-08-03 17:27:34 -070089 element.first);
Ed Tanousdc511aa2020-10-21 12:33:42 -070090 continue;
Ed Tanous1abe55e2018-09-05 08:30:59 -070091 }
Ed Tanous0bdda662023-08-03 17:27:34 -070092 if (element.first == "unique_id")
Ed Tanous1abe55e2018-09-05 08:30:59 -070093 {
94 userSession->uniqueId = *thisValue;
95 }
Ed Tanous0bdda662023-08-03 17:27:34 -070096 else if (element.first == "session_token")
Ed Tanous1abe55e2018-09-05 08:30:59 -070097 {
98 userSession->sessionToken = *thisValue;
99 }
Ed Tanous0bdda662023-08-03 17:27:34 -0700100 else if (element.first == "csrf_token")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700101 {
102 userSession->csrfToken = *thisValue;
103 }
Ed Tanous0bdda662023-08-03 17:27:34 -0700104 else if (element.first == "username")
Ed Tanous1abe55e2018-09-05 08:30:59 -0700105 {
106 userSession->username = *thisValue;
107 }
Ed Tanous0bdda662023-08-03 17:27:34 -0700108 else if (element.first == "client_id")
Sunitha Harish08bdcc72020-05-12 05:17:57 -0500109 {
110 userSession->clientId = *thisValue;
111 }
Ed Tanous0bdda662023-08-03 17:27:34 -0700112 else if (element.first == "client_ip")
Sunitha Harish92f68222020-05-28 05:09:09 -0500113 {
114 userSession->clientIp = *thisValue;
115 }
116
Ed Tanous1abe55e2018-09-05 08:30:59 -0700117 else
118 {
Ed Tanous62598e32023-07-17 17:06:25 -0700119 BMCWEB_LOG_ERROR(
120 "Got unexpected property reading persistent file: {}",
Ed Tanous0bdda662023-08-03 17:27:34 -0700121 element.first);
Ed Tanousdc511aa2020-10-21 12:33:42 -0700122 continue;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700123 }
124 }
Ed Tanousdc511aa2020-10-21 12:33:42 -0700125 // If any of these fields are missing, we can't restore the session, as
126 // we don't have enough information. These 4 fields have been present
127 // in every version of this file in bmcwebs history, so any file, even
128 // on upgrade, should have these present
129 if (userSession->uniqueId.empty() || userSession->username.empty() ||
130 userSession->sessionToken.empty() || userSession->csrfToken.empty())
131 {
Ed Tanous62598e32023-07-17 17:06:25 -0700132 BMCWEB_LOG_DEBUG("Session missing required security "
133 "information, refusing to restore");
Ed Tanousdc511aa2020-10-21 12:33:42 -0700134 return nullptr;
135 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700136
137 // For now, sessions that were persisted through a reboot get their idle
138 // timer reset. This could probably be overcome with a better
139 // understanding of wall clock time and steady timer time, possibly
140 // persisting values with wall clock time instead of steady timer, but
141 // the tradeoffs of all the corner cases involved are non-trivial, so
142 // this is done temporarily
143 userSession->lastUpdated = std::chrono::steady_clock::now();
Ed Tanous89cda632024-04-16 08:45:54 -0700144 userSession->sessionType = SessionType::Session;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700145
146 return userSession;
Kowalski, Kamil5cef0f72018-02-15 15:26:51 +0100147 }
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +0100148};
149
Ed Tanous3ce36882024-06-09 10:58:16 -0700150enum class MTLSCommonNameParseMode
151{
152 Invalid = 0,
153 // This section approximately matches Redfish AccountService
154 // CertificateMappingAttribute, plus bmcweb defined OEM ones.
155 // Note, IDs in this enum must be maintained between versions, as they are
156 // persisted to disk
157 Whole = 1,
158 CommonName = 2,
159 UserPrincipalName = 3,
160
161 // Intentional gap for future DMTF-defined enums
162
163 // OEM parsing modes for various OEMs
Ed Tanous3ce36882024-06-09 10:58:16 -0700164};
165
166inline MTLSCommonNameParseMode getMTLSCommonNameParseMode(std::string_view name)
167{
168 if (name == "CommonName")
169 {
170 return MTLSCommonNameParseMode::CommonName;
171 }
172 if (name == "Whole")
173 {
174 // Not yet supported
175 // return MTLSCommonNameParseMode::Whole;
176 }
177 if (name == "UserPrincipalName")
178 {
Malik Akbar Hashemi Rafsanjani4d7b5dd2025-02-26 13:14:30 -0800179 return MTLSCommonNameParseMode::UserPrincipalName;
Ed Tanous3ce36882024-06-09 10:58:16 -0700180 }
Ed Tanous3ce36882024-06-09 10:58:16 -0700181 return MTLSCommonNameParseMode::Invalid;
182}
183
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100184struct AuthConfigMethods
185{
Ed Tanous3281bcf2024-06-25 16:02:05 -0700186 // Authentication paths
Ed Tanous25b54db2024-04-17 15:40:31 -0700187 bool basic = BMCWEB_BASIC_AUTH;
188 bool sessionToken = BMCWEB_SESSION_AUTH;
189 bool xtoken = BMCWEB_XTOKEN_AUTH;
190 bool cookie = BMCWEB_COOKIE_AUTH;
191 bool tls = BMCWEB_MUTUAL_TLS_AUTH;
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100192
Ed Tanous3281bcf2024-06-25 16:02:05 -0700193 // Whether or not unauthenticated TLS should be accepted
194 // true = reject connections if mutual tls is not provided
195 // false = allow connection, and allow user to use other auth method
196 // Always default to false, because root certificates will not
197 // be provisioned at startup
198 bool tlsStrict = false;
199
Ed Tanous3ce36882024-06-09 10:58:16 -0700200 MTLSCommonNameParseMode mTLSCommonNameParsingMode =
201 getMTLSCommonNameParseMode(
202 BMCWEB_MUTUAL_TLS_COMMON_NAME_PARSING_DEFAULT);
203
Ed Tanous0bdda662023-08-03 17:27:34 -0700204 void fromJson(const nlohmann::json::object_t& j)
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100205 {
Ed Tanous0bdda662023-08-03 17:27:34 -0700206 for (const auto& element : j)
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100207 {
Ed Tanous0bdda662023-08-03 17:27:34 -0700208 const bool* value = element.second.get_ptr<const bool*>();
Ed Tanous3ce36882024-06-09 10:58:16 -0700209 if (value != nullptr)
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100210 {
Ed Tanous3ce36882024-06-09 10:58:16 -0700211 if (element.first == "XToken")
212 {
213 xtoken = *value;
214 }
215 else if (element.first == "Cookie")
216 {
217 cookie = *value;
218 }
219 else if (element.first == "SessionToken")
220 {
221 sessionToken = *value;
222 }
223 else if (element.first == "BasicAuth")
224 {
225 basic = *value;
226 }
227 else if (element.first == "TLS")
228 {
229 tls = *value;
230 }
Ed Tanous3281bcf2024-06-25 16:02:05 -0700231 else if (element.first == "TLSStrict")
232 {
233 tlsStrict = *value;
234 }
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100235 }
Ed Tanous3ce36882024-06-09 10:58:16 -0700236 const uint64_t* intValue =
237 element.second.get_ptr<const uint64_t*>();
238 if (intValue != nullptr)
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100239 {
Ed Tanous3ce36882024-06-09 10:58:16 -0700240 if (element.first == "MTLSCommonNameParseMode")
241 {
Malik Akbar Hashemi Rafsanjani4d7b5dd2025-02-26 13:14:30 -0800242 MTLSCommonNameParseMode tmpMTLSCommonNameParseMode =
243 static_cast<MTLSCommonNameParseMode>(*intValue);
244 if (tmpMTLSCommonNameParseMode <=
Malik Akbar Hashemi Rafsanjania4943692025-05-27 13:23:44 -0700245 MTLSCommonNameParseMode::UserPrincipalName)
Ed Tanous3ce36882024-06-09 10:58:16 -0700246 {
Malik Akbar Hashemi Rafsanjani4d7b5dd2025-02-26 13:14:30 -0800247 mTLSCommonNameParsingMode = tmpMTLSCommonNameParseMode;
Ed Tanous3ce36882024-06-09 10:58:16 -0700248 }
249 else
250 {
Malik Akbar Hashemi Rafsanjani4d7b5dd2025-02-26 13:14:30 -0800251 BMCWEB_LOG_WARNING(
Ed Tanous3ce36882024-06-09 10:58:16 -0700252 "Json value of {} was out of range of the enum. Ignoring",
253 *intValue);
254 }
255 }
Zbigniew Kurzynski501f1e52019-10-02 11:22:11 +0200256 }
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100257 }
258 }
259};
260
Ed Tanous1abe55e2018-09-05 08:30:59 -0700261class SessionStore
262{
263 public:
264 std::shared_ptr<UserSession> generateUserSession(
Ed Tanous26ccae32023-02-16 10:28:44 -0800265 std::string_view username, const boost::asio::ip::address& clientIp,
Ed Tanous89cda632024-04-16 08:45:54 -0700266 const std::optional<std::string>& clientId, SessionType sessionType,
Sunitha Harishd3239222021-02-24 15:33:29 +0530267 bool isConfigureSelfOnly = false)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700268 {
Ed Tanous1abe55e2018-09-05 08:30:59 -0700269 // Only need csrf tokens for cookie based auth, token doesn't matter
Ed Tanousb7f3a822024-06-05 08:45:25 -0700270 std::string sessionToken =
271 bmcweb::getRandomIdOfLength(sessionTokenSize);
272 std::string csrfToken = bmcweb::getRandomIdOfLength(sessionTokenSize);
273 std::string uniqueId = bmcweb::getRandomIdOfLength(10);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700274
Ed Tanousb7f3a822024-06-05 08:45:25 -0700275 //
276 if (sessionToken.empty() || csrfToken.empty() || uniqueId.empty())
Ed Tanous1abe55e2018-09-05 08:30:59 -0700277 {
Ed Tanousb7f3a822024-06-05 08:45:25 -0700278 BMCWEB_LOG_ERROR("Failed to generate session tokens");
279 return nullptr;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700280 }
Jiaqing Zhao41d61c82021-12-07 13:21:47 +0800281
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400282 auto session = std::make_shared<UserSession>(UserSession{
283 uniqueId,
284 sessionToken,
285 std::string(username),
286 csrfToken,
287 clientId,
288 redfish::ip_util::toString(clientIp),
289 std::chrono::steady_clock::now(),
290 sessionType,
291 false,
292 isConfigureSelfOnly,
293 "",
294 {}});
Patrick Williams41713dd2022-09-28 06:48:07 -0500295 auto it = authTokens.emplace(sessionToken, session);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700296 // Only need to write to disk if session isn't about to be destroyed.
Ed Tanous89cda632024-04-16 08:45:54 -0700297 needWrite = sessionType != SessionType::Basic &&
298 sessionType != SessionType::MutualTLS;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700299 return it.first->second;
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +0100300 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700301
Ed Tanous26ccae32023-02-16 10:28:44 -0800302 std::shared_ptr<UserSession> loginSessionByToken(std::string_view token)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700303 {
304 applySessionTimeouts();
Ed Tanous51dae672018-09-05 16:07:32 -0700305 if (token.size() != sessionTokenSize)
306 {
307 return nullptr;
308 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700309 auto sessionIt = authTokens.find(std::string(token));
310 if (sessionIt == authTokens.end())
311 {
312 return nullptr;
313 }
314 std::shared_ptr<UserSession> userSession = sessionIt->second;
315 userSession->lastUpdated = std::chrono::steady_clock::now();
316 return userSession;
317 }
318
Ed Tanous26ccae32023-02-16 10:28:44 -0800319 std::shared_ptr<UserSession> getSessionByUid(std::string_view uid)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700320 {
321 applySessionTimeouts();
322 // TODO(Ed) this is inefficient
323 auto sessionIt = authTokens.begin();
324 while (sessionIt != authTokens.end())
325 {
326 if (sessionIt->second->uniqueId == uid)
327 {
328 return sessionIt->second;
329 }
330 sessionIt++;
331 }
332 return nullptr;
333 }
334
Ed Tanousb5a76932020-09-29 16:16:58 -0700335 void removeSession(const std::shared_ptr<UserSession>& session)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700336 {
337 authTokens.erase(session->sessionToken);
338 needWrite = true;
339 }
340
Ed Tanous89cda632024-04-16 08:45:54 -0700341 std::vector<std::string> getAllUniqueIds()
Ed Tanous1abe55e2018-09-05 08:30:59 -0700342 {
343 applySessionTimeouts();
Ed Tanous89cda632024-04-16 08:45:54 -0700344 std::vector<std::string> ret;
Ed Tanous1abe55e2018-09-05 08:30:59 -0700345 ret.reserve(authTokens.size());
346 for (auto& session : authTokens)
347 {
Ed Tanous89cda632024-04-16 08:45:54 -0700348 ret.push_back(session.second->uniqueId);
349 }
350 return ret;
351 }
352
353 std::vector<std::string> getUniqueIdsBySessionType(SessionType type)
354 {
355 applySessionTimeouts();
356
357 std::vector<std::string> ret;
358 ret.reserve(authTokens.size());
359 for (auto& session : authTokens)
360 {
361 if (type == session.second->sessionType)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700362 {
Ed Tanous89cda632024-04-16 08:45:54 -0700363 ret.push_back(session.second->uniqueId);
Ed Tanous1abe55e2018-09-05 08:30:59 -0700364 }
365 }
366 return ret;
367 }
368
Ed Tanous89cda632024-04-16 08:45:54 -0700369 std::vector<std::shared_ptr<UserSession>> getSessions()
370 {
371 std::vector<std::shared_ptr<UserSession>> sessions;
372 sessions.reserve(authTokens.size());
373 for (auto& session : authTokens)
374 {
375 sessions.push_back(session.second);
376 }
377 return sessions;
378 }
379
Xie Ning9fa06f12022-06-29 18:27:47 +0800380 void removeSessionsByUsername(std::string_view username)
381 {
382 std::erase_if(authTokens, [username](const auto& value) {
383 if (value.second == nullptr)
384 {
385 return false;
386 }
387 return value.second->username == username;
388 });
389 }
390
Ravi Tejae518ef32024-05-16 10:33:08 -0500391 void removeSessionsByUsernameExceptSession(
392 std::string_view username, const std::shared_ptr<UserSession>& session)
393 {
394 std::erase_if(authTokens, [username, session](const auto& value) {
395 if (value.second == nullptr)
396 {
397 return false;
398 }
399
400 return value.second->username == username &&
401 value.second->uniqueId != session->uniqueId;
402 });
403 }
404
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100405 void updateAuthMethodsConfig(const AuthConfigMethods& config)
406 {
Zbigniew Kurzynski009c2a42019-11-14 13:37:15 +0100407 bool isTLSchanged = (authMethodsConfig.tls != config.tls);
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100408 authMethodsConfig = config;
409 needWrite = true;
Zbigniew Kurzynski009c2a42019-11-14 13:37:15 +0100410 if (isTLSchanged)
411 {
412 // recreate socket connections with new settings
Myung Bae92e11bf2025-01-31 09:22:23 -0500413 // NOLINTNEXTLINE(misc-include-cleaner)
Zbigniew Kurzynski009c2a42019-11-14 13:37:15 +0100414 std::raise(SIGHUP);
415 }
Zbigniew Kurzynski78158632019-11-05 12:57:37 +0100416 }
417
418 AuthConfigMethods& getAuthMethodsConfig()
419 {
420 return authMethodsConfig;
421 }
422
Ed Tanous9eb808c2022-01-25 10:19:23 -0800423 bool needsWrite() const
Ed Tanous1abe55e2018-09-05 08:30:59 -0700424 {
425 return needWrite;
426 }
Ed Tanous271584a2019-07-09 16:24:22 -0700427 int64_t getTimeoutInSeconds() const
Ed Tanous1abe55e2018-09-05 08:30:59 -0700428 {
Manojkiran Edaf2a4a602020-08-27 16:04:26 +0530429 return std::chrono::seconds(timeoutInSeconds).count();
430 }
431
432 void updateSessionTimeout(std::chrono::seconds newTimeoutInSeconds)
433 {
434 timeoutInSeconds = newTimeoutInSeconds;
435 needWrite = true;
Ed Tanous23a21a12020-07-25 04:45:05 +0000436 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700437
Ed Tanous1abe55e2018-09-05 08:30:59 -0700438 static SessionStore& getInstance()
439 {
440 static SessionStore sessionStore;
441 return sessionStore;
442 }
443
Ed Tanous1abe55e2018-09-05 08:30:59 -0700444 void applySessionTimeouts()
445 {
446 auto timeNow = std::chrono::steady_clock::now();
Manojkiran Edaf2a4a602020-08-27 16:04:26 +0530447 if (timeNow - lastTimeoutUpdate > std::chrono::seconds(1))
Ed Tanous1abe55e2018-09-05 08:30:59 -0700448 {
449 lastTimeoutUpdate = timeNow;
450 auto authTokensIt = authTokens.begin();
451 while (authTokensIt != authTokens.end())
452 {
453 if (timeNow - authTokensIt->second->lastUpdated >=
Manojkiran Edaf2a4a602020-08-27 16:04:26 +0530454 timeoutInSeconds)
Ed Tanous1abe55e2018-09-05 08:30:59 -0700455 {
456 authTokensIt = authTokens.erase(authTokensIt);
Ratan Gupta07386c62019-12-14 14:06:09 +0530457
Ed Tanous1abe55e2018-09-05 08:30:59 -0700458 needWrite = true;
459 }
460 else
461 {
462 authTokensIt++;
463 }
464 }
465 }
466 }
Gunnar Mills83cf8182020-11-11 15:37:34 -0600467
468 SessionStore(const SessionStore&) = delete;
469 SessionStore& operator=(const SessionStore&) = delete;
Ed Tanousecd6a3a2022-01-07 09:18:40 -0800470 SessionStore(SessionStore&&) = delete;
471 SessionStore& operator=(const SessionStore&&) = delete;
472 ~SessionStore() = default;
Gunnar Mills83cf8182020-11-11 15:37:34 -0600473
474 std::unordered_map<std::string, std::shared_ptr<UserSession>,
Ed Tanous724985f2024-06-05 09:19:06 -0700475 std::hash<std::string>, bmcweb::ConstantTimeCompare>
Gunnar Mills83cf8182020-11-11 15:37:34 -0600476 authTokens;
477
478 std::chrono::time_point<std::chrono::steady_clock> lastTimeoutUpdate;
479 bool needWrite{false};
480 std::chrono::seconds timeoutInSeconds;
481 AuthConfigMethods authMethodsConfig;
482
483 private:
Patrick Williams89492a12023-05-10 07:51:34 -0500484 SessionStore() : timeoutInSeconds(1800) {}
Kowalski, Kamil2b7981f2018-01-31 13:24:59 +0100485};
486
Ed Tanous1abe55e2018-09-05 08:30:59 -0700487} // namespace persistent_data