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.

49 lines
1.6 KiB

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