| 1347 | } // namespace { |
| 1348 | |
| 1349 | Try<Nothing> initializeHttpAuthenticators( |
| 1350 | const string& realm, |
| 1351 | const vector<string>& authenticatorNames, |
| 1352 | const Option<Credentials>& credentials, |
| 1353 | const Option<string>& jwtSecretKey) |
| 1354 | { |
| 1355 | if (authenticatorNames.empty()) { |
| 1356 | return Error( |
| 1357 | "No HTTP authenticators specified for realm '" + realm + "'"); |
| 1358 | } |
| 1359 | |
| 1360 | Option<process::http::authentication::Authenticator*> authenticator; |
| 1361 | |
| 1362 | if (authenticatorNames.size() == 1) { |
| 1363 | Result<process::http::authentication::Authenticator*> authenticator_ = |
| 1364 | None(); |
| 1365 | |
| 1366 | if (authenticatorNames[0] == internal::DEFAULT_BASIC_HTTP_AUTHENTICATOR) { |
| 1367 | authenticator_ = |
| 1368 | createBasicAuthenticator(realm, authenticatorNames[0], credentials); |
| 1369 | #ifdef USE_SSL_SOCKET |
| 1370 | } else if ( |
| 1371 | authenticatorNames[0] == internal::DEFAULT_JWT_HTTP_AUTHENTICATOR) { |
| 1372 | authenticator_ = |
| 1373 | createJWTAuthenticator(realm, authenticatorNames[0], jwtSecretKey); |
| 1374 | #endif // USE_SSL_SOCKET |
| 1375 | } else { |
| 1376 | authenticator_ = createCustomAuthenticator(realm, authenticatorNames[0]); |
| 1377 | } |
| 1378 | |
| 1379 | if (authenticator_.isError()) { |
| 1380 | return Error( |
| 1381 | "Failed to create HTTP authenticator module '" + |
| 1382 | authenticatorNames[0] + "': " + authenticator_.error()); |
| 1383 | } |
| 1384 | |
| 1385 | CHECK_SOME(authenticator_); |
| 1386 | authenticator = authenticator_.get(); |
| 1387 | } else { |
| 1388 | // There are multiple authenticators loaded for this realm, |
| 1389 | // so construct a `CombinedAuthenticator` to handle them. |
| 1390 | vector<Owned<process::http::authentication::Authenticator>> authenticators; |
| 1391 | foreach (const string& name, authenticatorNames) { |
| 1392 | Result<process::http::authentication::Authenticator*> authenticator_ = |
| 1393 | None(); |
| 1394 | |
| 1395 | if (name == internal::DEFAULT_BASIC_HTTP_AUTHENTICATOR) { |
| 1396 | authenticator_ = createBasicAuthenticator(realm, name, credentials); |
| 1397 | #ifdef USE_SSL_SOCKET |
| 1398 | } else if (name == internal::DEFAULT_JWT_HTTP_AUTHENTICATOR) { |
| 1399 | authenticator_ = createJWTAuthenticator(realm, name, jwtSecretKey); |
| 1400 | #endif // USE_SSL_SOCKET |
| 1401 | } else { |
| 1402 | authenticator_ = createCustomAuthenticator(realm, name); |
| 1403 | } |
| 1404 | |
| 1405 | if (authenticator_.isError()) { |
| 1406 | return Error( |
no test coverage detected