-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathCondition.cpp
More file actions
52 lines (44 loc) · 1.75 KB
/
Condition.cpp
File metadata and controls
52 lines (44 loc) · 1.75 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
// Local private includes
#include "Condition.hpp"
// Standard includes
#include <iostream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
namespace SDMS {
namespace Core {
void Promote::enforce(AuthMap &auth_map, const std::string &public_key) {
if (auth_map.hasKeyType(m_promote_from, public_key)) {
size_t access_count = auth_map.getAccessCount(m_promote_from, public_key);
boost::uuids::random_generator generator;
boost::uuids::uuid uuid = generator();
LogContext log_context;
log_context.correlation_id = boost::uuids::to_string(uuid);
if (access_count >= m_transient_to_session_count_threshold) {
// Convert transient key to session key if has been accessed more than the
// threshold
std::string uid = auth_map.getUID(m_promote_from, public_key, log_context);
auth_map.addKey(m_promote_to, public_key, uid);
}
// Remove expired short lived transient key
auth_map.removeKey(m_promote_from, public_key);
// Set the access counter so that it doesn't get prematurely removed
auth_map.setAccessCount(m_promote_to, public_key, access_count);
}
}
void Reset::enforce(AuthMap &auth_map, const std::string &public_key) {
if (auth_map.hasKeyType(m_act_on_key_type, public_key)) {
size_t access_count =
auth_map.getAccessCount(m_act_on_key_type, public_key);
if (access_count >= m_access_attempts) {
// If the session key has been accessed within the threshold then reset
// the active period
auth_map.resetKey(m_act_on_key_type, public_key);
} else {
// If the key has not been used then remove it.
auth_map.removeKey(m_act_on_key_type, public_key);
}
}
}
} // namespace Core
} // namespace SDMS