Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 3 | #pragma once |
| 4 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 5 | #include "bmcweb_config.h" |
| 6 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 7 | #include "http_response.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 8 | #include "logging.hpp" |
| 9 | #include "ossl_random.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 10 | #include "pam_authenticate.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 11 | #include "sessions.hpp" |
| 12 | #include "utility.hpp" |
| 13 | #include "utils/ip_utils.hpp" |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 14 | #include "webroutes.hpp" |
| 15 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 16 | #include <security/_pam_types.h> |
| 17 | |
| 18 | #include <boost/asio/ip/address.hpp> |
| 19 | #include <boost/beast/http/field.hpp> |
| 20 | #include <boost/beast/http/message.hpp> |
| 21 | #include <boost/beast/http/verb.hpp> |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 22 | #include <boost/container/flat_set.hpp> |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 23 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 24 | #include <cstddef> |
| 25 | #include <cstring> |
| 26 | #include <memory> |
| 27 | #include <optional> |
| 28 | #include <string> |
| 29 | #include <string_view> |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 30 | #include <utility> |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 31 | |
| 32 | namespace crow |
| 33 | { |
| 34 | |
Nan Zhou | d055a34 | 2022-05-25 01:15:34 +0000 | [diff] [blame] | 35 | namespace authentication |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 36 | { |
| 37 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 38 | inline std::shared_ptr<persistent_data::UserSession> performBasicAuth( |
| 39 | const boost::asio::ip::address& clientIp, std::string_view authHeader) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 40 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 41 | BMCWEB_LOG_DEBUG("[AuthMiddleware] Basic authentication"); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 42 | |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 43 | if (!authHeader.starts_with("Basic ")) |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 44 | { |
| 45 | return nullptr; |
| 46 | } |
| 47 | |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 48 | std::string_view param = authHeader.substr(strlen("Basic ")); |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 49 | std::string authData; |
| 50 | |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 51 | if (!crow::utility::base64Decode(param, authData)) |
| 52 | { |
| 53 | return nullptr; |
| 54 | } |
| 55 | std::size_t separator = authData.find(':'); |
| 56 | if (separator == std::string::npos) |
| 57 | { |
| 58 | return nullptr; |
| 59 | } |
| 60 | |
| 61 | std::string user = authData.substr(0, separator); |
| 62 | separator += 1; |
| 63 | if (separator > authData.size()) |
| 64 | { |
| 65 | return nullptr; |
| 66 | } |
| 67 | std::string pass = authData.substr(separator); |
| 68 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 69 | BMCWEB_LOG_DEBUG("[AuthMiddleware] Authenticating user: {}", user); |
| 70 | BMCWEB_LOG_DEBUG("[AuthMiddleware] User IPAddress: {}", |
| 71 | clientIp.to_string()); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 72 | |
Ravi Teja | 2ccce1f | 2024-08-10 04:05:36 -0500 | [diff] [blame] | 73 | int pamrc = pamAuthenticateUser(user, pass, std::nullopt); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 74 | bool isConfigureSelfOnly = pamrc == PAM_NEW_AUTHTOK_REQD; |
| 75 | if ((pamrc != PAM_SUCCESS) && !isConfigureSelfOnly) |
| 76 | { |
| 77 | return nullptr; |
| 78 | } |
| 79 | |
Ed Tanous | 89cda63 | 2024-04-16 08:45:54 -0700 | [diff] [blame] | 80 | // Attempt to locate an existing Basic Auth session from the same ip address |
| 81 | // and user |
| 82 | for (auto& session : |
| 83 | persistent_data::SessionStore::getInstance().getSessions()) |
| 84 | { |
| 85 | if (session->sessionType != persistent_data::SessionType::Basic) |
| 86 | { |
| 87 | continue; |
| 88 | } |
| 89 | if (session->clientIp != redfish::ip_util::toString(clientIp)) |
| 90 | { |
| 91 | continue; |
| 92 | } |
| 93 | if (session->username != user) |
| 94 | { |
| 95 | continue; |
| 96 | } |
| 97 | return session; |
| 98 | } |
| 99 | |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 100 | return persistent_data::SessionStore::getInstance().generateUserSession( |
Ed Tanous | 89cda63 | 2024-04-16 08:45:54 -0700 | [diff] [blame] | 101 | user, clientIp, std::nullopt, persistent_data::SessionType::Basic, |
| 102 | isConfigureSelfOnly); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 105 | inline std::shared_ptr<persistent_data::UserSession> performTokenAuth( |
| 106 | std::string_view authHeader) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 107 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 108 | BMCWEB_LOG_DEBUG("[AuthMiddleware] Token authentication"); |
Ed Tanous | 11ba397 | 2022-07-11 09:50:41 -0700 | [diff] [blame] | 109 | if (!authHeader.starts_with("Token ")) |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 110 | { |
| 111 | return nullptr; |
| 112 | } |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 113 | std::string_view token = authHeader.substr(strlen("Token ")); |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 114 | auto sessionOut = |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 115 | persistent_data::SessionStore::getInstance().loginSessionByToken(token); |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 116 | return sessionOut; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 119 | inline std::shared_ptr<persistent_data::UserSession> performXtokenAuth( |
| 120 | const boost::beast::http::header<true>& reqHeader) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 121 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 122 | BMCWEB_LOG_DEBUG("[AuthMiddleware] X-Auth-Token authentication"); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 123 | |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 124 | std::string_view token = reqHeader["X-Auth-Token"]; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 125 | if (token.empty()) |
| 126 | { |
| 127 | return nullptr; |
| 128 | } |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 129 | auto sessionOut = |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 130 | persistent_data::SessionStore::getInstance().loginSessionByToken(token); |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 131 | return sessionOut; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 134 | inline std::shared_ptr<persistent_data::UserSession> performCookieAuth( |
| 135 | boost::beast::http::verb method [[maybe_unused]], |
| 136 | const boost::beast::http::header<true>& reqHeader) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 137 | { |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 138 | using headers = boost::beast::http::header<true>; |
| 139 | std::pair<headers::const_iterator, headers::const_iterator> cookies = |
| 140 | reqHeader.equal_range(boost::beast::http::field::cookie); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 141 | |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 142 | for (auto it = cookies.first; it != cookies.second; it++) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 143 | { |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 144 | std::string_view cookieValue = it->value(); |
| 145 | BMCWEB_LOG_DEBUG("Checking cookie {}", cookieValue); |
| 146 | auto startIndex = cookieValue.find("SESSION="); |
| 147 | if (startIndex == std::string::npos) |
| 148 | { |
| 149 | BMCWEB_LOG_DEBUG( |
| 150 | "Cookie was present, but didn't look like a session {}", |
| 151 | cookieValue); |
| 152 | continue; |
| 153 | } |
| 154 | startIndex += sizeof("SESSION=") - 1; |
| 155 | auto endIndex = cookieValue.find(';', startIndex); |
| 156 | if (endIndex == std::string::npos) |
| 157 | { |
| 158 | endIndex = cookieValue.size(); |
| 159 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 160 | std::string_view authKey = |
| 161 | cookieValue.substr(startIndex, endIndex - startIndex); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 162 | |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 163 | std::shared_ptr<persistent_data::UserSession> sessionOut = |
| 164 | persistent_data::SessionStore::getInstance().loginSessionByToken( |
| 165 | authKey); |
| 166 | if (sessionOut == nullptr) |
| 167 | { |
| 168 | return nullptr; |
| 169 | } |
| 170 | sessionOut->cookieAuth = true; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 171 | |
Ed Tanous | 576db69 | 2024-05-10 16:37:56 -0700 | [diff] [blame] | 172 | if constexpr (!BMCWEB_INSECURE_DISABLE_CSRF) |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 173 | { |
| 174 | // RFC7231 defines methods that need csrf protection |
| 175 | if (method != boost::beast::http::verb::get) |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 176 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 177 | std::string_view csrf = reqHeader["X-XSRF-TOKEN"]; |
| 178 | // Make sure both tokens are filled |
| 179 | if (csrf.empty() || sessionOut->csrfToken.empty()) |
| 180 | { |
| 181 | return nullptr; |
| 182 | } |
| 183 | |
| 184 | if (csrf.size() != persistent_data::sessionTokenSize) |
| 185 | { |
| 186 | return nullptr; |
| 187 | } |
| 188 | // Reject if csrf token not available |
Ed Tanous | 724985f | 2024-06-05 09:19:06 -0700 | [diff] [blame] | 189 | if (!bmcweb::constantTimeStringCompare(csrf, |
| 190 | sessionOut->csrfToken)) |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 191 | { |
| 192 | return nullptr; |
| 193 | } |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 194 | } |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 195 | } |
Ed Tanous | 3eaecac | 2024-05-08 16:26:24 -0700 | [diff] [blame] | 196 | return sessionOut; |
Ed Tanous | 9f217c2 | 2024-04-19 17:22:43 -0700 | [diff] [blame] | 197 | } |
| 198 | return nullptr; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 201 | inline std::shared_ptr<persistent_data::UserSession> performTLSAuth( |
| 202 | Response& res, const std::shared_ptr<persistent_data::UserSession>& session) |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 203 | { |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 204 | if (session != nullptr) |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 205 | { |
Ed Tanous | 994fd86 | 2023-06-06 13:37:03 -0700 | [diff] [blame] | 206 | res.addHeader(boost::beast::http::field::set_cookie, |
| 207 | "IsAuthenticated=true; Secure"); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 208 | BMCWEB_LOG_DEBUG( |
| 209 | " TLS session: {} with cookie will be used for this request.", |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 210 | session->uniqueId); |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 211 | } |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 212 | |
| 213 | return session; |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 214 | } |
| 215 | |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 216 | // checks if request can be forwarded without authentication |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 217 | inline bool isOnAllowlist(std::string_view url, boost::beast::http::verb method) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 218 | { |
Ed Tanous | 3822150 | 2024-06-03 12:19:38 -0700 | [diff] [blame] | 219 | // Handle the case where the router registers routes as both ending with / |
| 220 | // and not. |
VinceChang6637 | 8f5df13 | 2024-06-14 17:13:16 +0800 | [diff] [blame] | 221 | if (url.ends_with('/') && url != "/") |
Ed Tanous | 3822150 | 2024-06-03 12:19:38 -0700 | [diff] [blame] | 222 | { |
| 223 | url.remove_suffix(1); |
| 224 | } |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 225 | if (boost::beast::http::verb::get == method) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 226 | { |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 227 | if ((url == "/redfish") || // |
| 228 | (url == "/redfish/v1") || // |
Ed Tanous | 3822150 | 2024-06-03 12:19:38 -0700 | [diff] [blame] | 229 | (url == "/redfish/v1/odata") || // |
| 230 | (url == "/redfish/v1/$metadata")) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 231 | { |
| 232 | return true; |
| 233 | } |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 234 | if (crow::webroutes::routes.find(std::string(url)) != |
Ed Tanous | d4d2579 | 2020-09-29 15:15:03 -0700 | [diff] [blame] | 235 | crow::webroutes::routes.end()) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 236 | { |
| 237 | return true; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // it's allowed to POST on session collection & login without |
| 242 | // authentication |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 243 | if (boost::beast::http::verb::post == method) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 244 | { |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 245 | if ((url == "/redfish/v1/SessionService/Sessions") || |
Ed Tanous | e76cd86 | 2022-03-14 09:12:00 -0700 | [diff] [blame] | 246 | (url == "/redfish/v1/SessionService/Sessions/Members") || |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 247 | (url == "/login")) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 248 | { |
| 249 | return true; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | return false; |
| 254 | } |
| 255 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 256 | inline std::shared_ptr<persistent_data::UserSession> authenticate( |
| 257 | const boost::asio::ip::address& ipAddress [[maybe_unused]], |
| 258 | Response& res [[maybe_unused]], |
| 259 | boost::beast::http::verb method [[maybe_unused]], |
| 260 | const boost::beast::http::header<true>& reqHeader, |
| 261 | [[maybe_unused]] const std::shared_ptr<persistent_data::UserSession>& |
| 262 | session) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 263 | { |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 264 | const persistent_data::AuthConfigMethods& authMethodsConfig = |
| 265 | persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 266 | |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 267 | std::shared_ptr<persistent_data::UserSession> sessionOut = nullptr; |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 268 | if constexpr (BMCWEB_MUTUAL_TLS_AUTH) |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 269 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 270 | if (authMethodsConfig.tls) |
| 271 | { |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 272 | sessionOut = performTLSAuth(res, session); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 273 | } |
James Feist | 6964c98 | 2020-07-28 16:10:23 -0700 | [diff] [blame] | 274 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 275 | if constexpr (BMCWEB_XTOKEN_AUTH) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 276 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 277 | if (sessionOut == nullptr && authMethodsConfig.xtoken) |
| 278 | { |
| 279 | sessionOut = performXtokenAuth(reqHeader); |
| 280 | } |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 281 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 282 | if constexpr (BMCWEB_COOKIE_AUTH) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 283 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 284 | if (sessionOut == nullptr && authMethodsConfig.cookie) |
| 285 | { |
| 286 | sessionOut = performCookieAuth(method, reqHeader); |
| 287 | } |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 288 | } |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 289 | std::string_view authHeader = reqHeader["Authorization"]; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 290 | BMCWEB_LOG_DEBUG("authHeader={}", authHeader); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 291 | if constexpr (BMCWEB_SESSION_AUTH) |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 292 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 293 | if (sessionOut == nullptr && authMethodsConfig.sessionToken) |
| 294 | { |
| 295 | sessionOut = performTokenAuth(authHeader); |
| 296 | } |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 297 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 298 | if constexpr (BMCWEB_BASIC_AUTH) |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 299 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 300 | if (sessionOut == nullptr && authMethodsConfig.basic) |
| 301 | { |
| 302 | sessionOut = performBasicAuth(ipAddress, authHeader); |
| 303 | } |
John Edward Broadbent | 97a056a | 2021-09-10 14:56:19 -0700 | [diff] [blame] | 304 | } |
| 305 | if (sessionOut != nullptr) |
| 306 | { |
| 307 | return sessionOut; |
| 308 | } |
| 309 | |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 310 | return nullptr; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Nan Zhou | d055a34 | 2022-05-25 01:15:34 +0000 | [diff] [blame] | 313 | } // namespace authentication |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 314 | } // namespace crow |