Move AdminVerificationStrategy to Server (#965)

This commit is contained in:
cyan317
2023-11-02 10:17:32 +00:00
committed by GitHub
parent 058df4d12a
commit 320ebaa5d2
7 changed files with 29 additions and 29 deletions

View File

@@ -54,13 +54,13 @@ PasswordAdminVerificationStrategy::isAdmin(RequestType const& request, std::stri
return passwordSha256_ == userAuth;
}
std::unique_ptr<AdminVerificationStrategy>
std::shared_ptr<AdminVerificationStrategy>
make_AdminVerificationStrategy(std::optional<std::string> password)
{
if (password.has_value()) {
return std::make_unique<PasswordAdminVerificationStrategy>(std::move(*password));
return std::make_shared<PasswordAdminVerificationStrategy>(std::move(*password));
}
return std::make_unique<IPAdminVerificationStrategy>();
return std::make_shared<IPAdminVerificationStrategy>();
}
} // namespace web::detail

View File

@@ -73,7 +73,7 @@ public:
isAdmin(RequestType const& request, std::string_view) const override;
};
std::unique_ptr<AdminVerificationStrategy>
std::shared_ptr<AdminVerificationStrategy>
make_AdminVerificationStrategy(std::optional<std::string> password);
} // namespace web::detail

View File

@@ -85,7 +85,7 @@ class HttpBase : public ConnectionBase {
std::shared_ptr<void> res_;
SendLambda sender_;
std::unique_ptr<AdminVerificationStrategy> adminVerification_;
std::shared_ptr<AdminVerificationStrategy> adminVerification_;
protected:
boost::beast::flat_buffer buffer_;
@@ -129,17 +129,17 @@ public:
HttpBase(
std::string const& ip,
std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
std::optional<std::string> adminPassword,
std::shared_ptr<AdminVerificationStrategy> adminVerification,
std::reference_wrapper<web::DOSGuard> dosGuard,
std::shared_ptr<HandlerType> const& handler,
std::shared_ptr<HandlerType> handler,
boost::beast::flat_buffer buffer
)
: ConnectionBase(tagFactory, ip)
, sender_(*this)
, adminVerification_(make_AdminVerificationStrategy(std::move(adminPassword)))
, adminVerification_(std::move(adminVerification))
, buffer_(std::move(buffer))
, dosGuard_(dosGuard)
, handler_(handler)
, handler_(std::move(handler))
{
LOG(perfLog_.debug()) << tag() << "http session created";
dosGuard_.get().increment(ip);