diff --git a/src/lib/utils/AuthSessionManager.cpp b/src/lib/utils/AuthSessionManager.cpp index 11d620282..6170fdb40 100644 --- a/src/lib/utils/AuthSessionManager.cpp +++ b/src/lib/utils/AuthSessionManager.cpp @@ -105,13 +105,18 @@ bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& t if(it != _map.end()) { _map[tok.id()] = Session{tok}; + LOG(Gen, Warn, "KEYCODE: Replacing session {} ", tok.id()); return true; } else if(_map.size() < _nusers) { _map[tok.id()] = Session{tok}; + LOG(Gen, Warn, "KEYCODE: Creating session {} ", tok.id()); return true; } + if(msg) + *msg = "KEYCODES: Not Enough Logins available for session"; + LOG(Gen, Error, "KEYCODES: Not Enough Logins available for session {}", tok.id()); return false; } diff --git a/src/lib/utils/AuthToken.cpp b/src/lib/utils/AuthToken.cpp index e1292b595..ebd753957 100644 --- a/src/lib/utils/AuthToken.cpp +++ b/src/lib/utils/AuthToken.cpp @@ -51,6 +51,42 @@ AuthSessionManager& session_manager() return mgr; } +bool requires_auth_session(const admin::BTSUser& user) +{ + bool needs_session = false; + //if the user can trade in any account or see market data, it needs a session + if(user.has_user_data() && + user.user_data().has_account_permissions() && + user.user_data().account_permissions().account_permissions_size()) + { + for(const auto& i: user.user_data().account_permissions().account_permissions()) + { + if(i.second.has_trading_permission() && i.second.trading_permission().has_permissions()) + { + needs_session = true; + break; + } + } + } + + if(user.has_user_data() && + user.user_data().has_exchange_user_data()) + { + if(user.user_data().exchange_user_data().has_cme_data()) + { + for(const auto& i: user.user_data().exchange_user_data().cme_data().md_permissions()) + { + if(i.enabled()) + { + needs_session = true; + break; + } + } + } + } + return needs_session; +} + AuthToken generate_token(const admin::BTSUser& user, std::string* msg) { api::user::TokenPayload payload; @@ -58,7 +94,9 @@ AuthToken generate_token(const admin::BTSUser& user, std::string* msg) payload.set_id(user.id()); if(user.name() == "bts") payload.set_wheel(true); - session_manager().add_or_replace_session(payload, msg); + + if(requires_auth_session(user)) + session_manager().add_or_replace_session(payload, msg); auto token = encrypt(payload.SerializeAsString()); bts_assert_d(token.size() < 255-8); AuthToken result; diff --git a/src/server/sparkd/user/AdminServiceServer.cpp b/src/server/sparkd/user/AdminServiceServer.cpp index 9e317e7fc..b795c7f39 100644 --- a/src/server/sparkd/user/AdminServiceServer.cpp +++ b/src/server/sparkd/user/AdminServiceServer.cpp @@ -155,7 +155,7 @@ void AdminServiceServer::get_filtered_admin_data( const api::Response& reply) { bts::api::user::TokenPayload toke; - if(bts::api::auth::decode_token(token, &toke)) + bts::api::auth::decode_token(token, &toke); { if(toke.wheel()) reply(_state); diff --git a/testing/manual/keycodes/keycode.txt b/testing/manual/keycodes/keycode.txt index ffd573a26..ed9535602 100644 --- a/testing/manual/keycodes/keycode.txt +++ b/testing/manual/keycodes/keycode.txt @@ -15,7 +15,7 @@ This will test our ability to generate and enforce keycodes. You should see keycode details printed to screen -4) Now test concurrent logins. Start a sparkd. +4) Now test concurrent logins. Start a sparkd. Make sure bts_2 and bts_3 have market data permission a) Start a spark -multiple login as bts and go to where you would see some market data b) Start another spark -multiple but log in as bts_2 and display some data c) Start a third spark -multiple, log in as bts_2 and display some data. @@ -37,5 +37,19 @@ You should see keycode details printed to screen d) remove the expired keycode you just generated by: rm ~/sparkdata/conf/keycode.conf e) restart sparkd, you should see data as normal in bts_2 + +6) Test admin vs trading logins +Note that an admin login is one that does not have trading permission in any account +AND does not have the ability to see any market data + + a) start sparkd again. make sure bts_2 and bts_3 have market data and trading permissions in webui + b) Start a spark -multiple login as bts_2 and go to where you would see some market data. You should see data + c) Start a webui and log in as bts_3, you should see data + d) close your shell and log out of web ui, now log in bts_3 into the webui and log in bts_2 in a shell ( + this is the reverse of the previous order), you should see a message in the shell about keycodes, but it will let you log in, just not see market data + e) from the webui, de-permission bts_3 from trading AND market data, + f) exit shell, log out of webui and kill sparkd, restart sparkd + + g)now try d again-- you should not get the same shell error