External config

Allow config to be accessed from outside the framework core code.
This commit is contained in:
rjwats
2020-02-01 08:44:26 +00:00
committed by GitHub
parent 0ca9530afa
commit 39a86b0411
19 changed files with 422 additions and 251 deletions

View File

@ -10,14 +10,39 @@
#define SECURITY_SETTINGS_FILE "/config/securitySettings.json"
#define SECURITY_SETTINGS_PATH "/rest/securitySettings"
class SecuritySettingsService : public AdminSettingsService, public SecurityManager {
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