MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
user_manager.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_USERS_USER_MANAGIER_H_
27#define ROUTER_SRC_REST_MRS_SRC_MRS_USERS_USER_MANAGIER_H_
28
29#include <shared_mutex>
30
31#include "helper/cache/cache.h"
37
38namespace mrs {
39namespace users {
40
42 public:
46 using UserIndex = AuthUser::UserIndex;
51 std::vector<std::pair<database::entry::UniversalId, std::string>>;
53
54 public:
55 UserManager(const bool limit_to_existing_users,
56 const helper::Optional<UniversalId> &default_role_id,
57 QueryFactory *query_factory)
58 : limit_to_existing_users_{limit_to_existing_users},
59 default_role_id_{default_role_id},
60 query_factory_{query_factory} {}
61
62 bool user_get_by_id(UserId user_id, AuthUser *out_user,
63 SqlSessionCache *out_cache);
64 /**
65 * Find the user data inside a cache or DB.
66 *
67 * If the user entry provided to the function differs from
68 * the entry found (cache/db), then the DB entry is updated.
69 * This behavior is provided for accounts that are
70 * imported/managed by other sources like in case of OAUTH2.
71 */
72 bool user_get(AuthUser *out_user, SqlSessionCache *out_cache,
73 const bool update_changed = true);
74
75 void update_email(SqlSessionCache *out_cache, const UserId &id,
76 const std::optional<std::string> &email);
77 void user_invalidate(const UserId id);
78
79 void update_users_cache(const ChangedUsersIds &changed_users_ids);
80
81 private:
82 bool query_update_user(SqlSessionCache *out_cache, const UserId user_id,
83 AuthUser *out_user);
84 bool query_insert_user(SqlSessionCache *out_cache, AuthUser *out_user);
85 AuthUser *query_user(SqlSessionCache *out_cache, AuthUser *out_user,
86 bool *out_is_different);
87 AuthUser *cache_get(AuthUser *out_user, bool *out_is_different);
88
89 std::shared_mutex mutex_query_database_;
90 std::shared_mutex mutex_user_cache_;
95};
96
97} // namespace users
98} // namespace mrs
99
100#endif // ROUTER_SRC_REST_MRS_SRC_MRS_USERS_USER_MANAGIER_H_
Definition: cache_manager.h:41
Lightweight implementation of optional.
Definition: optional.h:39
Definition: lru.h:37
Definition: authorize_handler.h:53
collector::MysqlCacheManager::CachedObject SqlSessionCached
Definition: authorize_handler.h:55
Definition: query_factory.h:55
Definition: user_manager.h:41
AuthUser::UserIndex UserIndex
Definition: user_manager.h:46
bool user_get_by_id(UserId user_id, AuthUser *out_user, SqlSessionCache *out_cache)
Definition: user_manager.cc:103
bool limit_to_existing_users_
Definition: user_manager.h:92
void user_invalidate(const UserId id)
Definition: user_manager.cc:60
Handler::SqlSessionCached SqlSessionCache
Definition: user_manager.h:49
bool query_insert_user(SqlSessionCache *out_cache, AuthUser *out_user)
Definition: user_manager.cc:242
Cache user_cache_
Definition: user_manager.h:91
QueryFactory * query_factory_
Definition: user_manager.h:94
bool query_update_user(SqlSessionCache *out_cache, const UserId user_id, AuthUser *out_user)
Definition: user_manager.cc:233
const helper::Optional< UniversalId > default_role_id_
Definition: user_manager.h:93
database::entry::AuthUser AuthUser
Definition: user_manager.h:44
bool user_get(AuthUser *out_user, SqlSessionCache *out_cache, const bool update_changed=true)
Find the user data inside a cache or DB.
Definition: user_manager.cc:122
void update_email(SqlSessionCache *out_cache, const UserId &id, const std::optional< std::string > &email)
Definition: user_manager.cc:208
void update_users_cache(const ChangedUsersIds &changed_users_ids)
Definition: user_manager.cc:264
std::shared_mutex mutex_query_database_
Definition: user_manager.h:89
UserManager(const bool limit_to_existing_users, const helper::Optional< UniversalId > &default_role_id, QueryFactory *query_factory)
Definition: user_manager.h:55
std::vector< std::pair< database::entry::UniversalId, std::string > > ChangedUsersIds
Definition: user_manager.h:51
AuthUser * query_user(SqlSessionCache *out_cache, AuthUser *out_user, bool *out_is_different)
Definition: user_manager.cc:219
std::shared_mutex mutex_user_cache_
Definition: user_manager.h:90
AuthUser * cache_get(AuthUser *out_user, bool *out_is_different)
Definition: user_manager.cc:65
AuthUser::UserId UserId
Definition: user_manager.h:45
mrs::database::entry::AuthUser AuthUser
Definition: scram_handler.cc:54
QueryUuid::UserId UserId
Definition: query_uuid.cc:34
UserManager::AuthUser AuthUser
Definition: user_manager.cc:34
Definition: authorize_manager.h:48