| 356 | } |
| 357 | |
| 358 | void validateUserAuthenticationMethods( |
| 359 | const std::vector<AuthenticationData> & authentication_methods, |
| 360 | const String & user_name, |
| 361 | bool allow_no_password, |
| 362 | bool allow_plaintext_password, |
| 363 | const std::optional<OneTimePasswordSecret> & otp_secret) |
| 364 | { |
| 365 | bool has_no_password = false; |
| 366 | bool has_password_method = false; |
| 367 | for (const auto & authentication_method : authentication_methods) |
| 368 | { |
| 369 | auto auth_type = authentication_method.getType(); |
| 370 | |
| 371 | if (auth_type == AuthenticationType::NO_PASSWORD) |
| 372 | { |
| 373 | has_no_password = true; |
| 374 | } |
| 375 | |
| 376 | if (AuthenticationTypeInfo::get(auth_type).is_password || auth_type == AuthenticationType::NO_PASSWORD) |
| 377 | { |
| 378 | has_password_method = true; |
| 379 | } |
| 380 | |
| 381 | if (((auth_type == AuthenticationType::NO_PASSWORD) && !allow_no_password) || |
| 382 | ((auth_type == AuthenticationType::PLAINTEXT_PASSWORD) && !allow_plaintext_password)) |
| 383 | { |
| 384 | throw Exception(ErrorCodes::BAD_ARGUMENTS, |
| 385 | "Authentication type {} is not allowed, check the setting allow_{} in the server configuration", |
| 386 | toString(auth_type), AuthenticationTypeInfo::get(auth_type).name); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | if (has_no_password && authentication_methods.size() > 1) |
| 391 | { |
| 392 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "'no_password' cannot be combined with other authentication methods for user {}.", user_name); |
| 393 | } |
| 394 | |
| 395 | if (otp_secret && !has_password_method) |
| 396 | { |
| 397 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "One-time password can be used only with password based authentication for user {}.", user_name); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | UserPtr parseUser( |
| 402 | const Poco::Util::AbstractConfiguration & config, |