MySQL 9.4.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
41
42namespace mrs {
43namespace database {
44namespace entry {
45
46struct AuthUser {
48
49 class UserIndex {
50 public:
52 UserIndex(const std::string &vendor_id) : vendor_user_id{vendor_id} {}
53 UserIndex(const UserId id) : has_user_id{true}, user_id{id} {}
54 UserIndex(const AuthUser &other) { *this = other; }
56 : has_user_id{other.has_user_id},
57 user_id{other.user_id},
58 vendor_user_id{std::move(other.vendor_user_id)} {}
59
60 UserIndex &operator=(const AuthUser &other) {
61 has_user_id = other.has_user_id;
62 user_id = other.user_id;
63 vendor_user_id = other.vendor_user_id;
64
65 return *this;
66 }
67
68 bool operator==(const UserIndex &other) const {
69 if (has_user_id && other.has_user_id) {
70 return user_id == other.user_id;
71 }
72
73 if (vendor_user_id.empty()) return false;
74 if (other.vendor_user_id.empty()) return false;
75
76 return vendor_user_id.compare(other.vendor_user_id) == 0;
77 }
78
79 bool operator<(const UserIndex &other) const {
80 if (has_user_id && other.has_user_id) {
81 return user_id < other.user_id;
82 }
83
84 if (vendor_user_id.empty()) return true;
85 if (other.vendor_user_id.empty()) return true;
86
87 return vendor_user_id.compare(other.vendor_user_id) < 0;
88 }
89
90 std::string to_string() const {
91 std::string result = "{";
92 result += "vendor_id:" + vendor_user_id;
93 if (has_user_id) result += ", user_id:" + user_id.to_string();
94
95 result += "}";
96 return result;
97 }
98
99 bool has_user_id{false};
100 UserId user_id{};
101 std::string vendor_user_id;
102 };
103
104 AuthUser() = default;
105 AuthUser(const AuthUser &) = default;
106 AuthUser &operator=(const AuthUser &) = default;
107
108 ~AuthUser() = default;
109
110 bool has_user_id{false};
113 std::string name;
114 std::string email;
115 std::string auth_string;
116 std::string vendor_user_id;
117 bool login_permitted{true};
118 std::vector<AuthPrivilege> privileges;
119 std::set<UniversalId> groups;
120 std::string options;
121};
122
123inline std::string to_string(const AuthUser &ud) {
124 using std::to_string;
125 std::string result{"{"};
126 bool first = true;
127 std::map<std::string, std::string> map;
128
129 if (ud.has_user_id) map["user_id"] = ud.user_id.to_string();
130 if (!ud.name.empty()) map["name"] = ud.name;
131 if (!ud.email.empty()) map["email"] = ud.email;
132 if (!ud.vendor_user_id.empty()) map["vendor_user_id"] = ud.vendor_user_id;
133 if (!ud.auth_string.empty()) map["auth_string"] = ud.auth_string;
134 map["login_permitted"] = ud.login_permitted ? "true" : "false";
135
136 for (const auto &kv : map) {
137 result += (first ? "'" : ", '");
138 result += kv.first + "':'";
139 result += kv.second + "'";
140
141 first = false;
142 }
143
144 result += "}";
145 return result;
146}
147
148} // namespace entry
149} // namespace database
150} // namespace mrs
151
152#endif // ROUTER_SRC_REST_MRS_SRC_MRS_DATABASE_ENTRY_AUTH_USER_H_
UserIndex(const AuthUser &other)
Definition: auth_user.h:54
UserIndex(const std::string &vendor_id)
Definition: auth_user.h:52
bool operator<(const UserIndex &other) const
Definition: auth_user.h:79
UserIndex & operator=(const AuthUser &other)
Definition: auth_user.h:60
std::string vendor_user_id
Definition: auth_user.h:101
UserIndex(AuthUser &&other)
Definition: auth_user.h:55
bool has_user_id
Definition: auth_user.h:99
bool operator==(const UserIndex &other) const
Definition: auth_user.h:68
UserIndex()
Definition: auth_user.h:51
std::string to_string() const
Definition: auth_user.h:90
UserIndex(const UserId id)
Definition: auth_user.h:53
UserId user_id
Definition: auth_user.h:100
Logging interface for using and extending the logging subsystem.
#define IMPORT_LOG_FUNCTIONS()
convenience macro to avoid common boilerplate
Definition: logging.h:331
std::string to_string(const AuthUser &ud)
Definition: auth_user.h:123
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:46
std::string options
Definition: auth_user.h:120
AuthUser(const AuthUser &)=default
UserId user_id
Definition: auth_user.h:111
std::string auth_string
Definition: auth_user.h:115
std::string vendor_user_id
Definition: auth_user.h:116
std::string email
Definition: auth_user.h:114
AuthUser & operator=(const AuthUser &)=default
UniversalId app_id
Definition: auth_user.h:112
std::set< UniversalId > groups
Definition: auth_user.h:119
bool login_permitted
Definition: auth_user.h:117
std::vector< AuthPrivilege > privileges
Definition: auth_user.h:118
bool has_user_id
Definition: auth_user.h:110
std::string name
Definition: auth_user.h:113
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