|
4 | 4 | #include <SettingsService.h> |
5 | 5 |
|
6 | 6 | class AdminSettingsService : public SettingsService { |
7 | | - |
8 | | - public: |
9 | | - AdminSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager, char const* servicePath, char const* filePath): |
10 | | - SettingsService(server, fs, servicePath, filePath), _securityManager(securityManager) {} |
11 | | - |
12 | | - protected: |
13 | | - // will validate the requests with the security manager |
14 | | - SecurityManager* _securityManager; |
15 | | - |
16 | | - void fetchConfig(AsyncWebServerRequest *request) { |
17 | | - // verify the request against the predicate |
18 | | - Authentication authentication = _securityManager->authenticateRequest(request); |
19 | | - if (!getAuthenticationPredicate()(authentication)) { |
20 | | - request->send(401); |
21 | | - return; |
22 | | - } |
23 | | - // delegate to underlying implemetation |
24 | | - SettingsService::fetchConfig(request); |
25 | | - } |
26 | | - |
27 | | - void updateConfig(AsyncWebServerRequest *request, JsonDocument &jsonDocument) { |
28 | | - // verify the request against the predicate |
29 | | - Authentication authentication = _securityManager->authenticateRequest(request); |
30 | | - if (!getAuthenticationPredicate()(authentication)) { |
31 | | - request->send(401); |
32 | | - return; |
33 | | - } |
34 | | - // delegate to underlying implemetation |
35 | | - SettingsService::updateConfig(request, jsonDocument); |
| 7 | + public: |
| 8 | + AdminSettingsService(AsyncWebServer* server, |
| 9 | + FS* fs, |
| 10 | + SecurityManager* securityManager, |
| 11 | + char const* servicePath, |
| 12 | + char const* filePath) : |
| 13 | + SettingsService(server, fs, servicePath, filePath), |
| 14 | + _securityManager(securityManager) { |
| 15 | + } |
| 16 | + |
| 17 | + protected: |
| 18 | + // will validate the requests with the security manager |
| 19 | + SecurityManager* _securityManager; |
| 20 | + |
| 21 | + void fetchConfig(AsyncWebServerRequest* request) { |
| 22 | + // verify the request against the predicate |
| 23 | + Authentication authentication = _securityManager->authenticateRequest(request); |
| 24 | + if (!getAuthenticationPredicate()(authentication)) { |
| 25 | + request->send(401); |
| 26 | + return; |
36 | 27 | } |
37 | | - |
38 | | - // override this to replace the default authentication predicate, IS_ADMIN |
39 | | - AuthenticationPredicate getAuthenticationPredicate() { |
40 | | - return AuthenticationPredicates::IS_ADMIN; |
| 28 | + // delegate to underlying implemetation |
| 29 | + SettingsService::fetchConfig(request); |
| 30 | + } |
| 31 | + |
| 32 | + void updateConfig(AsyncWebServerRequest* request, JsonDocument& jsonDocument) { |
| 33 | + // verify the request against the predicate |
| 34 | + Authentication authentication = _securityManager->authenticateRequest(request); |
| 35 | + if (!getAuthenticationPredicate()(authentication)) { |
| 36 | + request->send(401); |
| 37 | + return; |
41 | 38 | } |
42 | | - |
| 39 | + // delegate to underlying implemetation |
| 40 | + SettingsService::updateConfig(request, jsonDocument); |
| 41 | + } |
| 42 | + |
| 43 | + // override this to replace the default authentication predicate, IS_ADMIN |
| 44 | + AuthenticationPredicate getAuthenticationPredicate() { |
| 45 | + return AuthenticationPredicates::IS_ADMIN; |
| 46 | + } |
43 | 47 | }; |
44 | 48 |
|
45 | | -#endif // end AdminSettingsService |
| 49 | +#endif // end AdminSettingsService |
0 commit comments