Make error message after dropping current user more correct.

This commit is contained in:
Vitaly Baranov 2022-11-09 21:01:05 +01:00
parent d02d1fd489
commit 675507594a

View File

@ -465,6 +465,17 @@ std::shared_ptr<const AccessRights> ContextAccess::getAccessRightsWithImplicit()
template <bool throw_if_denied, bool grant_option, typename... Args>
bool ContextAccess::checkAccessImplHelper(AccessFlags flags, const Args &... args) const
{
if (user_was_dropped)
{
/// If the current user has been dropped we always throw an exception (even if `throw_if_denied` is false)
/// because dropping of the current user is considered as a situation which is exceptional enough to stop
/// query execution.
throw Exception(getUserName() + ": User has been dropped", ErrorCodes::UNKNOWN_USER);
}
if (is_full_access)
return true;
auto access_granted = [&]
{
if (trace_log)
@ -483,12 +494,6 @@ bool ContextAccess::checkAccessImplHelper(AccessFlags flags, const Args &... arg
return false;
};
if (is_full_access)
return true;
if (user_was_dropped)
return access_denied("User has been dropped", ErrorCodes::UNKNOWN_USER);
if (flags & AccessType::CLUSTER && !access_control->doesOnClusterQueriesRequireClusterGrant())
flags &= ~AccessType::CLUSTER;