2022-02-02 14:29:47 +00:00
|
|
|
#include <Access/CachedAccessChecking.h>
|
|
|
|
#include <Access/ContextAccess.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2024-05-29 16:09:03 +00:00
|
|
|
CachedAccessChecking::CachedAccessChecking(const std::shared_ptr<const ContextAccessWrapper> & access_, AccessFlags access_flags_)
|
2022-02-02 14:29:47 +00:00
|
|
|
: CachedAccessChecking(access_, AccessRightsElement{access_flags_})
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-05-29 16:09:03 +00:00
|
|
|
CachedAccessChecking::CachedAccessChecking(const std::shared_ptr<const ContextAccessWrapper> & access_, const AccessRightsElement & element_)
|
2022-02-02 14:29:47 +00:00
|
|
|
: access(access_), element(element_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CachedAccessChecking::~CachedAccessChecking() = default;
|
|
|
|
|
|
|
|
bool CachedAccessChecking::checkAccess(bool throw_if_denied)
|
|
|
|
{
|
|
|
|
if (checked)
|
|
|
|
return result;
|
|
|
|
if (throw_if_denied)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
access->checkAccess(element);
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = access->isGranted(element);
|
|
|
|
}
|
|
|
|
checked = true;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|