From 3cfac6cf160a44d9abde5b88abaada2aab7ca9b4 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Mon, 7 Nov 2022 15:32:20 -0800 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-10918 Signed-off-by: stephb9959 --- src/RESTObjects/RESTAPI_SecurityObjects.cpp | 75 +++++++++++++++++++++ src/RESTObjects/RESTAPI_SecurityObjects.h | 39 +++++++++++ 2 files changed, 114 insertions(+) diff --git a/src/RESTObjects/RESTAPI_SecurityObjects.cpp b/src/RESTObjects/RESTAPI_SecurityObjects.cpp index 9b84be3..c02df59 100644 --- a/src/RESTObjects/RESTAPI_SecurityObjects.cpp +++ b/src/RESTObjects/RESTAPI_SecurityObjects.cpp @@ -619,5 +619,80 @@ namespace OpenWifi::SecurityObjects { field_to_json(Obj,"login",login); field_to_json(Obj,"logout",logout); } + + void ApiKeyAccessRight::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "service", service); + field_to_json(Obj, "access", access); + } + + bool ApiKeyAccessRight::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "service", service); + field_from_json(Obj, "access", access); + return true; + } catch(...) { + std::cout << "Cannot parse: Token" << std::endl; + } + return false; + } + + void ApiKeyAccessRightList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "acls", acls); + } + + bool ApiKeyAccessRightList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "acls", acls); + return true; + } catch(...) { + std::cout << "Cannot parse: Token" << std::endl; + } + return false; + } + + void ApiKeyEntry::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "id", id); + field_to_json(Obj, "userUuid", userUuid); + field_to_json(Obj, "name", name); + field_to_json(Obj, "apiKey", apiKey); + field_to_json(Obj, "salt", salt); + field_to_json(Obj, "description", description); + field_to_json(Obj, "expiresOn", expiresOn); + field_to_json(Obj, "rights", rights); + field_to_json(Obj, "lastUse", lastUse); + } + + bool ApiKeyEntry::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "id", id); + field_from_json(Obj, "userUuid", userUuid); + field_from_json(Obj, "name", name); + field_from_json(Obj, "apiKey", apiKey); + field_from_json(Obj, "salt", salt); + field_from_json(Obj, "description", description); + field_from_json(Obj, "expiresOn", expiresOn); + field_from_json(Obj, "rights", rights); + field_from_json(Obj, "lastUse", lastUse); + return true; + } catch(...) { + std::cout << "Cannot parse: Token" << std::endl; + } + return false; + } + + void ApiKeyEntryList::to_json(Poco::JSON::Object &Obj) const { + field_to_json(Obj, "apiKeys", apiKeys); + } + + bool ApiKeyEntryList::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json(Obj, "apiKeys", apiKeys); + return true; + } catch(...) { + std::cout << "Cannot parse: Token" << std::endl; + } + return false; + } + } diff --git a/src/RESTObjects/RESTAPI_SecurityObjects.h b/src/RESTObjects/RESTAPI_SecurityObjects.h index 3cee8cc..a804128 100644 --- a/src/RESTObjects/RESTAPI_SecurityObjects.h +++ b/src/RESTObjects/RESTAPI_SecurityObjects.h @@ -325,5 +325,44 @@ namespace OpenWifi { void to_json(Poco::JSON::Object &Obj) const; }; + + struct ApiKeyAccessRight { + std::string service; + std::string access; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct ApiKeyAccessRightList { + std::vector acls; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct ApiKeyEntry { + Types::UUID_t id; + Types::UUID_t userUuid; + std::string name; + std::string description; + std::string apiKey; + std::string salt; + std::uint64_t created; + std::uint64_t expiresOn=0; + ApiKeyAccessRightList rights; + std::uint64_t lastUse=0; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + struct ApiKeyEntryList { + std::vector apiKeys; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + } }