🪄 Formats SecurityManager
This commit is contained in:
@@ -28,60 +28,40 @@
|
||||
|
||||
#define MAX_JWT_SIZE 128
|
||||
|
||||
class User
|
||||
{
|
||||
public:
|
||||
class User {
|
||||
public:
|
||||
String username;
|
||||
String password;
|
||||
bool admin;
|
||||
|
||||
public:
|
||||
User(String username, String password, bool admin) : username(username), password(password), admin(admin)
|
||||
{
|
||||
}
|
||||
public:
|
||||
User(String username, String password, bool admin) : username(username), password(password), admin(admin) {}
|
||||
};
|
||||
|
||||
class Authentication
|
||||
{
|
||||
public:
|
||||
class Authentication {
|
||||
public:
|
||||
User *user;
|
||||
boolean authenticated;
|
||||
|
||||
public:
|
||||
Authentication(User &user) : user(new User(user)), authenticated(true)
|
||||
{
|
||||
}
|
||||
Authentication() : user(nullptr), authenticated(false)
|
||||
{
|
||||
}
|
||||
~Authentication()
|
||||
{
|
||||
delete (user);
|
||||
}
|
||||
public:
|
||||
Authentication(User &user) : user(new User(user)), authenticated(true) {}
|
||||
Authentication() : user(nullptr), authenticated(false) {}
|
||||
~Authentication() { delete (user); }
|
||||
};
|
||||
|
||||
typedef std::function<boolean(Authentication &authentication)> AuthenticationPredicate;
|
||||
|
||||
class AuthenticationPredicates
|
||||
{
|
||||
public:
|
||||
static bool NONE_REQUIRED(Authentication &authentication)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
static bool IS_AUTHENTICATED(Authentication &authentication)
|
||||
{
|
||||
return authentication.authenticated;
|
||||
};
|
||||
static bool IS_ADMIN(Authentication &authentication)
|
||||
{
|
||||
class AuthenticationPredicates {
|
||||
public:
|
||||
static bool NONE_REQUIRED(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;
|
||||
};
|
||||
};
|
||||
|
||||
class SecurityManager
|
||||
{
|
||||
public:
|
||||
class SecurityManager {
|
||||
public:
|
||||
#if FT_ENABLED(FT_SECURITY)
|
||||
/*
|
||||
* Authenticate, returning the user if found
|
||||
@@ -108,12 +88,14 @@ public:
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
virtual PsychicJsonRequestCallback wrapCallback(PsychicJsonRequestCallback onRequest, AuthenticationPredicate predicate) = 0;
|
||||
virtual PsychicJsonRequestCallback wrapCallback(PsychicJsonRequestCallback onRequest,
|
||||
AuthenticationPredicate predicate) = 0;
|
||||
};
|
||||
|
||||
#endif // end SecurityManager_h
|
||||
|
||||
Reference in New Issue
Block a user