-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathAuthenticationOperator.cpp
More file actions
59 lines (46 loc) · 1.77 KB
/
AuthenticationOperator.cpp
File metadata and controls
59 lines (46 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Local private includes
#include "AuthenticationOperator.hpp"
// Local public includes
#include "common/TraceException.hpp"
#include "common/DynaLog.hpp"
// Standard includes
#include <any>
#include <iostream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
namespace SDMS {
AuthenticationOperator::AuthenticationOperator(std::any &options) {
try {
m_authentication_manager = std::any_cast<IAuthenticationManager *>(options);
} catch (std::bad_cast &error) {
std::cerr << "Caught bad any cast in AuthenticationOperator constructor."
<< error.what() << std::endl;
}
}
void AuthenticationOperator::execute(IMessage &message) {
if (message.exists(MessageAttribute::KEY) == 0) {
EXCEPT(1, "'KEY' attribute not defined.");
}
// 🔹 Generate correlation ID for this request
boost::uuids::random_generator generator;
boost::uuids::uuid uuid = generator();
LogContext log_context;
log_context.correlation_id = boost::uuids::to_string(uuid);
m_authentication_manager->purge();
std::string key = std::get<std::string>(message.get(MessageAttribute::KEY));
std::string uid = "anon";
if (m_authentication_manager->hasKey(key, log_context)) {
m_authentication_manager->incrementKeyAccessCounter(key, log_context);
try {
uid = m_authentication_manager->getUID(key, log_context);
} catch (const std::exception& e) {
// Log the exception to help diagnose authentication issues
std::cerr << "[AuthenticationOperator] Failed to get UID for key: "
<< key.substr(0, 8) << "... Exception: " << e.what() << std::endl;
// Keep uid as "anon" if we fail to get the actual UID
}
}
message.set(MessageAttribute::ID, uid);
}
} // namespace SDMS