MCPcopy Create free account
hub / github.com/3rdparty/libprocess / authenticate

Method authenticate

src/authenticator_manager.cpp:79–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78
79Future<Option<AuthenticationResult>> AuthenticatorManagerProcess::authenticate(
80 const Request& request,
81 const string& realm)
82{
83 if (!authenticators_.contains(realm)) {
84 VLOG(2) << "Request for '" << request.url.path << "' requires"
85 << " authentication in realm '" << realm << "'"
86 << " but no authenticator found";
87 return None();
88 }
89
90 return authenticators_[realm]->authenticate(request)
91 .then([](const AuthenticationResult& authentication)
92 -> Future<Option<AuthenticationResult>> {
93 // Validate that exactly 1 member is set!
94 size_t count =
95 (authentication.principal.isSome() ? 1 : 0) +
96 (authentication.unauthorized.isSome() ? 1 : 0) +
97 (authentication.forbidden.isSome() ? 1 : 0);
98
99 if (count != 1) {
100 return Failure(
101 "HTTP authenticators must return only one of an authenticated "
102 "principal, an Unauthorized response, or a Forbidden response");
103 }
104
105 if (authentication.principal.isSome()) {
106 // Validate that at least one of `value` and `claims` is set.
107 if (authentication.principal->value.isNone() &&
108 authentication.principal->claims.empty()) {
109 return Failure(
110 "In the principal returned by an HTTP authenticator, at least one"
111 " of 'value' and 'claims' must be set");
112 }
113 }
114
115 return authentication;
116 });
117}
118
119
120AuthenticatorManager::AuthenticatorManager()

Callers

nothing calls this directly

Calls 5

FailureClass · 0.85
dispatchFunction · 0.70
thenMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected