Properly handled http headers for subsonic API. ref #119
This commit is contained in:
@@ -29,7 +29,7 @@ namespace Auth
|
||||
{
|
||||
|
||||
HttpHeadersEnvService::HttpHeadersEnvService()
|
||||
: _fieldName {Service<IConfig>::get()->getString("http-headers-field-name", "X-Forwarded-User")}
|
||||
: _fieldName {Service<IConfig>::get()->getString("http-headers-login-field", "X-Forwarded-User")}
|
||||
{
|
||||
LMS_LOG(AUTH, INFO) << "Using http header field = '" << _fieldName << "'";
|
||||
}
|
||||
@@ -37,7 +37,21 @@ namespace Auth
|
||||
HttpHeadersEnvService::CheckResult
|
||||
HttpHeadersEnvService::processEnv(Database::Session& session, const Wt::WEnvironment& env)
|
||||
{
|
||||
const std::string loginName { env.headerValue(_fieldName)};
|
||||
const std::string loginName {env.headerValue(_fieldName)};
|
||||
if (loginName.empty())
|
||||
return {CheckResult::State::Denied};
|
||||
|
||||
LMS_LOG(AUTH, DEBUG) << "Extracted login name = '" << loginName << "' from HTTP header";
|
||||
|
||||
const Database::IdType userId {getOrCreateUser(session, loginName)};
|
||||
onUserAuthenticated(session, userId);
|
||||
return {CheckResult::State::Granted, userId};
|
||||
}
|
||||
|
||||
HttpHeadersEnvService::CheckResult
|
||||
HttpHeadersEnvService::processRequest(Database::Session& session, const Wt::Http::Request& request)
|
||||
{
|
||||
const std::string loginName {request.headerValue(_fieldName)};
|
||||
if (loginName.empty())
|
||||
return {CheckResult::State::Denied};
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Auth
|
||||
|
||||
private:
|
||||
CheckResult processEnv(Database::Session& session, const Wt::WEnvironment& env) override;
|
||||
CheckResult processRequest(Database::Session& session, const Wt::Http::Request& request) override;
|
||||
|
||||
std::string _fieldName;
|
||||
};
|
||||
|
||||
@@ -34,6 +34,11 @@ namespace Wt
|
||||
class WEnvironment;
|
||||
}
|
||||
|
||||
namespace Wt::Http
|
||||
{
|
||||
class Request;
|
||||
}
|
||||
|
||||
namespace Auth
|
||||
{
|
||||
class IEnvService
|
||||
@@ -56,6 +61,7 @@ namespace Auth
|
||||
};
|
||||
|
||||
virtual CheckResult processEnv(Database::Session& session, const Wt::WEnvironment& env) = 0;
|
||||
virtual CheckResult processRequest(Database::Session& session, const Wt::Http::Request& request) = 0;
|
||||
};
|
||||
|
||||
std::unique_ptr<IEnvService> createEnvService(std::string_view backendName);
|
||||
|
||||
Reference in New Issue
Block a user