From 6997aed9bd45d30d5df4335d301504a4f347f926 Mon Sep 17 00:00:00 2001 From: Kevin Darby Date: Tue, 2 Jul 2019 15:05:23 -0400 Subject: [PATCH 1/4] fixed SPARK-2524, allowing admin logins to not require a keycode session --- src/lib/utils/AuthSessionManager.cpp | 5 +++ src/lib/utils/AuthToken.cpp | 40 ++++++++++++++++++- src/server/sparkd/user/AdminServiceServer.cpp | 2 +- testing/manual/keycodes/keycode.txt | 16 +++++++- 4 files changed, 60 insertions(+), 3 deletions(-) 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 From f2f06d76dedffb4430a8767423b34f938287a817 Mon Sep 17 00:00:00 2001 From: Kevin Darby Date: Tue, 2 Jul 2019 17:43:28 -0400 Subject: [PATCH 2/4] PR feedback --- src/lib/utils/AuthSessionManager.cpp | 8 ++++---- src/lib/utils/AuthToken.cpp | 13 +++---------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/lib/utils/AuthSessionManager.cpp b/src/lib/utils/AuthSessionManager.cpp index 6170fdb40..dddb415fd 100644 --- a/src/lib/utils/AuthSessionManager.cpp +++ b/src/lib/utils/AuthSessionManager.cpp @@ -86,7 +86,7 @@ bool AuthSessionManager::add_or_replace_session(const api::user::TokenPayload& t return true; if(datetime::ll_diff_in_us(datetime::ll_now(), _expiration) < 0) { - LOG(Gen,Error, "Your BTS Keycode is expired!"); + LOG(User,Error, "Your BTS Keycode is expired!"); if(msg) *msg = "Your BTS Keycode is EXPIRED! Please contact sales@bluetradesys.com"; return false; @@ -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(Gen, Warn, "KEYCODE: Replacing session {} ", tok.id()); + LOG(User, 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()); + LOG(User, 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()); + LOG(User, 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 ebd753957..2423638a8 100644 --- a/src/lib/utils/AuthToken.cpp +++ b/src/lib/utils/AuthToken.cpp @@ -53,7 +53,6 @@ AuthSessionManager& session_manager() 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() && @@ -62,10 +61,7 @@ bool requires_auth_session(const admin::BTSUser& user) 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; - } + return true; } } @@ -77,14 +73,11 @@ bool requires_auth_session(const admin::BTSUser& user) for(const auto& i: user.user_data().exchange_user_data().cme_data().md_permissions()) { if(i.enabled()) - { - needs_session = true; - break; - } + return true; } } } - return needs_session; + return false; } AuthToken generate_token(const admin::BTSUser& user, std::string* msg) From e7a941212464b97603895e236e01998fe55d73c4 Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Mon, 8 Jul 2019 12:21:39 -0400 Subject: [PATCH 3/4] Updated release notes. --- doc/user/content/release_notes/_index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md index 5933e4fd3..71aa59b71 100644 --- a/doc/user/content/release_notes/_index.md +++ b/doc/user/content/release_notes/_index.md @@ -9,6 +9,7 @@ insert_anchor_links = "right" - In the ladder made last trade more distinctive when overlayed on the volumn column - In the ladder, corrected display of volume tool tip - In the ladder, changed the consolidation of last trade to consider only the price ignoring aggressor changes + ## 2.5.0 ### User Visible Changes - Added loss limit risk check From f4395ef8336e616545616292e4c10ba0c22b6661 Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Mon, 8 Jul 2019 12:26:27 -0400 Subject: [PATCH 4/4] Updated release notes. --- doc/user/content/release_notes/_index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md index 71aa59b71..ffb88aee2 100644 --- a/doc/user/content/release_notes/_index.md +++ b/doc/user/content/release_notes/_index.md @@ -9,7 +9,9 @@ insert_anchor_links = "right" - In the ladder made last trade more distinctive when overlayed on the volumn column - In the ladder, corrected display of volume tool tip - In the ladder, changed the consolidation of last trade to consider only the price ignoring aggressor changes - +### Internal Changes + - Ensure that admin logins are always allowed to login, regardless of keycode status. + ## 2.5.0 ### User Visible Changes - Added loss limit risk check