diff options
author | Ed Tanous <edtanous@google.com> | 2022-08-03 03:07:54 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-10-07 21:06:08 +0300 |
commit | bb759e3aeaadfec9f3aac4485f253bcc8a523e4c (patch) | |
tree | 52e48fbdd2a77c2c6ba583a2d41750e265336a77 /include/sessions.hpp | |
parent | 40e4f380d645c6bbe6bd8050e501203798a0c488 (diff) | |
download | bmcweb-bb759e3aeaadfec9f3aac4485f253bcc8a523e4c.tar.xz |
Move ClientID parameter out of OEM
In 2022.2, Redfish added support for the Context parameter on the
Session Resource. This parameter has the same function that the
OemSession.ClientId field served. This commit moves all the existing
ClientId code to produce Context as well.
Functionally, this has one important difference, in that Context in
Redfish is optionally provided by the user, which means we need to omit
it if not given by the user. The old implementation left it set to
empty string ("").
Because of this, a few minor interfaces need to change to use
std::optional. Existing uses of clientId are moved to using
value_or("") to keep the same behavior as before.
Tested:
curl --insecure -X POST -d "{\"UserName\": \"root\", \"Password\":
\"0penBmc\"}" https://192.168.7.2/redfish/v1/SessionService/Sessions
Returns a Session object with no Context key present
curl --insecure -X POST -d "{\"UserName\": \"root\", \"Password\":
\"0penBmc\", \"Context\": \"Foobar\"}"
https://192.168.7.2/redfish/v1/SessionService/Sessions
Returns a Session object with:
"Context": "Foobar"
Subsequent Gets of /redfish/v1/SessionService/Sessions/<sid>
return the same session objects, both with and without Context.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I4df358623f93f3e6cb659e99970ad909cefebc62
Diffstat (limited to 'include/sessions.hpp')
-rw-r--r-- | include/sessions.hpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/include/sessions.hpp b/include/sessions.hpp index 79b344ae4d..94a0755e7f 100644 --- a/include/sessions.hpp +++ b/include/sessions.hpp @@ -8,6 +8,7 @@ #include <utils/ip_utils.hpp> #include <csignal> +#include <optional> #include <random> #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE #include <ibm/locks.hpp> @@ -33,7 +34,7 @@ struct UserSession std::string sessionToken; std::string username; std::string csrfToken; - std::string clientId; + std::optional<std::string> clientId; std::string clientIp; std::chrono::time_point<std::chrono::steady_clock> lastUpdated; PersistenceType persistence{PersistenceType::TIMEOUT}; @@ -88,12 +89,10 @@ struct UserSession { userSession->username = *thisValue; } -#ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE else if (element.key() == "client_id") { userSession->clientId = *thisValue; } -#endif else if (element.key() == "client_ip") { userSession->clientIp = *thisValue; @@ -204,7 +203,7 @@ class SessionStore std::shared_ptr<UserSession> generateUserSession( const std::string_view username, const boost::asio::ip::address& clientIp, - const std::string_view clientId, + const std::optional<std::string>& clientId, PersistenceType persistence = PersistenceType::TIMEOUT, bool isConfigureSelfOnly = false) { @@ -255,8 +254,8 @@ class SessionStore } auto session = std::make_shared<UserSession>(UserSession{ - uniqueId, sessionToken, std::string(username), csrfToken, - std::string(clientId), redfish::ip_util::toString(clientIp), + uniqueId, sessionToken, std::string(username), csrfToken, clientId, + redfish::ip_util::toString(clientIp), std::chrono::steady_clock::now(), persistence, false, isConfigureSelfOnly}); auto it = authTokens.emplace(sessionToken, session); |