Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AdminVerificationStrategy.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "util/newconfig/ConfigDefinition.hpp"
23
24#include <boost/beast/http.hpp>
25#include <boost/beast/http/message.hpp>
26#include <boost/beast/http/string_body.hpp>
27
28#include <expected>
29#include <memory>
30#include <optional>
31#include <string>
32#include <string_view>
33
34namespace web {
35
40public:
41 using RequestHeader = boost::beast::http::request<boost::beast::http::string_body>::header_type;
42 virtual ~AdminVerificationStrategy() = default;
43
51 virtual bool
52 isAdmin(RequestHeader const& request, std::string_view ip) const = 0;
53};
54
59public:
67 bool
68 isAdmin(RequestHeader const&, std::string_view ip) const override;
69};
70
75private:
76 std::string passwordSha256_;
77
78public:
82 static constexpr std::string_view kPASSWORD_PREFIX = "Password ";
83
89 PasswordAdminVerificationStrategy(std::string const& password);
90
98 bool
99 isAdmin(RequestHeader const& request, std::string_view) const override;
100};
101
109std::shared_ptr<AdminVerificationStrategy>
110makeAdminVerificationStrategy(std::optional<std::string> password);
111
118std::expected<std::shared_ptr<AdminVerificationStrategy>, std::string>
120
121} // namespace web
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:54
Interface for admin verification strategies.
Definition AdminVerificationStrategy.hpp:39
virtual bool isAdmin(RequestHeader const &request, std::string_view ip) const =0
Checks whether request is from a host that is considered authorized as admin.
Admin verification strategy that checks the ip address of the client.
Definition AdminVerificationStrategy.hpp:58
bool isAdmin(RequestHeader const &, std::string_view ip) const override
Checks whether request is from a host that is considered authorized as admin by checking the ip addre...
Definition AdminVerificationStrategy.cpp:39
Admin verification strategy that checks the password from the request header.
Definition AdminVerificationStrategy.hpp:74
bool isAdmin(RequestHeader const &request, std::string_view) const override
Checks whether request is from a host that is considered authorized as admin using the password (if a...
Definition AdminVerificationStrategy.cpp:57
PasswordAdminVerificationStrategy(std::string const &password)
Construct a new PasswordAdminVerificationStrategy object.
Definition AdminVerificationStrategy.cpp:44
static constexpr std::string_view kPASSWORD_PREFIX
The prefix for the password in the request header.
Definition AdminVerificationStrategy.hpp:82
This namespace implements the web server and related components.
Definition Types.hpp:43
std::shared_ptr< AdminVerificationStrategy > makeAdminVerificationStrategy(std::optional< std::string > password)
Factory function for creating an admin verification strategy.
Definition AdminVerificationStrategy.cpp:75