|
| 1 | +/// \page page_whitelist IP/command whitelist |
| 2 | +///Whitelist functionality allows to specify xml-file with list of IP with allowed/denied commands. To pass whitelist file to WebDriver need to use "white-list" server option(\ref page_webdriver_switches) |
| 3 | +///\code |
| 4 | +/// -white-list=/path/to/whitelist.xml |
| 5 | +///\endcode |
| 6 | +///If no whitelist xml-file defined then all commands for all IP is allowed. |
| 7 | +/// |
| 8 | +///Example of whitelist.xml: |
| 9 | +///\code |
| 10 | +/// <?xml version="1.0" encoding="UTF-8"?> |
| 11 | +/// <hosts> |
| 12 | +/// <host ip="10.32.191.8"/> |
| 13 | +/// <host ip="192.27.27.7"> |
| 14 | +/// <deny url="/session/*/window/*" method="*"/> |
| 15 | +/// <deny url="/session/*/click" method="POST"/> |
| 16 | +/// </host> |
| 17 | +/// <host ip="192.34.191.7"> |
| 18 | +/// <allow url="/status" method="GET" /> |
| 19 | +/// </host> |
| 20 | +/// </hosts> |
| 21 | +///\endcode |
| 22 | +///*In this example: |
| 23 | +///* - if nothing is specified (10.32.191.8) all command is allowed for that IP; |
| 24 | +///* - if "allow" node is specified only these commands is allowed, other disallowed; |
| 25 | +///* - if "deny" node is specified this command will be disallowed, all other allowed; |
| 26 | +///* - if there will be "allow" and "deny" nodes for one IP, only "deny" will have effect, all other will be allowed; |
| 27 | +///* - for all other IP all commands will be disallowed; |
| 28 | +/// |
| 29 | +///To allow some command for any IP wildcard should be used: |
| 30 | +///\code |
| 31 | +/// <host ip="*"> |
| 32 | +/// <allow url="/status" method="GET" /> |
| 33 | +/// </host> |
| 34 | +///\endcode |
| 35 | +/// |
| 36 | +/// |
| 37 | +///There is <a href="whitelist.xsd" target="_blank"><b>xsd</b></a> file to validate/generate whitelist.xml |
| 38 | + |
| 39 | + |
1 | 40 | #ifndef WEBDRIVER_ACCESS_H |
2 | 41 | #define WEBDRIVER_ACCESS_H |
3 | 42 |
|
|
8 | 47 |
|
9 | 48 | namespace webdriver { |
10 | 49 |
|
11 | | -struct AccessCommandTable |
12 | | -{ |
13 | | - std::string method; |
14 | | - std::string url; |
15 | | -}; |
16 | | - |
17 | | -struct AccessRule { |
18 | | - long hostIp; |
19 | | - bool isGeneralRule; //for all ip |
20 | | - bool allowed; |
21 | | - std::vector<AccessCommandTable> commandList; |
22 | | -}; |
23 | | - |
| 50 | +/// Provides \ref page_whitelist functionality |
24 | 51 | class AccessValidator |
25 | 52 | { |
26 | 53 | public: |
27 | 54 | AccessValidator(); |
28 | 55 | ~AccessValidator(); |
| 56 | + |
| 57 | + ///Parse xml file with whitelist config |
| 58 | + ///@param xmlPath path to whitelist xml-file |
29 | 59 | void setWhiteList(FilePath &xmlPath); |
| 60 | + |
| 61 | + ///Check if given command is allowed for this IP |
| 62 | + ///@param remote_ip origin IP to check |
| 63 | + ///@param url command url |
| 64 | + ///@param method command method |
30 | 65 | bool isAllowed(const long &remote_ip, const std::string &url, const std::string &method); |
31 | 66 |
|
32 | 67 | private: |
| 68 | + |
| 69 | + struct AccessCommandTable |
| 70 | + { |
| 71 | + std::string method; |
| 72 | + std::string url; |
| 73 | + }; |
| 74 | + |
| 75 | + struct AccessRule { |
| 76 | + long hostIp; |
| 77 | + bool isGeneralRule; //for all ip |
| 78 | + bool allowed; |
| 79 | + std::vector<AccessCommandTable> commandList; |
| 80 | + }; |
| 81 | + |
33 | 82 | bool convertIpString(const char *str_ip, long *int_ip); |
34 | 83 | std::list<AccessRule> accessList; |
35 | 84 | }; |
|
0 commit comments