#pragma once #include #include #include #include namespace DB { class ASTExtendedRoleSet; class AccessControlManager; /// Represents a set of users/roles like /// {user_name | role_name | CURRENT_USER} [,...] | NONE | ALL | ALL EXCEPT {user_name | role_name | CURRENT_USER} [,...] /// Similar to ASTExtendedRoleSet, but with IDs instead of names. struct ExtendedRoleSet { ExtendedRoleSet(); ExtendedRoleSet(const ExtendedRoleSet & src); ExtendedRoleSet & operator =(const ExtendedRoleSet & src); ExtendedRoleSet(ExtendedRoleSet && src); ExtendedRoleSet & operator =(ExtendedRoleSet && src); struct AllTag {}; ExtendedRoleSet(AllTag); ExtendedRoleSet(const UUID & id); ExtendedRoleSet(const std::vector & ids_); ExtendedRoleSet(const boost::container::flat_set & ids_); /// The constructor from AST requires the AccessControlManager if `ast.id_mode == false`. ExtendedRoleSet(const ASTExtendedRoleSet & ast); ExtendedRoleSet(const ASTExtendedRoleSet & ast, const UUID & current_user_id); ExtendedRoleSet(const ASTExtendedRoleSet & ast, const AccessControlManager & manager); ExtendedRoleSet(const ASTExtendedRoleSet & ast, const AccessControlManager & manager, const UUID & current_user_id); std::shared_ptr toAST() const; String toString() const; Strings toStrings() const; std::shared_ptr toASTWithNames(const AccessControlManager & manager) 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_); void add(const boost::container::flat_set & ids_); /// Checks if a specified ID matches this ExtendedRoleSet. bool match(const UUID & id) const; bool match(const UUID & user_id, const std::vector & enabled_roles) 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 ExtendedRoleSet & lhs, const ExtendedRoleSet & rhs); friend bool operator !=(const ExtendedRoleSet & lhs, const ExtendedRoleSet & rhs) { return !(lhs == rhs); } boost::container::flat_set ids; bool all = false; boost::container::flat_set except_ids; private: void init(const ASTExtendedRoleSet & ast, const AccessControlManager * manager = nullptr, const UUID * current_user_id = nullptr); }; }