diff --git a/src/lib/utils/AuthSessionManager.cpp b/src/lib/utils/AuthSessionManager.cpp index 8b1b74438..2e22b823d 100644 --- a/src/lib/utils/AuthSessionManager.cpp +++ b/src/lib/utils/AuthSessionManager.cpp @@ -80,7 +80,7 @@ bool AuthSessionManager::validate_ip_port(const bts::config::KeyCode& kc) return portgood && ipgood; } -bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& tok, const admin::BTSUser& user, std::string* msg) +bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& tok, const std::string& username, std::string* msg) { if(tok.wheel()) return true; @@ -105,18 +105,18 @@ bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& t if(it != _map.end()) { _map[tok.id()] = Session{tok}; - LOG(User, Warn, "KEYCODE: Replacing session {} user:{}:{} ", tok.id(), user.id(), user.name()); + LOG(User, Warn, "KEYCODE: Replacing session {} user:{} ", tok.id(), username); return true; } else if(_map.size() < _nusers) { _map[tok.id()] = Session{tok}; - LOG(User, Warn, "KEYCODE: Creating session {} user:{}:{}", tok.id(), user.id(), user.name()); + LOG(User, Warn, "KEYCODE: Creating session {} user:{}", tok.id(), username); return true; } if(msg) *msg = "KEYCODES: Not Enough Logins available for session"; - LOG(User, Error, "KEYCODES: Not Enough Logins available for session {} user:{}:{}", tok.id(), user.id(), user.name()); + LOG(User, Error, "KEYCODES: Not Enough Logins available for session {} user:{}", tok.id(), username); return false; } @@ -134,6 +134,10 @@ bool AuthSessionManager::check_session(const api::user::TokenPayload& tok) bool same_token = _concurrent || (tok.date() == it->second.token.date()); return not_expired && same_token; } + else //not in map, try to login in case server booted + { + return add_or_replace_session(tok); + } } return false; } diff --git a/src/lib/utils/AuthSessionManager.h b/src/lib/utils/AuthSessionManager.h index fa68d097e..1be135bb0 100644 --- a/src/lib/utils/AuthSessionManager.h +++ b/src/lib/utils/AuthSessionManager.h @@ -19,7 +19,7 @@ class AuthSessionManager public: AuthSessionManager(); - bool add_or_replace_session(const api::user::TokenPayload& tok, const admin::BTSUser& user, std::string* msg = nullptr); + bool add_or_replace_session(const api::user::TokenPayload& tok, const std::string& username = "", std::string* msg = nullptr); bool check_session(const api::user::TokenPayload& tok); private: diff --git a/src/lib/utils/AuthToken.cpp b/src/lib/utils/AuthToken.cpp index 9c062c592..09095b883 100644 --- a/src/lib/utils/AuthToken.cpp +++ b/src/lib/utils/AuthToken.cpp @@ -89,7 +89,7 @@ AuthToken generate_token(const admin::BTSUser& user, std::string* msg) payload.set_wheel(true); if(requires_auth_session(user)) - session_manager().add_or_replace_session(payload, user, msg); + session_manager().add_or_replace_session(payload, user.name(), msg); auto token = encrypt(payload.SerializeAsString()); bts_assert_d(token.size() < 255-8); AuthToken result; diff --git a/testing/manual/keycodes/keycode.txt b/testing/manual/keycodes/keycode.txt index ed9535602..43106e45c 100644 --- a/testing/manual/keycodes/keycode.txt +++ b/testing/manual/keycodes/keycode.txt @@ -23,7 +23,8 @@ You should see keycode details printed to screen -You should see the data zero out on the first instance logged in as bts_2 and data ticking on the bts instance as well as the second bts_2 instance - d)Kill your sparkd + d) Kill your sparkd but leave your shells open + e) bring sparkd back up, you should see market data in the shell logged in as bts AND one of the other shells 4.5) For extra credit generate a keycode with -allow_concurrent and make sure we don't zero the market data for concurrent logins