2019-08-10 11:35:26 +00:00
|
|
|
#ifndef AdminSettingsService_h
|
|
|
|
#define AdminSettingsService_h
|
|
|
|
|
|
|
|
#include <SettingsService.h>
|
|
|
|
|
2020-02-01 08:44:26 +00:00
|
|
|
template <class T>
|
|
|
|
class AdminSettingsService : public SettingsService<T> {
|
2019-12-03 23:16:06 +00:00
|
|
|
public:
|
|
|
|
AdminSettingsService(AsyncWebServer* server,
|
|
|
|
FS* fs,
|
|
|
|
SecurityManager* securityManager,
|
|
|
|
char const* servicePath,
|
|
|
|
char const* filePath) :
|
2020-02-01 08:44:26 +00:00
|
|
|
SettingsService<T>(server, fs, servicePath, filePath),
|
2019-12-03 23:16:06 +00:00
|
|
|
_securityManager(securityManager) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// will validate the requests with the security manager
|
|
|
|
SecurityManager* _securityManager;
|
|
|
|
|
|
|
|
void fetchConfig(AsyncWebServerRequest* request) {
|
|
|
|
// verify the request against the predicate
|
|
|
|
Authentication authentication = _securityManager->authenticateRequest(request);
|
|
|
|
if (!getAuthenticationPredicate()(authentication)) {
|
|
|
|
request->send(401);
|
|
|
|
return;
|
2019-08-10 11:35:26 +00:00
|
|
|
}
|
2019-12-03 23:16:06 +00:00
|
|
|
// delegate to underlying implemetation
|
2020-02-01 08:44:26 +00:00
|
|
|
SettingsService<T>::fetchConfig(request);
|
2019-12-03 23:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateConfig(AsyncWebServerRequest* request, JsonDocument& jsonDocument) {
|
|
|
|
// verify the request against the predicate
|
|
|
|
Authentication authentication = _securityManager->authenticateRequest(request);
|
|
|
|
if (!getAuthenticationPredicate()(authentication)) {
|
|
|
|
request->send(401);
|
|
|
|
return;
|
2019-08-10 11:35:26 +00:00
|
|
|
}
|
2019-12-03 23:16:06 +00:00
|
|
|
// delegate to underlying implemetation
|
2020-02-01 08:44:26 +00:00
|
|
|
SettingsService<T>::updateConfig(request, jsonDocument);
|
2019-12-03 23:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// override this to replace the default authentication predicate, IS_ADMIN
|
|
|
|
AuthenticationPredicate getAuthenticationPredicate() {
|
|
|
|
return AuthenticationPredicates::IS_ADMIN;
|
|
|
|
}
|
2019-08-10 11:35:26 +00:00
|
|
|
};
|
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
#endif // end AdminSettingsService
|