| 146 | } |
| 147 | |
| 148 | AuthenticationData parseUserAuthMethod( |
| 149 | const Poco::Util::AbstractConfiguration & config, |
| 150 | const String & user_name, |
| 151 | const String & auth_method_path, |
| 152 | const std::optional<OneTimePasswordSecret> & otp_secret) |
| 153 | { |
| 154 | const bool validate = true; |
| 155 | |
| 156 | bool has_no_password = config.has(auth_method_path + ".no_password"); |
| 157 | |
| 158 | const auto password_plaintext_config = auth_method_path + ".password"; |
| 159 | bool has_password_plaintext = config.has(password_plaintext_config); |
| 160 | |
| 161 | const auto password_sha256_hex_config = auth_method_path + ".password_sha256_hex"; |
| 162 | bool has_password_sha256_hex = config.has(password_sha256_hex_config); |
| 163 | |
| 164 | const auto scram_password_config = auth_method_path + ".password_scram_sha256_hex"; |
| 165 | bool has_scram_password_sha256_hex = config.has(scram_password_config); |
| 166 | |
| 167 | const auto password_double_sha1_hex_config = auth_method_path + ".password_double_sha1_hex"; |
| 168 | bool has_password_double_sha1_hex = config.has(password_double_sha1_hex_config); |
| 169 | |
| 170 | const auto ldap_config = auth_method_path + ".ldap"; |
| 171 | bool has_ldap = config.has(ldap_config); |
| 172 | |
| 173 | const auto kerberos_config = auth_method_path + ".kerberos"; |
| 174 | bool has_kerberos = config.has(kerberos_config); |
| 175 | |
| 176 | const auto certificates_config = auth_method_path + ".ssl_certificates"; |
| 177 | bool has_certificates = config.has(certificates_config); |
| 178 | |
| 179 | const auto ssh_keys_config = auth_method_path + ".ssh_keys"; |
| 180 | bool has_ssh_keys = config.has(ssh_keys_config); |
| 181 | |
| 182 | const auto http_auth_config = auth_method_path + ".http_authentication"; |
| 183 | bool has_http_auth = config.has(http_auth_config); |
| 184 | |
| 185 | size_t num_authentication_types = has_no_password + has_password_plaintext + has_password_sha256_hex + has_password_double_sha1_hex |
| 186 | + has_ldap + has_kerberos + has_certificates + has_ssh_keys + has_http_auth + has_scram_password_sha256_hex; |
| 187 | |
| 188 | if (num_authentication_types > 1) |
| 189 | throw Exception(ErrorCodes::BAD_ARGUMENTS, |
| 190 | "Cannot specify multiple authentication methods for user {} at {}. " |
| 191 | "Specify only one authentication method.", user_name, auth_method_path); |
| 192 | |
| 193 | if (num_authentication_types < 1) |
| 194 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "At least one authentication type (one of 'password', " |
| 195 | "'password_sha256_hex', 'password_scram_sha256_hex', 'password_double_sha1_hex', 'no_password', 'ldap', 'kerberos', " |
| 196 | "'ssl_certificates', 'ssh_keys', 'http_authentication') must be specified for user {} in path {}.", user_name, auth_method_path); |
| 197 | |
| 198 | AuthenticationData auth_data; |
| 199 | |
| 200 | if (has_no_password && otp_secret) |
| 201 | { |
| 202 | auth_data = createPasswordAuthData(AuthenticationType::NO_PASSWORD, "", otp_secret, validate, false); |
| 203 | } |
| 204 | else if (has_no_password) |
| 205 | { |
no test coverage detected