userver: userver/server/handlers/auth/digest/standalone_checker.hpp Source File
Loading...
Searching...
No Matches
standalone_checker.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/handlers/auth/digest/standalone_checker.hpp
4/// @brief @copybrief server::handlers::auth::digest::AuthStandaloneCheckerBase
5
6#include <chrono>
7#include <cstdint>
8#include <functional>
9#include <random>
10#include <string_view>
11
12#include <userver/cache/expirable_lru_cache.hpp>
13#include <userver/concurrent/mpsc_queue.hpp>
14#include <userver/concurrent/variable.hpp>
15#include <userver/crypto/hash.hpp>
16#include <userver/rcu/rcu_map.hpp>
17#include <userver/server/handlers/auth/digest/auth_checker_base.hpp>
18#include <userver/server/handlers/auth/digest/auth_checker_settings.hpp>
19#include <userver/server/handlers/auth/digest/directives_parser.hpp>
20#include <userver/server/http/http_request.hpp>
21#include <userver/server/http/http_response.hpp>
22#include <userver/server/http/http_status.hpp>
23#include <userver/server/request/request_context.hpp>
24
25USERVER_NAMESPACE_BEGIN
26
27namespace server::handlers::auth::digest {
28
29struct NonceInfo final {
30 NonceInfo();
31 NonceInfo(const std::string& nonce, TimePoint expiration_time,
32 std::int64_t nonce_count);
33 std::string nonce;
34 TimePoint expiration_time;
35 std::int64_t nonce_count;
36};
37
38/// @ingroup userver_base_classes
39///
40/// @brief Class for digest authentication checker. Implements a stand-alone
41/// digest-authentication logic.
43 public:
44 AuthStandaloneCheckerBase(const AuthCheckerSettings& digest_settings,
45 std::string&& realm,
46 const SecdistConfig& secdist_config,
47 std::size_t ways, std::size_t way_size);
48
49 [[nodiscard]] bool SupportsUserAuth() const noexcept override { return true; }
50
51 std::optional<UserData> FetchUserData(
52 const std::string& username) const override;
53 void SetUserData(const std::string& username, const std::string& nonce,
54 std::int64_t nonce_count,
55 TimePoint nonce_creation_time) const override;
56
57 void PushUnnamedNonce(std::string nonce) const override;
59 const std::string& nonce) const override;
60
61 virtual std::optional<UserData::HA1> GetHA1(
62 std::string_view username) const = 0;
63
64 private:
66 // potentially we store ALL user's data
67 // great chance to occupy large block of memory
68 mutable rcu::RcuMap<std::string, concurrent::Variable<NonceInfo>> user_data_;
69 // cache for "unnamed" nonces,
70 // i.e initial nonces not tied to any user
71 mutable NonceCache unnamed_nonces_;
72};
73
74} // namespace server::handlers::auth::digest
75
76USERVER_NAMESPACE_END