userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
auth_checker_factory.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/server/handlers/auth/auth_checker_factory.hpp
4
/// @brief Authorization factory registration and base classes.
5
6
#
include
<
string
>
7
#
include
<
string_view
>
8
#
include
<
vector
>
9
10
#
include
<
userver
/
components
/
component_context
.
hpp
>
11
#
include
<
userver
/
server
/
handlers
/
auth
/
auth_checker_base
.
hpp
>
12
#
include
<
userver
/
server
/
handlers
/
handler_config
.
hpp
>
13
#
include
<
userver
/
utils
/
not_null
.
hpp
>
14
15
USERVER_NAMESPACE_BEGIN
16
17
namespace
server::
handlers
::auth {
18
19
/// Base class for all the authorization factory checkers.
20
class
AuthCheckerFactoryBase
{
21
public
:
22
virtual
~AuthCheckerFactoryBase() =
default
;
23
24
virtual
AuthCheckerBasePtr MakeAuthChecker(
const
HandlerAuthConfig&)
const
= 0;
25
};
26
27
namespace
impl {
28
29
using
AuthCheckerFactoryFactory =
utils
::
UniqueRef
<
AuthCheckerFactoryBase
> (*)(
const
components
::ComponentContext&);
30
31
void
DoRegisterAuthCheckerFactory(std::string_view auth_type, AuthCheckerFactoryFactory factory);
32
33
utils
::
UniqueRef
<
AuthCheckerFactoryBase
> MakeAuthCheckerFactory(
34
std::string_view auth_type,
35
const
components
::ComponentContext& context
36
);
37
38
std::vector<std::string> GetAllAuthTypes();
39
40
template
<
typename
AuthCheckerFactory>
41
utils
::
UniqueRef
<
AuthCheckerFactoryBase
> MakeAuthCheckerFactory(
const
components
::ComponentContext& context) {
42
return
utils
::MakeUniqueRef<AuthCheckerFactory>(context);
43
}
44
45
}
// namespace impl
46
47
/// @brief Function to call from main() to register an authorization checker.
48
///
49
/// @tparam AuthCheckerFactory must:
50
/// 1) inherit from @ref server::handlers::auth::AuthCheckerFactoryBase;
51
/// 2) have a constructor from `const components::ComponentContext&`;
52
/// 3) have `static constexpr std::string_view kAuthType = "..."` member.
53
template
<
typename
AuthCheckerFactory>
54
void
RegisterAuthCheckerFactory
() {
55
const
auto
auth_type = std::string_view{AuthCheckerFactory::kAuthType};
56
impl::DoRegisterAuthCheckerFactory(auth_type, &impl::MakeAuthCheckerFactory<AuthCheckerFactory>);
57
}
58
59
}
// namespace server::handlers::auth
60
61
USERVER_NAMESPACE_END
userver
server
handlers
auth
auth_checker_factory.hpp
Generated on
for userver by
Doxygen
1.17.0