Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.5 KiB

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