mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-04 11:55:51 +00:00
Move AdminVerificationStrategy to Server (#965)
This commit is contained in:
@@ -55,7 +55,7 @@ public:
|
||||
explicit HttpSession(
|
||||
tcp::socket&& socket,
|
||||
std::string const& ip,
|
||||
std::optional<std::string> adminPassword,
|
||||
std::shared_ptr<detail::AdminVerificationStrategy> const& adminVerification,
|
||||
std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
|
||||
std::reference_wrapper<web::DOSGuard> dosGuard,
|
||||
std::shared_ptr<HandlerType> const& handler,
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
: detail::HttpBase<HttpSession, HandlerType>(
|
||||
ip,
|
||||
tagFactory,
|
||||
std::move(adminPassword),
|
||||
adminVerification,
|
||||
dosGuard,
|
||||
handler,
|
||||
std::move(buffer)
|
||||
|
||||
@@ -57,7 +57,7 @@ class Detector : public std::enable_shared_from_this<Detector<PlainSessionType,
|
||||
std::reference_wrapper<web::DOSGuard> const dosGuard_;
|
||||
std::shared_ptr<HandlerType> const handler_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
std::optional<std::string> adminPassword_;
|
||||
std::shared_ptr<detail::AdminVerificationStrategy> const adminVerification_;
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -75,15 +75,15 @@ public:
|
||||
std::optional<std::reference_wrapper<boost::asio::ssl::context>> ctx,
|
||||
std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
|
||||
std::reference_wrapper<web::DOSGuard> dosGuard,
|
||||
std::shared_ptr<HandlerType> const& handler,
|
||||
std::optional<std::string> adminPassword
|
||||
std::shared_ptr<HandlerType> handler,
|
||||
std::shared_ptr<detail::AdminVerificationStrategy> adminVerification
|
||||
)
|
||||
: stream_(std::move(socket))
|
||||
, ctx_(ctx)
|
||||
, tagFactory_(std::cref(tagFactory))
|
||||
, dosGuard_(dosGuard)
|
||||
, handler_(handler)
|
||||
, adminPassword_(std::move(adminPassword))
|
||||
, handler_(std::move(handler))
|
||||
, adminVerification_(std::move(adminVerification))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public:
|
||||
std::make_shared<SslSessionType<HandlerType>>(
|
||||
stream_.release_socket(),
|
||||
ip,
|
||||
adminPassword_,
|
||||
adminVerification_,
|
||||
*ctx_,
|
||||
tagFactory_,
|
||||
dosGuard_,
|
||||
@@ -148,7 +148,7 @@ public:
|
||||
}
|
||||
|
||||
std::make_shared<PlainSessionType<HandlerType>>(
|
||||
stream_.release_socket(), ip, adminPassword_, tagFactory_, dosGuard_, handler_, std::move(buffer_)
|
||||
stream_.release_socket(), ip, adminVerification_, tagFactory_, dosGuard_, handler_, std::move(buffer_)
|
||||
)
|
||||
->run();
|
||||
}
|
||||
@@ -174,7 +174,7 @@ class Server : public std::enable_shared_from_this<Server<PlainSessionType, SslS
|
||||
std::reference_wrapper<web::DOSGuard> dosGuard_;
|
||||
std::shared_ptr<HandlerType> handler_;
|
||||
tcp::acceptor acceptor_;
|
||||
std::optional<std::string> adminPassword_;
|
||||
std::shared_ptr<detail::AdminVerificationStrategy> adminVerification_;
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -194,16 +194,16 @@ public:
|
||||
tcp::endpoint endpoint,
|
||||
util::TagDecoratorFactory tagFactory,
|
||||
web::DOSGuard& dosGuard,
|
||||
std::shared_ptr<HandlerType> const& handler,
|
||||
std::shared_ptr<HandlerType> handler,
|
||||
std::optional<std::string> adminPassword
|
||||
)
|
||||
: ioc_(std::ref(ioc))
|
||||
, ctx_(ctx)
|
||||
, tagFactory_(tagFactory)
|
||||
, dosGuard_(std::ref(dosGuard))
|
||||
, handler_(handler)
|
||||
, handler_(std::move(handler))
|
||||
, acceptor_(boost::asio::make_strand(ioc))
|
||||
, adminPassword_(std::move(adminPassword))
|
||||
, adminVerification_(detail::make_AdminVerificationStrategy(std::move(adminPassword)))
|
||||
{
|
||||
boost::beast::error_code ec;
|
||||
|
||||
@@ -257,7 +257,7 @@ private:
|
||||
ctx_ ? std::optional<std::reference_wrapper<boost::asio::ssl::context>>{ctx_.value()} : std::nullopt;
|
||||
|
||||
std::make_shared<Detector<PlainSessionType, SslSessionType, HandlerType>>(
|
||||
std::move(socket), ctxRef, std::cref(tagFactory_), dosGuard_, handler_, adminPassword_
|
||||
std::move(socket), ctxRef, std::cref(tagFactory_), dosGuard_, handler_, adminVerification_
|
||||
)
|
||||
->run();
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
explicit SslHttpSession(
|
||||
tcp::socket&& socket,
|
||||
std::string const& ip,
|
||||
std::optional<std::string> adminPassword,
|
||||
std::shared_ptr<detail::AdminVerificationStrategy> const& adminVerification,
|
||||
boost::asio::ssl::context& ctx,
|
||||
std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
|
||||
std::reference_wrapper<web::DOSGuard> dosGuard,
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
: detail::HttpBase<SslHttpSession, HandlerType>(
|
||||
ip,
|
||||
tagFactory,
|
||||
std::move(adminPassword),
|
||||
adminVerification,
|
||||
dosGuard,
|
||||
handler,
|
||||
std::move(buffer)
|
||||
|
||||
@@ -109,19 +109,19 @@ public:
|
||||
std::string ip,
|
||||
std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
|
||||
std::reference_wrapper<web::DOSGuard> dosGuard,
|
||||
std::shared_ptr<HandlerType> const& handler,
|
||||
std::shared_ptr<HandlerType> handler,
|
||||
boost::beast::flat_buffer&& buffer,
|
||||
http::request<http::string_body> request,
|
||||
bool isAdmiin
|
||||
bool isAdmin
|
||||
)
|
||||
: https_(std::move(stream))
|
||||
, buffer_(std::move(buffer))
|
||||
, ip_(std::move(ip))
|
||||
, tagFactory_(tagFactory)
|
||||
, dosGuard_(dosGuard)
|
||||
, handler_(handler)
|
||||
, handler_(std::move(handler))
|
||||
, req_(std::move(request))
|
||||
, isAdmin_(isAdmiin)
|
||||
, isAdmin_(isAdmin)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user