Throw exception when xml user profile does not exist

Closes #26086
This commit is contained in:
Nicolae Vartolomei 2022-06-13 13:29:08 +00:00
parent 06d94a4dde
commit 9555153f95
3 changed files with 15 additions and 2 deletions

View File

@ -19,6 +19,10 @@ class AccessControl;
struct SettingsProfileElement
{
std::optional<UUID> parent_profile;
/// parent_profile_xml_name is set only when users are configured via XML
/// and is used for user-friendly error messages.
std::optional<String> parent_profile_xml_name;
String setting_name;
Field value;
Field min_value;

View File

@ -170,8 +170,15 @@ void SettingsProfilesCache::substituteProfiles(
continue;
auto profile_it = all_profiles.find(profile_id);
if (profile_it == all_profiles.end())
continue;
if (profile_it == all_profiles.end()) {
/// If the textual profile name is set, then users are configured via XML.
/// For these users we want to throw an exception when their profile can't
/// be found. Otherwise, these users are super admins.
if (element.parent_profile_xml_name)
throw Exception(ErrorCodes::THERE_IS_NO_PROFILE, "There is no profile '{}' in configuration file", *element.parent_profile_xml_name);
else
continue;
}
const auto & profile = profile_it->second;
const auto & profile_elements = profile->elements;

View File

@ -142,6 +142,7 @@ namespace
auto profile_name = config.getString(profile_name_config);
SettingsProfileElement profile_element;
profile_element.parent_profile = generateID(AccessEntityType::SETTINGS_PROFILE, profile_name);
profile_element.parent_profile_xml_name = profile_name;
user->settings.push_back(std::move(profile_element));
}
@ -473,6 +474,7 @@ namespace
String parent_profile_name = config.getString(profile_config + "." + key);
SettingsProfileElement profile_element;
profile_element.parent_profile = generateID(AccessEntityType::SETTINGS_PROFILE, parent_profile_name);
profile_element.parent_profile_xml_name = parent_profile_name;
profile->elements.emplace_back(std::move(profile_element));
continue;
}