39 #include <unordered_map>
43 #include "tbb/concurrent_hash_map.h"
62 namespace Catalog_Namespace {
93 if (
this != &user_meta) {
123 std::string
toString(
bool hide_password =
true)
const;
154 std::string
const& new_name);
168 void init(
const std::string& basePath,
169 std::shared_ptr<Data_Namespace::DataMgr> dataMgr,
171 std::shared_ptr<Calcite> calcite,
174 const std::vector<LeafHostInfo>& string_dict_hosts);
183 std::shared_ptr<Catalog>
login(std::string& db,
184 std::string& username,
185 const std::string& password,
187 bool check_password =
true);
189 const std::string& username);
193 void dropUser(
const std::string& name,
bool if_exists =
false);
198 void renameUser(std::string
const& old_name, std::string
const& new_name);
200 void renameDatabase(std::string
const& old_name, std::string
const& new_name);
203 std::optional<UserMetadata>
getUser(std::string
const& uname) {
209 std::optional<UserMetadata>
getUser(int32_t
const uid) {
215 std::optional<DBMetadata>
getDB(std::string
const& dbname) {
221 std::optional<DBMetadata>
getDB(int32_t
const dbid) {
246 const std::string& objectName,
249 int32_t objectId = -1);
260 const std::string& newName,
268 const std::vector<DBObject>& objects,
274 const std::vector<DBObject>& objects,
301 bool revoke_privileges =
true);
303 const bool user_private_role,
304 const bool is_temporary =
false);
305 void dropRole(
const std::string& roleName,
const bool is_temporary =
false);
307 const std::vector<std::string>& grantees);
309 const std::string& grantee,
310 const bool is_temporary =
false);
312 const std::vector<std::string>& grantees);
314 const std::string& grantee,
315 const bool is_temporary =
false);
320 const std::vector<DBObject>& privObjects)
const;
322 const std::vector<DBObject>& privObjects)
const;
328 int32_t objectId)
const;
331 const std::string& roleName,
332 bool only_direct)
const;
333 std::vector<std::string>
getRoles(
const std::string& user_name,
bool effective =
true);
334 std::vector<std::string>
getRoles(
bool include_user_private_role,
336 const std::string& user_name,
337 bool ignore_deleted_user =
false);
338 std::vector<std::string>
getRoles(
const std::string& userName,
const int32_t dbId);
362 std::vector<std::string> idp_roles,
365 const std::vector<std::string>& dashboard_ids);
371 std::shared_ptr<Catalog>
getCatalog(
const std::string& dbName);
372 std::shared_ptr<Catalog>
getCatalog(
const int32_t db_id);
389 const std::map<int32_t, std::vector<DBObject>>& old_owner_db_objects,
390 int32_t new_owner_id,
397 using GranteeMap = std::map<std::string, std::unique_ptr<Grantee>>;
399 std::multimap<std::string, std::unique_ptr<ObjectRoleDescriptor>>;
423 const std::string& password,
441 bool revoke_privileges =
true);
446 const bool userPrivateRole,
447 const bool is_temporary);
448 void dropRole_unsafe(
const std::string& roleName,
const bool is_temporary);
450 const std::vector<std::string>& grantees);
452 const std::string& granteeName,
453 const bool is_temporary);
455 const std::vector<std::string>& grantees);
457 const std::string& granteeName,
458 const bool is_temporary);
468 const std::vector<DBObject>& objects,
474 const std::vector<DBObject>& objects,
488 const std::string& username,
498 template <
typename F,
typename... Args>
522 using dbid_to_cat_map = tbb::concurrent_hash_map<std::string, std::shared_ptr<Catalog>>;
549 bool populate_fragmenter =
true);
554 #endif // SYS_CATALOG_H
std::optional< std::string > passwd
std::optional< DBMetadata > getDB(std::string const &dbname)
std::multimap< std::string, std::unique_ptr< ObjectRoleDescriptor >> ObjectRoleDescriptorMap
void recordExecutedMigration(const std::string &migration_name) const
void revokeAllOnDatabase_unsafe(const std::string &roleName, int32_t dbId, Grantee *grantee)
void buildMaps(bool is_new_db=false)
void migrateDBAccessPrivileges()
void revokeDBObjectPrivilegesBatch_unsafe(const std::vector< std::string > &grantees, const std::vector< DBObject > &objects, const Catalog_Namespace::Catalog &catalog)
std::tuple< int, std::string > ColumnKey
void dropUserUnchecked(const std::string &name, const UserMetadata &user)
std::vector< Catalog * > getCatalogsForAllDbs()
auto duplicateAndRenameCatalog(std::string const ¤t_name, std::string const &new_name)
SqliteConnector * getSqliteConnector()
std::optional< std::string > default_db
class for a per-database catalog. also includes metadata for the current database and the current use...
void changeDBObjectOwnership(const UserMetadata &new_owner, const UserMetadata &previous_owner, DBObject object, const Catalog_Namespace::Catalog &catalog, bool revoke_privileges=true)
int32_t next_temporary_user_id_
void rebuildObjectMapsUnlocked()
std::set< std::string > getCreatedRoles() const
void grantRole(const std::string &role, const std::string &grantee, const bool is_temporary=false)
void revokeRole(const std::string &role, const std::string &grantee, const bool is_temporary=false)
void load(Archive &ar, ExplainedQueryHint &query_hint, const unsigned int version)
std::string const & base_path_
bool checkPasswordForUser(const std::string &passwd, std::string &name, UserMetadata &user)
void revokeDBObjectPrivileges_unsafe(const std::string &granteeName, DBObject object, const Catalog_Namespace::Catalog &catalog)
std::optional< UserMetadata > getUser(std::string const &uname)
void checkDuplicateCaseInsensitiveDbNames() const
void createRole_unsafe(const std::string &roleName, const bool userPrivateRole, const bool is_temporary)
void revokeDBObjectPrivilegesFromAll(DBObject object, Catalog *catalog)
bool getMetadataForUser(const std::string &name, UserMetadata &user)
void revokeDBObjectPrivileges(const std::string &grantee, const DBObject &object, const Catalog_Namespace::Catalog &catalog)
void removeCatalog(const std::string &dbName)
static std::unique_ptr< SysCatalog > instance_
std::atomic< std::thread::id > thread_holding_sqlite_lock
void checkDropRenderGroupColumnsMigration() const
void createRole(const std::string &roleName, const bool user_private_role, const bool is_temporary=false)
const TableDescriptor * get_metadata_for_table(const ::shared::TableKey &table_key, bool populate_fragmenter)
const std::string kSystemCatalogName
std::shared_ptr< Catalog > getDummyCatalog()
const ColumnDescriptor * get_metadata_for_column(const ::shared::ColumnKey &column_key)
ObjectRoleDescriptorMap objectDescriptorMap_
void changeDatabaseOwner(std::string const &dbname, const std::string &new_owner)
void updatePasswordsToHashes()
Grantee * getGrantee(const std::string &name) const
void dropDatabase(const DBMetadata &db)
void loginImpl(std::string &username, const std::string &password, UserMetadata &user_meta)
std::vector< ObjectRoleDescriptor > getMetadataForAllObjects() const
bool getMetadataForUserById(const int32_t idIn, UserMetadata &user)
void reassignObjectOwners(const std::map< int32_t, std::vector< DBObject >> &old_owner_db_objects, int32_t new_owner_id, const Catalog_Namespace::Catalog &catalog)
std::string toString(bool hide_password=true) const
std::list< UpdateQuery > UpdateQueries
void importDataFromOldMapdDB()
void init(const std::string &basePath, std::shared_ptr< Data_Namespace::DataMgr > dataMgr, const AuthMetadata &authMetadata, std::shared_ptr< Calcite > calcite, bool is_new_db, bool aggregator, const std::vector< LeafHostInfo > &string_dict_hosts)
std::optional< bool > is_super
void createDBObject(const UserMetadata &user, const std::string &objectName, DBObjectType type, const Catalog_Namespace::Catalog &catalog, int32_t objectId=-1)
void dropUser(const std::string &name, bool if_exists=false)
std::vector< std::string > text_params
void getDBObjectPrivileges(const std::string &granteeName, DBObject &object, const Catalog_Namespace::Catalog &catalog) const
void revokeRole_unsafe(const std::string &roleName, const std::string &granteeName, const bool is_temporary)
bool hasVersionHistoryTable() const
void grantDBObjectPrivileges_unsafe(const std::string &granteeName, const DBObject object, const Catalog_Namespace::Catalog &catalog)
void grantRoleBatch(const std::vector< std::string > &roles, const std::vector< std::string > &grantees)
std::unique_ptr< PkiServer > pki_server_
void revokeDBObjectPrivilegesBatch(const std::vector< std::string > &grantees, const std::vector< DBObject > &objects, const Catalog_Namespace::Catalog &catalog)
const AuthMetadata * authMetadata_
void updateBlankPasswordsToRandom()
static std::mutex instance_mutex_
void grantRoleBatch_unsafe(const std::vector< std::string > &roles, const std::vector< std::string > &grantees)
Data_Namespace::DataMgr & getDataMgr() const
bool checkPrivileges(const UserMetadata &user, const std::vector< DBObject > &privObjects) const
void buildObjectDescriptorMapUnlocked()
void renameDBObject(const std::string &objectName, const std::string &newName, DBObjectType type, int32_t objectId, const Catalog_Namespace::Catalog &catalog)
static SysCatalog & instance()
auto assembleCatalogName(std::string const &name)
bool wouldChange(UserMetadata const &user_meta) const
void getMetadataWithDefaultDB(std::string &dbname, const std::string &username, Catalog_Namespace::DBMetadata &db_meta, UserMetadata &user_meta)
auto yieldTransactionStreamer()
void grantAllOnDatabase_unsafe(const std::string &roleName, DBObject &object, const Catalog_Namespace::Catalog &catalog)
const std::string & getCatalogBasePath() const
tbb::concurrent_hash_map< std::string, std::shared_ptr< Catalog >> dbid_to_cat_map
heavyai::shared_mutex sharedMutex_
std::unordered_map< std::string, std::shared_ptr< UserMetadata > > temporary_users_by_name_
void renameObjectsInDescriptorMap(DBObject &object, const Catalog_Namespace::Catalog &cat)
bool checkPasswordForUserImpl(const std::string &passwd, std::string &name, UserMetadata &user)
std::shared_ptr< Catalog > login(std::string &db, std::string &username, const std::string &password, UserMetadata &user_meta, bool check_password=true)
void revokeRoleBatch_unsafe(const std::vector< std::string > &roles, const std::vector< std::string > &grantees)
void grantRole_unsafe(const std::string &roleName, const std::string &granteeName, const bool is_temporary)
void revokeRoleBatch(const std::vector< std::string > &roles, const std::vector< std::string > &grantees)
std::shared_ptr< Data_Namespace::DataMgr > dataMgr_
UserMetadata createUser(std::string const &name, UserAlterations alts, bool is_temporary)
std::unique_lock< T > unique_lock
DBSummaryList getDatabaseListForUser(const UserMetadata &user)
std::shared_ptr< Catalog > switchDatabase(std::string &dbname, const std::string &username)
Role * getRoleGrantee(const std::string &name) const
std::optional< UserMetadata > getUser(int32_t const uid)
void revokeDBObjectPrivilegesFromAllBatch_unsafe(std::vector< DBObject > &objects, Catalog *catalog)
User * getUserGrantee(const std::string &name) const
void grantDBObjectPrivilegesBatch(const std::vector< std::string > &grantees, const std::vector< DBObject > &objects, const Catalog_Namespace::Catalog &catalog)
void grantDBObjectPrivileges(const std::string &grantee, const DBObject &object, const Catalog_Namespace::Catalog &catalog)
specifies the content in-memory of a row in the column metadata table
std::unique_ptr< SqliteConnector > sqliteConnector_
CommonFileOperations(std::string const &base_path)
void updateUserRoleName(const std::string &roleName, const std::string &newName)
std::list< UserMetadata > getAllUserMetadata()
void grantDBObjectPrivilegesBatch_unsafe(const std::vector< std::string > &grantees, const std::vector< DBObject > &objects, const Catalog_Namespace::Catalog &catalog)
void buildUserRoleMapUnlocked()
void execInTransaction(F &&f, Args &&...args)
const int32_t kTempUserIdRange
void dropRole_unsafe(const std::string &roleName, const bool is_temporary)
std::unique_ptr< heavyai::DistributedSharedMutex > dsqliteMutex_
void check_for_session_encryption(const std::string &pki_cert, std::string &session)
void renameUser(std::string const &old_name, std::string const &new_name)
std::shared_ptr< Catalog > getCatalog(const std::string &dbName)
void migratePrivileged_old()
bool isRoleGrantedToGrantee(const std::string &granteeName, const std::string &roleName, bool only_direct) const
bool hasAnyPrivileges(const UserMetadata &user, std::vector< DBObject > &privObjects)
void deleteObjectDescriptorMap(const std::string &roleName)
void removeCatalogByName(std::string const &name)
void updateSupportUserDeactivation()
void checkAndExecuteMigrations()
void updateObjectDescriptorMap(const std::string &roleName, DBObject &object, bool roleType, const Catalog_Namespace::Catalog &cat)
std::unordered_map< int32_t, std::shared_ptr< UserMetadata > > temporary_users_by_id_
bool allowLocalLogin() const
void syncUserWithRemoteProvider(const std::string &user_name, std::vector< std::string > idp_roles, UserAlterations alts)
void dropRole(const std::string &roleName, const bool is_temporary=false)
void createVersionHistoryTable() const
std::list< DBMetadata > getAllDBMetadata()
void renameDatabase(std::string const &old_name, std::string const &new_name)
void revokeDBObjectPrivilegesFromAll_unsafe(DBObject object, Catalog *catalog)
void buildMapsUnlocked(bool is_new_db=false)
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
bool verifyDBObjectOwnership(const UserMetadata &user, DBObject object, const Catalog_Namespace::Catalog &catalog)
std::vector< LeafHostInfo > string_dict_hosts_
std::optional< bool > can_login
std::unique_ptr< heavyai::DistributedSharedMutex > dcatalogMutex_
std::shared_ptr< Calcite > calciteMgr_
std::unordered_map< std::string, std::vector< std::string > > getGranteesOfSharedDashboards(const std::vector< std::string > &dashboard_ids)
void runUpdateQueriesAndChangeOwnership(const UserMetadata &new_owner, const UserMetadata &previous_owner, DBObject object, const Catalog_Namespace::Catalog &catalog, const UpdateQueries &update_queries, bool revoke_privileges=true)
std::list< DBSummary > DBSummaryList
void populateRoleDbObjects(const std::vector< DBObject > &objects)
static thread_local bool thread_holds_read_lock
void grantDefaultPrivilegesToRole_unsafe(const std::string &name, bool issuper)
std::optional< DBMetadata > getDB(int32_t const dbid)
Calcite & getCalciteMgr() const
bool isDashboardSystemRole(const std::string &roleName) const
std::shared_timed_mutex shared_mutex
bool isAggregator() const
bool hasExecutedMigration(const std::string &migration_name) const
std::map< std::string, std::unique_ptr< Grantee >> GranteeMap
bool getMetadataForDBById(const int32_t idIn, DBMetadata &db)
void createDatabase(const std::string &dbname, int owner)
UserMetadata alterUser(std::string const &name, UserAlterations alts)
std::shared_ptr< Catalog > dummyCatalog_
void removeCatalogByFullPath(std::string const &full_path)
std::vector< ObjectRoleDescriptor * > getMetadataForObject(int32_t dbId, int32_t dbType, int32_t objectId) const
std::vector< std::string > getRoles(const std::string &user_name, bool effective=true)
void buildRoleMapUnlocked()
bool getMetadataForDB(const std::string &name, DBMetadata &db)
void revokeDBObjectPrivilegesFromAllBatch(std::vector< DBObject > &objects, Catalog *catalog)
void initializeInformationSchemaDb()
bool isInitialized() const
std::atomic< std::thread::id > thread_holding_write_lock