MySQL 9.3.0
Source Code Documentation
auth_user.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, 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_ENTRY_AUTH_USER_H_
27#define ROUTER_SRC_REST_MRS_SRC_MRS_DATABASE_ENTRY_AUTH_USER_H_
28
29#include <cstring>
30#include <initializer_list>
31#include <map>
32#include <set>
33#include <string>
34#include <vector>
35
39#include "secure_string.h" // NOLINT(build/include_subdir)
40
42
43namespace mrs {
44namespace database {
45namespace entry {
46
47struct AuthUser {
49
50 class UserIndex {
51 public:
53 UserIndex(const std::string &vendor_id) : vendor_user_id{vendor_id} {}
54 UserIndex(const UserId id) : has_user_id{true}, user_id{id} {}
55 UserIndex(const AuthUser &other) { *this = other; }
57 : has_user_id{other.has_user_id},
58 user_id{other.user_id},
59 vendor_user_id{std::move(other.vendor_user_id)} {}
60
61 UserIndex &operator=(const AuthUser &other) {
62 has_user_id = other.has_user_id;
63 user_id = other.user_id;
64 vendor_user_id = other.vendor_user_id;
65
66 return *this;
67 }
68
69 bool operator==(const UserIndex &other) const {
70 if (has_user_id && other.has_user_id) {
71 return user_id == other.user_id;
72 }
73
74 if (vendor_user_id.empty()) return false;
75 if (other.vendor_user_id.empty()) return false;
76
77 return vendor_user_id.compare(other.vendor_user_id) == 0;
78 }
79
80 bool operator<(const UserIndex &other) const {
81 if (has_user_id && other.has_user_id) {
82 return user_id < other.user_id;
83 }
84
85 if (vendor_user_id.empty()) return true;
86 if (other.vendor_user_id.empty()) return true;
87
88 return vendor_user_id.compare(other.vendor_user_id) < 0;
89 }
90
91 std::string to_string() const {
92 std::string result = "{";
93 result += "vendor_id:" + vendor_user_id;
94 if (has_user_id) result += ", user_id:" + user_id.to_string();
95
96 result += "}";
97 return result;
98 }
99
100 bool has_user_id{false};
101 UserId user_id{};
102 std::string vendor_user_id;
103 };
104
105 AuthUser() = default;
106 AuthUser(const AuthUser &) = default;
107 AuthUser &operator=(const AuthUser &) = default;
108
109 ~AuthUser() = default;
110
111 bool has_user_id{false};
114 std::string name;
115 std::string email;
116 std::string auth_string;
117 std::string vendor_user_id;
118 bool login_permitted{true};
119 std::vector<AuthPrivilege> privileges;
120 std::set<UniversalId> groups;
121 std::string options;
122
123 bool is_mysql_auth{false};
125};
126
127inline std::string to_string(const AuthUser &ud) {
128 using std::to_string;
129 std::string result{"{"};
130 bool first = true;
131 std::map<std::string, std::string> map;
132
133 if (ud.has_user_id) map["user_id"] = ud.user_id.to_string();
134 if (!ud.name.empty()) map["name"] = ud.name;
135 if (!ud.email.empty()) map["email"] = ud.email;
136 if (!ud.vendor_user_id.empty()) map["vendor_user_id"] = ud.vendor_user_id;
137 if (!ud.auth_string.empty()) map["auth_string"] = ud.auth_string;
138 map["login_permitted"] = ud.login_permitted ? "true" : "false";
139
140 for (const auto &kv : map) {
141 result += (first ? "'" : ", '");
142 result += kv.first + "':'";
143 result += kv.second + "'";
144
145 first = false;
146 }
147
148 result += "}";
149 return result;
150}
151
152} // namespace entry
153} // namespace database
154} // namespace mrs
155
156#endif // ROUTER_SRC_REST_MRS_SRC_MRS_DATABASE_ENTRY_AUTH_USER_H_
UserIndex(const AuthUser &other)
Definition: auth_user.h:55
UserIndex(const std::string &vendor_id)
Definition: auth_user.h:53
bool operator<(const UserIndex &other) const
Definition: auth_user.h:80
UserIndex & operator=(const AuthUser &other)
Definition: auth_user.h:61
std::string vendor_user_id
Definition: auth_user.h:102
UserIndex(AuthUser &&other)
Definition: auth_user.h:56
bool has_user_id
Definition: auth_user.h:100
bool operator==(const UserIndex &other) const
Definition: auth_user.h:69
UserIndex()
Definition: auth_user.h:52
std::string to_string() const
Definition: auth_user.h:91
UserIndex(const UserId id)
Definition: auth_user.h:54
UserId user_id
Definition: auth_user.h:101
Null-terminated string which is securely wiped on destruction.
Definition: secure_string.h:59
Logging interface for using and extending the logging subsystem.
#define IMPORT_LOG_FUNCTIONS()
convenience macro to avoid common boilerplate
Definition: logging.h:323
std::string to_string(const AuthUser &ud)
Definition: auth_user.h:127
Definition: authorize_manager.h:48
mrs::database::entry::UniversalId UniversalId
Definition: universal_id.h:33
Definition: gcs_xcom_synode.h:64
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2894
struct result result
Definition: result.h:34
Definition: completion_hash.h:35
Definition: auth_user.h:47
std::string options
Definition: auth_user.h:121
mysql_harness::SecureString mysql_password
Definition: auth_user.h:124
AuthUser(const AuthUser &)=default
UserId user_id
Definition: auth_user.h:112
std::string auth_string
Definition: auth_user.h:116
std::string vendor_user_id
Definition: auth_user.h:117
std::string email
Definition: auth_user.h:115
AuthUser & operator=(const AuthUser &)=default
UniversalId app_id
Definition: auth_user.h:113
std::set< UniversalId > groups
Definition: auth_user.h:120
bool login_permitted
Definition: auth_user.h:118
std::vector< AuthPrivilege > privileges
Definition: auth_user.h:119
bool has_user_id
Definition: auth_user.h:111
std::string name
Definition: auth_user.h:114
Definition: universal_id.h:45
std::string to_string() const
Definition: universal_id.h:119
Definition: result.h:30
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510