MySQL 9.3.0
Source Code Documentation
query_changes_auth_app.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2025, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_REST_MRS_SRC_MRS_DATABASE_QUERY_CHANGES_AUTHENTICATION_H_
27#define ROUTER_SRC_REST_MRS_SRC_MRS_DATABASE_QUERY_CHANGES_AUTHENTICATION_H_
28
29#include <set>
30
34
35namespace mrs {
36namespace database {
37
38template <typename QueryForAuthApps = v2::QueryEntriesAuthApp, int version = 2>
39class QueryChangesAuthApp : public QueryForAuthApps {
40 public:
41 using Parent = QueryForAuthApps;
43 using Entries = typename Parent::Entries;
44
45 public:
46 QueryChangesAuthApp(const uint64_t last_audit_log_id) {
47 Parent::audit_log_id_ = last_audit_log_id;
48 }
49
50 void query_entries(MySQLSession *session) override {
51 QueryAuditLogEntries audit_entries;
52 Entries local_entries;
53 uint64_t max_audit_log_id = Parent::audit_log_id_;
54
55 entries_fetched.clear();
56
57 std::vector<std::string> allowed_changes{"auth_app", "auth_vendor",
58 "service_has_auth_app"};
59
60 if (version == 3) allowed_changes.push_back("service_has_auth_app");
61
62 audit_entries.query_entries(session, allowed_changes,
63 Parent::audit_log_id_);
64
65 for (const auto &audit_entry : audit_entries.entries) {
66 auto table = audit_entry.table;
67 if (audit_entry.old_table_id.has_value())
68 query_auth_entries(session, &local_entries, table,
69 audit_entry.old_table_id.value());
70
71 if (audit_entry.new_table_id.has_value())
72 query_auth_entries(session, &local_entries, table,
73 audit_entry.new_table_id.value());
74
75 if (max_audit_log_id < audit_entry.id) max_audit_log_id = audit_entry.id;
76 }
77
78 Parent::entries_.swap(local_entries);
79
80 Parent::audit_log_id_ = max_audit_log_id;
81 }
82
83 private:
85 const std::string &table_name,
86 const entry::UniversalId &id) {
87 Parent::entries_.clear();
88
90
91 for (const auto &entry : Parent::entries_) {
92 if (entries_fetched.count(entry.id)) continue;
93
94 out->push_back(entry);
95 entries_fetched.insert(entry.id);
96 }
97
98 if (Parent::entries_.empty() && table_name == "auth_app") {
100 pe.id = id;
101 pe.deleted = true;
102 entries_fetched.insert(id);
103 out->push_back(pe);
104 }
105 }
106
107 std::string build_query(std::string table_name,
108 const entry::UniversalId &id) {
109 if ("service_has_auth_app" == table_name) {
111 " WHERE subtable.auth_app_id in (SELECT shaa.`auth_app_id` FROM "
112 "`mysql_rest_service_metadata`.`service_has_auth_app` as shaa "
113 " WHERE `shaa`.`service_id`=? ) "};
114 where << id;
115 return Parent::query_.str() + where.str();
116 }
117
118 mysqlrouter::sqlstring where{" WHERE !=? "};
119 where << (table_name + "_id") << id;
120
121 return Parent::query_.str() + where.str();
122 }
123
124 std::set<entry::UniversalId> entries_fetched;
125};
126
127} // namespace database
128} // namespace mrs
129
130#endif // ROUTER_SRC_REST_MRS_SRC_MRS_DATABASE_QUERY_CHANGES_AUTHENTICATION_H_
mysqlrouter::MySQLSession MySQLSession
Definition: bootstrap_mysql_account.cc:41
Definition: query_entries_audit_log.h:37
VectorOfAuditEntries entries
Definition: query_entries_audit_log.h:48
virtual uint64_t query_entries(MySQLSession *session, const std::vector< std::string > &allowed_tables, const uint64_t audit_log_id)
Definition: query_entries_audit_log.cc:34
Definition: query_changes_auth_app.h:39
QueryChangesAuthApp(const uint64_t last_audit_log_id)
Definition: query_changes_auth_app.h:46
std::set< entry::UniversalId > entries_fetched
Definition: query_changes_auth_app.h:124
QueryForAuthApps Parent
Definition: query_changes_auth_app.h:41
std::string build_query(std::string table_name, const entry::UniversalId &id)
Definition: query_changes_auth_app.h:107
void query_entries(MySQLSession *session) override
Definition: query_changes_auth_app.h:50
void query_auth_entries(MySQLSession *session, Entries *out, const std::string &table_name, const entry::UniversalId &id)
Definition: query_changes_auth_app.h:84
typename Parent::Entries Entries
Definition: query_changes_auth_app.h:43
UniversalId id
Definition: auth_app.h:43
Definition: mysql_session.h:157
Definition: utils_sqlstring.h:67
static char * query
Definition: myisam_ftdump.cc:47
static char * where
Definition: mysqldump.cc:153
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
mrs::database::entry::AuthApp AuthApp
Definition: oauth2_handler.cc:58
QueryEntriesAuthApp::Entries Entries
Definition: query_entries_auth_app.cc:36
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
required uint64 version
Definition: replication_group_member_actions.proto:41
Definition: completion_hash.h:35
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510