forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SessionManager.h
50 lines (40 loc) · 897 Bytes
/
SessionManager.h
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
#pragma once
#include <unordered_set>
#include <unordered_map>
#define RPC_ADMIN if (!m_sm.hasPrivilegeLevel(_session, Privilege::Admin)) throw jsonrpc::JsonRpcException("Invalid privileges");
namespace dev
{
namespace rpc
{
enum class Privilege
{
Admin
};
}
}
namespace std
{
template<> struct hash<dev::rpc::Privilege>
{
size_t operator()(dev::rpc::Privilege _value) const { return (size_t)_value; }
};
}
namespace dev
{
namespace rpc
{
struct SessionPermissions
{
std::unordered_set<Privilege> privileges;
};
class SessionManager
{
public:
std::string newSession(SessionPermissions const& _p);
void addSession(std::string const& _session, SessionPermissions const& _p);
bool hasPrivilegeLevel(std::string const& _session, Privilege _l) const;
private:
std::unordered_map<std::string, SessionPermissions> m_sessions;
};
}
}