ORE Studio 0.0.4
Loading...
Searching...
No Matches
accounts_message_handler.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_IAM_MESSAGING_ACCOUNTS_MESSAGE_HANDLER_HPP
21#define ORES_IAM_MESSAGING_ACCOUNTS_MESSAGE_HANDLER_HPP
22
23#include <memory>
24#include "ores.database/domain/context.hpp"
25#include "ores.logging/make_logger.hpp"
26#include "ores.comms/messaging/message_handler.hpp"
27#include "ores.comms/service/auth_session_service.hpp"
28#include "ores.iam/service/account_service.hpp"
29#include "ores.iam/service/account_setup_service.hpp"
30#include "ores.iam/service/authorization_service.hpp"
31#include "ores.iam/repository/session_repository.hpp"
32#include "ores.variability/service/system_flags_service.hpp"
33#include "ores.geo/service/geolocation_service.hpp"
34#include "ores.iam/messaging/bootstrap_protocol.hpp"
35
36namespace ores::iam::messaging {
37
44using bundle_provider_fn = std::function<std::vector<bootstrap_bundle_info>()>;
45
80private:
81 [[nodiscard]] static auto& lg() {
82 using namespace ores::logging;
83 static auto instance = make_logger(
84 "ores.iam.messaging.accounts_message_handler");
85 return instance;
86 }
87
88public:
100 std::shared_ptr<variability::service::system_flags_service> system_flags,
101 std::shared_ptr<comms::service::auth_session_service> sessions,
102 std::shared_ptr<service::authorization_service> auth_service,
103 std::shared_ptr<geo::service::geolocation_service> geo_service,
104 bundle_provider_fn bundle_provider = nullptr);
105
106 using handler_result = boost::asio::awaitable<
107 std::expected<std::vector<std::byte>, ores::utility::serialization::error_code>
108 >;
109
118 handler_result
119 handle_message(comms::messaging::message_type type,
120 std::span<const std::byte> payload,
121 const std::string& remote_address) override;
122
123private:
129 handler_result
130 handle_save_account_request(std::span<const std::byte> payload,
131 const std::string& remote_address);
132
138 handler_result
139 handle_get_accounts_request(std::span<const std::byte> payload,
140 const std::string& remote_address);
141
147 handler_result
148 handle_list_login_info_request(std::span<const std::byte> payload,
149 const std::string& remote_address);
150
154 handler_result
155 handle_login_request(std::span<const std::byte> payload,
156 const std::string& remote_address);
157
163 handler_result
164 handle_lock_account_request(std::span<const std::byte> payload,
165 const std::string& remote_address);
166
172 handler_result
173 handle_unlock_account_request(std::span<const std::byte> payload,
174 const std::string& remote_address);
175
181 handler_result
182 handle_delete_account_request(std::span<const std::byte> payload,
183 const std::string& remote_address);
184
190 handler_result
191 handle_create_initial_admin_request(std::span<const std::byte> payload,
192 const std::string& remote_address);
193
199 handler_result
200 handle_bootstrap_status_request(std::span<const std::byte> payload);
201
207 handler_result
208 handle_logout_request(std::span<const std::byte> payload,
209 const std::string& remote_address);
210
216 handler_result
217 handle_get_account_history_request(std::span<const std::byte> payload,
218 const std::string& remote_address);
219
226 handler_result
227 handle_reset_password_request(std::span<const std::byte> payload,
228 const std::string& remote_address);
229
236 handler_result
237 handle_change_password_request(std::span<const std::byte> payload,
238 const std::string& remote_address);
239
245 handler_result
246 handle_update_my_email_request(std::span<const std::byte> payload,
247 const std::string& remote_address);
248
255 handler_result
256 handle_signup_request(std::span<const std::byte> payload);
257
258 // =========================================================================
259 // RBAC Handlers
260 // =========================================================================
261
267 handler_result
268 handle_list_roles_request(std::span<const std::byte> payload,
269 const std::string& remote_address);
270
276 handler_result
277 handle_list_permissions_request(std::span<const std::byte> payload,
278 const std::string& remote_address);
279
285 handler_result
286 handle_get_role_request(std::span<const std::byte> payload,
287 const std::string& remote_address);
288
294 handler_result
295 handle_assign_role_request(std::span<const std::byte> payload,
296 const std::string& remote_address);
297
303 handler_result
304 handle_revoke_role_request(std::span<const std::byte> payload,
305 const std::string& remote_address);
306
312 handler_result
313 handle_get_account_roles_request(std::span<const std::byte> payload,
314 const std::string& remote_address);
315
321 handler_result
322 handle_get_account_permissions_request(std::span<const std::byte> payload,
323 const std::string& remote_address);
324
331 static bool is_localhost(const std::string& remote_address);
332
338 using auth_check_result = std::expected<
340 ores::utility::serialization::error_code
341 >;
342
354 auth_check_result check_authorization(
355 const std::string& remote_address,
356 std::string_view permission,
357 std::string_view operation_name);
358
368 auth_check_result get_authenticated_session(
369 const std::string& remote_address,
370 std::string_view operation_name);
371
378 handler_result
379 handle_list_sessions_request(std::span<const std::byte> payload,
380 const std::string& remote_address);
381
388 handler_result
389 handle_get_session_statistics_request(std::span<const std::byte> payload,
390 const std::string& remote_address);
391
398 handler_result
399 handle_get_active_sessions_request(std::span<const std::byte> payload,
400 const std::string& remote_address);
401
404 std::shared_ptr<variability::service::system_flags_service> system_flags_;
405 std::shared_ptr<comms::service::auth_session_service> sessions_;
406 std::shared_ptr<service::authorization_service> auth_service_;
407 service::account_setup_service setup_service_;
408 repository::session_repository session_repo_;
409 std::shared_ptr<geo::service::geolocation_service> geo_service_;
410 bundle_provider_fn bundle_provider_;
411};
412
413}
414
415#endif
Network messaging infrastructure for the IAM module.
Definition account_history_protocol.hpp:33
std::function< std::vector< bootstrap_bundle_info >()> bundle_provider_fn
Function type for fetching available bundles during bootstrap.
Definition accounts_message_handler.hpp:44
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Abstract interface for handling messages from a subsystem.
Definition message_handler.hpp:66
Lightweight session info for backward compatibility.
Definition auth_session_service.hpp:43
Context for the operations on a postgres database.
Definition context.hpp:30
Message handler for accounts subsystem messages.
Definition accounts_message_handler.hpp:79
handler_result handle_message(comms::messaging::message_type type, std::span< const std::byte > payload, const std::string &remote_address) override
Handle an accounts subsystem message.
Definition accounts_message_handler.cpp:54
Repository for session persistence and querying.
Definition session_repository.hpp:40
Service for managing user accounts including creation, listing, and deletion.
Definition account_service.hpp:39
Centralized service for complete account initialization.
Definition account_setup_service.hpp:42