Add meson options for all authentication methods.
Add meson options to enabled/disabled authentication methods:
- basic-auth : For enable basic authentication, default is enabled
- session-auth : For enable session token authentication, default is
enabled
- xtoken-auth : For enable x-token authentication, default is enabled
- cookie-auth : For enabled cookie authentication, default is enabled
Signed-off-by: Alan Kuo <Alan_Kuo@quantatw.com>
Change-Id: I52e636f2534a14897cb57d35e563ea8841cc68b9
diff --git a/include/authorization.hpp b/include/authorization.hpp
index 0f73e96..c0a84b6 100644
--- a/include/authorization.hpp
+++ b/include/authorization.hpp
@@ -34,6 +34,7 @@
}
}
+#ifdef BMCWEB_ENABLE_BASIC_AUTHENTICATION
static std::shared_ptr<persistent_data::UserSession>
performBasicAuth(const boost::asio::ip::address& clientIp,
std::string_view auth_header)
@@ -81,7 +82,9 @@
user, persistent_data::PersistenceType::SINGLE_REQUEST,
isConfigureSelfOnly, clientIp.to_string());
}
+#endif
+#ifdef BMCWEB_ENABLE_SESSION_AUTHENTICATION
static std::shared_ptr<persistent_data::UserSession>
performTokenAuth(std::string_view auth_header)
{
@@ -92,7 +95,9 @@
persistent_data::SessionStore::getInstance().loginSessionByToken(token);
return session;
}
+#endif
+#ifdef BMCWEB_ENABLE_XTOKEN_AUTHENTICATION
static std::shared_ptr<persistent_data::UserSession>
performXtokenAuth(const crow::Request& req)
{
@@ -107,7 +112,9 @@
persistent_data::SessionStore::getInstance().loginSessionByToken(token);
return session;
}
+#endif
+#ifdef BMCWEB_ENABLE_COOKIE_AUTHENTICATION
static std::shared_ptr<persistent_data::UserSession>
performCookieAuth(const crow::Request& req)
{
@@ -164,6 +171,7 @@
#endif
return session;
}
+#endif
#ifdef BMCWEB_ENABLE_MUTUAL_TLS_AUTHENTICATION
static std::shared_ptr<persistent_data::UserSession>
@@ -250,14 +258,18 @@
req.session = performTLSAuth(req, res, session);
}
#endif
+#ifdef BMCWEB_ENABLE_XTOKEN_AUTHENTICATION
if (req.session == nullptr && authMethodsConfig.xtoken)
{
req.session = performXtokenAuth(req);
}
+#endif
+#ifdef BMCWEB_ENABLE_COOKIE_AUTHENTICATION
if (req.session == nullptr && authMethodsConfig.cookie)
{
req.session = performCookieAuth(req);
}
+#endif
if (req.session == nullptr)
{
std::string_view authHeader = req.getHeaderValue("Authorization");
@@ -267,12 +279,16 @@
if (boost::starts_with(authHeader, "Token ") &&
authMethodsConfig.sessionToken)
{
+#ifdef BMCWEB_ENABLE_SESSION_AUTHENTICATION
req.session = performTokenAuth(authHeader);
+#endif
}
else if (boost::starts_with(authHeader, "Basic ") &&
authMethodsConfig.basic)
{
+#ifdef BMCWEB_ENABLE_BASIC_AUTHENTICATION
req.session = performBasicAuth(req.ipAddress, authHeader);
+#endif
}
}
}