Fixed case where a non-super user shell denied market data after bring left up through a server restart

This commit is contained in:
Kevin Darby committed 2019-09-16 16:28:53 -04:00
1 parent 7b833087e5
commit baaa3c4f98
4 files changed
+12 -7

No files matched your search

+8 -4
View File
@@ -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;
}
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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;
+2 -1
View File
@@ -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