From e436008377fbcf287be02c9e9e1b59c6627d7673 Mon Sep 17 00:00:00 2001 From: Sunitha Harish Date: Mon, 28 Sep 2020 02:10:59 -0500 Subject: Redfish Session : Support ClientOriginIPAddress This commit implements the ClientOriginIPAddress property on the session resource Tested by: 1. Create session POST https://${bmc}/redfish/v1/SessionService/Sessions -d '{"UserName":<>, "Password":<>}' 2. Check the session gets updated with the ClientOriginIPAddress GET https://${bmc}/redfish/v1/SessionService/Sessions/ 3. Redfish validator passed Signed-off-by: Sunitha Harish Change-Id: I4c5c6f651bb6faec0cb1b1b78d9da593ecb85ff0 --- http/http_connection.h | 4 ++++ http/http_request.h | 2 ++ redfish-core/lib/redfish_sessions.hpp | 9 +++++---- static/redfish/v1/JsonSchemas/OemSession/index.json | 6 ------ static/redfish/v1/schema/OemSession_v1.xml | 4 ---- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/http/http_connection.h b/http/http_connection.h index ddedaea0ea..ca3314b7e0 100644 --- a/http/http_connection.h +++ b/http/http_connection.h @@ -317,6 +317,10 @@ class Connection : } } + // Copy the client's IP address + req->ipAddress = + boost::beast::get_lowest_layer(adaptor).remote_endpoint().address(); + BMCWEB_LOG_INFO << "Request: " << " " << this << " HTTP/" << req->version() / 10 << "." << req->version() % 10 << ' ' << req->methodString() diff --git a/http/http_request.h b/http/http_request.h index c16036830c..10aabc3f90 100644 --- a/http/http_request.h +++ b/http/http_request.h @@ -5,6 +5,7 @@ #include "sessions.hpp" #include +#include #include #include #include @@ -25,6 +26,7 @@ struct Request const std::string& body; boost::asio::io_context* ioService{}; + boost::asio::ip::address ipAddress; std::shared_ptr session; diff --git a/redfish-core/lib/redfish_sessions.hpp b/redfish-core/lib/redfish_sessions.hpp index e3259895d2..1797ab9803 100644 --- a/redfish-core/lib/redfish_sessions.hpp +++ b/redfish-core/lib/redfish_sessions.hpp @@ -60,15 +60,15 @@ class Sessions : public Node res.jsonValue["UserName"] = session->username; res.jsonValue["@odata.id"] = "/redfish/v1/SessionService/Sessions/" + session->uniqueId; - res.jsonValue["@odata.type"] = "#Session.v1_0_2.Session"; + res.jsonValue["@odata.type"] = "#Session.v1_3_0.Session"; res.jsonValue["Name"] = "User Session"; res.jsonValue["Description"] = "Manager User Session"; + res.jsonValue["ClientOriginIPAddress"] = session->clientIp; res.jsonValue["Oem"]["OpenBMC"]["@odata.type"] = "#OemSession.v1_0_0.Session"; #ifdef BMCWEB_ENABLE_IBM_MANAGEMENT_CONSOLE res.jsonValue["Oem"]["OpenBMC"]["ClientID"] = session->clientId; #endif - res.jsonValue["Oem"]["OpenBMC"]["ClientOriginIP"] = session->clientIp; res.end(); } @@ -174,7 +174,6 @@ class SessionCollection : public Node std::string password; std::optional oemObject; std::string clientId; - std::string clientIp; if (!json_util::readJson(req, res, "UserName", username, "Password", password, "Oem", oemObject)) { @@ -226,12 +225,14 @@ class SessionCollection : public Node } } #endif + BMCWEB_LOG_DEBUG << "Session created from IPAddress: " + << req.ipAddress.to_string(); // User is authenticated - create session std::shared_ptr session = persistent_data::SessionStore::getInstance().generateUserSession( username, persistent_data::PersistenceType::TIMEOUT, - isConfigureSelfOnly, clientId, clientIp); + isConfigureSelfOnly, clientId, req.ipAddress.to_string()); res.addHeader("X-Auth-Token", session->sessionToken); res.addHeader("Location", "/redfish/v1/SessionService/Sessions/" + session->uniqueId); diff --git a/static/redfish/v1/JsonSchemas/OemSession/index.json b/static/redfish/v1/JsonSchemas/OemSession/index.json index c80e34003c..8eefd952f3 100644 --- a/static/redfish/v1/JsonSchemas/OemSession/index.json +++ b/static/redfish/v1/JsonSchemas/OemSession/index.json @@ -28,12 +28,6 @@ "readonly": true, "type" : "string" }, - "ClientOriginIP" : { - "description": "The IP address where the Session was created from.", - "longDescription": "This property shall contain the IP address where the client created the session from.", - "readonly": true, - "type": "string" - }, "type": "object" } } diff --git a/static/redfish/v1/schema/OemSession_v1.xml b/static/redfish/v1/schema/OemSession_v1.xml index cc74848b81..f02f8617eb 100644 --- a/static/redfish/v1/schema/OemSession_v1.xml +++ b/static/redfish/v1/schema/OemSession_v1.xml @@ -32,10 +32,6 @@ - - - - -- cgit v1.2.3