#pragma once #include #include #include #include namespace DB { class ASTRolesOrUsersSet; class AccessControlManager; /// Represents a set of users/roles like /// {user_name | role_name | CURRENT_USER | ALL | NONE} [,...] /// [EXCEPT {user_name | role_name | CURRENT_USER | ALL | NONE} [,...]] /// Similar to ASTRolesOrUsersSet, but with IDs instead of names. struct RolesOrUsersSet { RolesOrUsersSet(); RolesOrUsersSet(const RolesOrUsersSet & src); RolesOrUsersSet & operator =(const RolesOrUsersSet & src); RolesOrUsersSet(RolesOrUsersSet && src); RolesOrUsersSet & operator =(RolesOrUsersSet && src); struct AllTag {}; RolesOrUsersSet(AllTag); RolesOrUsersSet(const UUID & id); RolesOrUsersSet(const std::vector & ids_); /// The constructor from AST requires the AccessControlManager if `ast.id_mode == false`. RolesOrUsersSet(const ASTRolesOrUsersSet & ast); RolesOrUsersSet(const ASTRolesOrUsersSet & ast, const std::optional & current_user_id); RolesOrUsersSet(const ASTRolesOrUsersSet & ast, const AccessControlManager & manager); RolesOrUsersSet(const ASTRolesOrUsersSet & ast, const AccessControlManager & manager, const std::optional & current_user_id); std::shared_ptr toAST() const; std::shared_ptr toASTWithNames(const AccessControlManager & manager) const; String toString() const; String toStringWithNames(const AccessControlManager & manager) const; Strings toStringsWithNames(const AccessControlManager & manager) const; bool empty() const; void clear(); void add(const UUID & id); void add(const std::vector & ids_); /// Checks if a specified ID matches this RolesOrUsersSet. bool match(const UUID & id) const; bool match(const UUID & user_id, const boost::container::flat_set & enabled_roles) const; /// Returns a list of matching IDs. The function must not be called if `all` == `true`. std::vector getMatchingIDs() const; /// Returns a list of matching users and roles. std::vector getMatchingIDs(const AccessControlManager & manager) const; friend bool operator ==(const RolesOrUsersSet & lhs, const RolesOrUsersSet & rhs); friend bool operator !=(const RolesOrUsersSet & lhs, const RolesOrUsersSet & rhs) { return !(lhs == rhs); } bool all = false; boost::container::flat_set ids; boost::container::flat_set except_ids; private: void init(const ASTRolesOrUsersSet & ast, const AccessControlManager * manager = nullptr, const std::optional & current_user_id = {}); }; }