🪄 Formats SecurityManager

This commit is contained in:
Rune Harlyk
2024-07-09 20:05:49 +02:00
committed by Rune Harlyk
parent 4e5f582978
commit c47a7bc02f
+21 -39
View File
@@ -28,60 +28,40 @@
#define MAX_JWT_SIZE 128 #define MAX_JWT_SIZE 128
class User class User {
{ public:
public:
String username; String username;
String password; String password;
bool admin; bool admin;
public: public:
User(String username, String password, bool admin) : username(username), password(password), admin(admin) User(String username, String password, bool admin) : username(username), password(password), admin(admin) {}
{
}
}; };
class Authentication class Authentication {
{ public:
public:
User *user; User *user;
boolean authenticated; boolean authenticated;
public: public:
Authentication(User &user) : user(new User(user)), authenticated(true) Authentication(User &user) : user(new User(user)), authenticated(true) {}
{ Authentication() : user(nullptr), authenticated(false) {}
} ~Authentication() { delete (user); }
Authentication() : user(nullptr), authenticated(false)
{
}
~Authentication()
{
delete (user);
}
}; };
typedef std::function<boolean(Authentication &authentication)> AuthenticationPredicate; typedef std::function<boolean(Authentication &authentication)> AuthenticationPredicate;
class AuthenticationPredicates class AuthenticationPredicates {
{ public:
public: static bool NONE_REQUIRED(Authentication &authentication) { return true; };
static bool NONE_REQUIRED(Authentication &authentication) static bool IS_AUTHENTICATED(Authentication &authentication) { return authentication.authenticated; };
{ static bool IS_ADMIN(Authentication &authentication) {
return true;
};
static bool IS_AUTHENTICATED(Authentication &authentication)
{
return authentication.authenticated;
};
static bool IS_ADMIN(Authentication &authentication)
{
return authentication.authenticated && authentication.user->admin; return authentication.authenticated && authentication.user->admin;
}; };
}; };
class SecurityManager class SecurityManager {
{ public:
public:
#if FT_ENABLED(FT_SECURITY) #if FT_ENABLED(FT_SECURITY)
/* /*
* Authenticate, returning the user if found * Authenticate, returning the user if found
@@ -108,12 +88,14 @@ public:
/** /**
* Wrap the provided request to provide validation against an AuthenticationPredicate. * Wrap the provided request to provide validation against an AuthenticationPredicate.
*/ */
virtual PsychicHttpRequestCallback wrapRequest(PsychicHttpRequestCallback onRequest, AuthenticationPredicate predicate) = 0; virtual PsychicHttpRequestCallback wrapRequest(PsychicHttpRequestCallback onRequest,
AuthenticationPredicate predicate) = 0;
/** /**
* Wrap the provided json request callback to provide validation against an AuthenticationPredicate. * Wrap the provided json request callback to provide validation against an AuthenticationPredicate.
*/ */
virtual PsychicJsonRequestCallback wrapCallback(PsychicJsonRequestCallback onRequest, AuthenticationPredicate predicate) = 0; virtual PsychicJsonRequestCallback wrapCallback(PsychicJsonRequestCallback onRequest,
AuthenticationPredicate predicate) = 0;
}; };
#endif // end SecurityManager_h #endif // end SecurityManager_h