forked from joyieldInc/predixy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAuth.h
67 lines (60 loc) · 1.29 KB
/
Auth.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* predixy - A high performance and full features proxy for redis.
* Copyright (C) 2017 Joyield, Inc. <[email protected]>
* All rights reserved.
*/
#ifndef _PREDIXY_AUTH_H_
#define _PREDIXY_AUTH_H_
#include <map>
#include <set>
#include <vector>
#include "Predixy.h"
class Auth
{
public:
Auth(int mode = Command::Read|Command::Write|Command::Admin);
Auth(const AuthConf& conf);
~Auth();
const String& password() const
{
return mPassword;
}
const String& namePrefix() const
{
return mNamePrefix;
}
bool permission(Request* req, const String& key) const;
private:
String mPassword;
int mMode;
typedef std::set<String> KeyPrefixSet;
KeyPrefixSet* mReadKeyPrefix;
KeyPrefixSet* mWriteKeyPrefix;
String mNamePrefix;
};
class Authority
{
public:
Authority();
~Authority();
bool hasAuth() const
{
return !mAuthMap.empty();
}
Auth* get(const String& pd) const
{
auto it = mAuthMap.find(pd);
return it == mAuthMap.end() ? nullptr : it->second;
}
Auth* getDefault() const
{
return mDefault;
}
void add(const AuthConf& ac);
private:
std::map<String, Auth*> mAuthMap;
Auth* mDefault;
static Auth AuthAllowAll;
static Auth AuthDenyAll;
};
#endif