MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
object_row_ownership.h
Go to the documentation of this file.
1
2/*
3 Copyright (c) 2021, 2025, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25*/
26
27#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_HELPER_OBJECT_ROW_OWNERSHIP_H_
28#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_HELPER_OBJECT_ROW_OWNERSHIP_H_
29
30#include <memory>
31#include <optional>
32#include <set>
33#include <string>
34
41
42namespace mrs {
43namespace database {
44
46 public:
51 std::vector<mrs::database::entry::RowGroupOwnership>;
52
53 ObjectRowOwnership(std::shared_ptr<entry::Table> table = {},
54 const RowUserOwnership *user_ownership = nullptr,
55 const std::optional<UserId> &user_id = {},
57 const std::set<UniversalId> &user_groups = {})
58 : m_table(table),
60 (user_ownership && user_ownership->user_ownership_enforced)
61 ? user_ownership->user_ownership_column
62 : ""),
63 m_user_id(!user_id.has_value() ? std::optional<mysqlrouter::sqlstring>()
64 : to_sqlstring(*user_id)),
67 assert(!enabled() || user_id.has_value());
68 }
69
70 ObjectRowOwnership(std::shared_ptr<entry::Table> table,
71 const std::string &column_name,
72 const mysqlrouter::sqlstring &user_id,
74 const std::set<UniversalId> &user_groups = {})
75 : m_table(table),
76 m_owner_column_name(column_name),
77 m_user_id(user_id),
80
82
83 const std::string &owner_column_name() const { return m_owner_column_name; }
84
85 bool enabled() const { return !m_owner_column_name.empty(); }
86
88 const entry::Column &column) const {
89 return enabled() && m_table->schema == table.schema &&
90 m_table->table == table.table &&
91 m_owner_column_name == column.column_name;
92 }
93
95
96 const std::set<UniversalId> user_groups() const { return m_user_groups; }
97
99 return mysqlrouter::sqlstring("(! = ?)")
101 }
102
104 return mysqlrouter::sqlstring("(!.! = ?)")
106 }
107
108 private:
109 std::shared_ptr<entry::Table> m_table;
111 std::optional<mysqlrouter::sqlstring> m_user_id;
113 const std::set<UniversalId> &m_user_groups;
114};
115
116} // namespace database
117} // namespace mrs
118
119#endif // ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_HELPER_OBJECT_ROW_OWNERSHIP_H_
Definition: object_row_ownership.h:45
std::vector< mrs::database::entry::RowGroupOwnership > VectorOfRowGroupOwnership
Definition: object_row_ownership.h:51
const VectorOfRowGroupOwnership & m_row_groups
Definition: object_row_ownership.h:112
ObjectRowOwnership(std::shared_ptr< entry::Table > table, const std::string &column_name, const mysqlrouter::sqlstring &user_id, const VectorOfRowGroupOwnership &row_groups={}, const std::set< UniversalId > &user_groups={})
Definition: object_row_ownership.h:70
const std::set< UniversalId > user_groups() const
Definition: object_row_ownership.h:96
const std::set< UniversalId > & m_user_groups
Definition: object_row_ownership.h:113
bool enabled() const
Definition: object_row_ownership.h:85
std::string m_owner_column_name
Definition: object_row_ownership.h:110
mysqlrouter::sqlstring owner_check_expr(const std::string &table_name) const
Definition: object_row_ownership.h:103
std::optional< mysqlrouter::sqlstring > m_user_id
Definition: object_row_ownership.h:111
bool is_owner_id(const entry::Table &table, const entry::Column &column) const
Definition: object_row_ownership.h:87
mysqlrouter::sqlstring owner_check_expr() const
Definition: object_row_ownership.h:98
std::shared_ptr< entry::Table > m_table
Definition: object_row_ownership.h:109
const mysqlrouter::sqlstring & owner_user_id() const
Definition: object_row_ownership.h:81
mrs::database::entry::AuthUser::UserId UserId
Definition: object_row_ownership.h:47
const std::string & owner_column_name() const
Definition: object_row_ownership.h:83
const VectorOfRowGroupOwnership & row_groups() const
Definition: object_row_ownership.h:94
mrs::database::entry::RowUserOwnership RowUserOwnership
Definition: object_row_ownership.h:48
ObjectRowOwnership(std::shared_ptr< entry::Table > table={}, const RowUserOwnership *user_ownership=nullptr, const std::optional< UserId > &user_id={}, const VectorOfRowGroupOwnership &row_groups={}, const std::set< UniversalId > &user_groups={})
Definition: object_row_ownership.h:53
mrs::database::entry::UniversalId UniversalId
Definition: object_row_ownership.h:49
Definition: utils_sqlstring.h:67
mrs::database::entry::RowUserOwnership RowUserOwnership
Definition: handler_db_object_table.cc:75
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
entry::Column Column
Definition: select.h:53
entry::Table Table
Definition: select.h:51
mysqlrouter::sqlstring sqlstring
Definition: query_retry_on_ro.cc:36
mysqlrouter::sqlstring to_sqlstring(entry::Column *dfield, Value *value)
Definition: filter_object_generator.cc:254
Definition: authorize_manager.h:48
mrs::database::entry::UniversalId UniversalId
Definition: universal_id.h:33
const char * table_name
Definition: rules_table_service.cc:56
UniversalId UserId
Definition: auth_user.h:48
Definition: row_user_ownership.h:35
std::string user_ownership_column
Definition: row_user_ownership.h:37
bool user_ownership_enforced
Definition: row_user_ownership.h:36