esp8266-react-framework/lib/framework/SecuritySettingsService.h
rjwats 39a86b0411
External config
Allow config to be accessed from outside the framework core code.
2020-02-01 08:44:26 +00:00

48 lines
1.3 KiB
C++

#ifndef SecuritySettingsService_h
#define SecuritySettingsService_h
#include <AdminSettingsService.h>
#include <SecurityManager.h>
#define DEFAULT_ADMIN_USERNAME "admin"
#define DEFAULT_GUEST_USERNAME "guest"
#define SECURITY_SETTINGS_FILE "/config/securitySettings.json"
#define SECURITY_SETTINGS_PATH "/rest/securitySettings"
class SecuritySettings {
public:
String jwtSecret;
std::list<User> users;
};
class SecuritySettingsService : public AdminSettingsService<SecuritySettings>, public SecurityManager {
public:
SecuritySettingsService(AsyncWebServer* server, FS* fs);
~SecuritySettingsService();
// Functions to implement SecurityManager
Authentication authenticate(String username, String password);
Authentication authenticateRequest(AsyncWebServerRequest* request);
String generateJWT(User* user);
ArRequestHandlerFunction wrapRequest(ArRequestHandlerFunction onRequest, AuthenticationPredicate predicate);
protected:
void readFromJsonObject(JsonObject& root);
void writeToJsonObject(JsonObject& root);
private:
ArduinoJsonJWT _jwtHandler = ArduinoJsonJWT(DEFAULT_JWT_SECRET);
/*
* Lookup the user by JWT
*/
Authentication authenticateJWT(String jwt);
/*
* Verify the payload is correct
*/
boolean validatePayload(JsonObject& parsedPayload, User* user);
};
#endif // end SecuritySettingsService_h