Fixing submfa method

This commit is contained in:
stephb9959
2021-12-10 13:01:07 -08:00
parent f51e00c50c
commit fb2ddaa136
21 changed files with 108 additions and 80 deletions

View File

@@ -102,7 +102,7 @@ add_executable( owsec
src/RESTAPI/RESTAPI_subuser_handler.h src/RESTAPI/RESTAPI_subuser_handler.cpp src/RESTAPI/RESTAPI_subuser_handler.h src/RESTAPI/RESTAPI_subuser_handler.cpp
src/RESTAPI/RESTAPI_subusers_handler.h src/RESTAPI/RESTAPI_subusers_handler.cpp src/RESTAPI/RESTAPI_subusers_handler.h src/RESTAPI/RESTAPI_subusers_handler.cpp
src/RESTAPI/RESTAPI_validate_sub_token_handler.cpp src/RESTAPI/RESTAPI_validate_sub_token_handler.h src/RESTAPI/RESTAPI_validate_sub_token_handler.cpp src/RESTAPI/RESTAPI_validate_sub_token_handler.h
src/APIServers.cpp src/RESTAPI/RESTAPI_Routers.cpp
src/Daemon.h src/Daemon.cpp src/Daemon.h src/Daemon.cpp
src/AuthService.h src/AuthService.cpp src/AuthService.h src/AuthService.cpp
src/StorageService.cpp src/StorageService.h src/StorageService.cpp src/StorageService.h

2
build
View File

@@ -1 +1 @@
102 108

View File

@@ -23,8 +23,8 @@
namespace OpenWifi { namespace OpenWifi {
Poco::Net::HTTPRequestHandler * RESTAPI_external_server(const char *Path, RESTAPIHandler::BindingMap &Bindings, Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings,
Poco::Logger & L, RESTAPI_GenericServer & S) { Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
return RESTAPI_Router< return RESTAPI_Router<
RESTAPI_oauth2_handler, RESTAPI_oauth2_handler,
RESTAPI_users_handler, RESTAPI_users_handler,
@@ -41,11 +41,11 @@ namespace OpenWifi {
RESTAPI_subuser_handler, RESTAPI_subuser_handler,
RESTAPI_subusers_handler, RESTAPI_subusers_handler,
RESTAPI_submfa_handler RESTAPI_submfa_handler
>(Path, Bindings, L, S); >(Path, Bindings, L, S,TransactionId);
} }
Poco::Net::HTTPRequestHandler * RESTAPI_internal_server(const char *Path, RESTAPIHandler::BindingMap &Bindings, Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings,
Poco::Logger & L, RESTAPI_GenericServer & S) { Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) {
return RESTAPI_Router_I< return RESTAPI_Router_I<
RESTAPI_users_handler, RESTAPI_users_handler,
RESTAPI_user_handler, RESTAPI_user_handler,
@@ -59,6 +59,6 @@ namespace OpenWifi {
RESTAPI_suboauth2_handler, RESTAPI_suboauth2_handler,
RESTAPI_subusers_handler, RESTAPI_subusers_handler,
RESTAPI_submfa_handler RESTAPI_submfa_handler
>(Path, Bindings, L, S); >(Path, Bindings, L, S, TransactionId);
} }
} }

View File

@@ -9,13 +9,14 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_action_links : public RESTAPIHandler { class RESTAPI_action_links : public RESTAPIHandler {
public: public:
RESTAPI_action_links(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_action_links(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{ std::vector<std::string>{
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_POST,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal, Internal,
false, false,
true, RateLimit{.Interval=1000,.MaxCalls=10}) {} true, RateLimit{.Interval=1000,.MaxCalls=10}) {}

View File

@@ -9,7 +9,7 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_asset_server : public RESTAPIHandler { class RESTAPI_asset_server : public RESTAPIHandler {
public: public:
RESTAPI_asset_server(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_asset_server(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string> std::vector<std::string>
{Poco::Net::HTTPRequest::HTTP_POST, {Poco::Net::HTTPRequest::HTTP_POST,
@@ -18,6 +18,7 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_DELETE,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal, false) {} Internal, false) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/wwwassets/{id}" , static const std::list<const char *> PathName() { return std::list<const char *>{"/wwwassets/{id}" ,
"/favicon.ico"}; }; "/favicon.ico"}; };

View File

@@ -30,7 +30,7 @@ namespace OpenWifi {
class RESTAPI_avatar_handler : public RESTAPIHandler { class RESTAPI_avatar_handler : public RESTAPIHandler {
public: public:
RESTAPI_avatar_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_avatar_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{ std::vector<std::string>{
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_GET,
@@ -38,6 +38,7 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_DELETE,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/avatar/{id}"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/avatar/{id}"}; };

View File

@@ -9,11 +9,12 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_email_handler : public RESTAPIHandler { class RESTAPI_email_handler : public RESTAPIHandler {
public: public:
RESTAPI_email_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_email_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/email"};} static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/email"};}
void DoGet() final {}; void DoGet() final {};

View File

@@ -12,13 +12,14 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_oauth2_handler : public RESTAPIHandler { class RESTAPI_oauth2_handler : public RESTAPIHandler {
public: public:
RESTAPI_oauth2_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_oauth2_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST,
Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_DELETE,
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal, false, true , RateLimit{.Interval=1000,.MaxCalls=10}) {} Internal, false, true , RateLimit{.Interval=1000,.MaxCalls=10}) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/oauth2/{token}","/api/v1/oauth2"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/oauth2/{token}","/api/v1/oauth2"}; };
void DoGet() final; void DoGet() final;

View File

@@ -9,13 +9,14 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_preferences : public RESTAPIHandler { class RESTAPI_preferences : public RESTAPIHandler {
public: public:
RESTAPI_preferences(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_preferences(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{ std::vector<std::string>{
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_PUT,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/preferences"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/preferences"}; };
void DoGet() final; void DoGet() final;

View File

@@ -9,11 +9,12 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_sms_handler : public RESTAPIHandler { class RESTAPI_sms_handler : public RESTAPIHandler {
public: public:
RESTAPI_sms_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_sms_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/sms"};} static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/sms"};}
void DoGet() final {}; void DoGet() final {};

View File

@@ -94,10 +94,17 @@ namespace OpenWifi {
PhoneNumber.verified = true; PhoneNumber.verified = true;
User.userTypeProprietaryInfo.mobiles.clear(); User.userTypeProprietaryInfo.mobiles.clear();
User.userTypeProprietaryInfo.mobiles.push_back(PhoneNumber); User.userTypeProprietaryInfo.mobiles.push_back(PhoneNumber);
StorageService()->UpdateSubUserInfo(UserInfo_.userinfo.email, UserInfo_.userinfo.Id, User); StorageService()->UpdateSubUserInfo(UserInfo_.userinfo.email, UserInfo_.userinfo.Id, User);
MFC.sms = MFC.sms;
MFC.type = "sms";
MFC.email = UserInfo_.userinfo.email;
MFC.id = MicroService::instance().CreateUUID();
Poco::JSON::Object Answer; Poco::JSON::Object Answer;
MFC.to_json(Answer); MFC.to_json(Answer);
return ReturnObject(Answer); return ReturnObject(Answer);
} else { } else {

View File

@@ -9,12 +9,13 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_submfa_handler : public RESTAPIHandler { class RESTAPI_submfa_handler : public RESTAPIHandler {
public: public:
RESTAPI_submfa_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_submfa_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_PUT, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_PUT,
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal, true, false , RateLimit{.Interval=1000,.MaxCalls=10}, Internal, true, false , RateLimit{.Interval=1000,.MaxCalls=10},
true) {} true) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/submfa"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/submfa"}; };

View File

@@ -8,13 +8,14 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_suboauth2_handler : public RESTAPIHandler { class RESTAPI_suboauth2_handler : public RESTAPIHandler {
public: public:
RESTAPI_suboauth2_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_suboauth2_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST,
Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_DELETE,
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal, false, false , RateLimit{.Interval=1000,.MaxCalls=10}, Internal, false, false , RateLimit{.Interval=1000,.MaxCalls=10},
false) {} false) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/suboauth2/{token}","/api/v1/suboauth2"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/suboauth2/{token}","/api/v1/suboauth2"}; };

View File

@@ -9,7 +9,7 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_subuser_handler : public RESTAPIHandler { class RESTAPI_subuser_handler : public RESTAPIHandler {
public: public:
RESTAPI_subuser_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_subuser_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string> std::vector<std::string>
{Poco::Net::HTTPRequest::HTTP_POST, {Poco::Net::HTTPRequest::HTTP_POST,
@@ -18,6 +18,7 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_DELETE,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/subuser/{id}"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/subuser/{id}"}; };
void DoGet() final; void DoGet() final;

View File

@@ -9,12 +9,13 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_subusers_handler : public RESTAPIHandler { class RESTAPI_subusers_handler : public RESTAPIHandler {
public: public:
RESTAPI_subusers_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_subusers_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string> std::vector<std::string>
{Poco::Net::HTTPRequest::HTTP_GET, {Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/subusers"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/subusers"}; };
void DoGet() final; void DoGet() final;

View File

@@ -9,11 +9,12 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_system_endpoints_handler : public RESTAPIHandler { class RESTAPI_system_endpoints_handler : public RESTAPIHandler {
public: public:
RESTAPI_system_endpoints_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_system_endpoints_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/systemEndpoints"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/systemEndpoints"}; };
void DoGet() final; void DoGet() final;

View File

@@ -9,7 +9,7 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_user_handler : public RESTAPIHandler { class RESTAPI_user_handler : public RESTAPIHandler {
public: public:
RESTAPI_user_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_user_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string> std::vector<std::string>
{Poco::Net::HTTPRequest::HTTP_POST, {Poco::Net::HTTPRequest::HTTP_POST,
@@ -18,6 +18,7 @@ namespace OpenWifi {
Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_DELETE,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/user/{id}"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/user/{id}"}; };
void DoGet() final; void DoGet() final;

View File

@@ -9,12 +9,13 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_users_handler : public RESTAPIHandler { class RESTAPI_users_handler : public RESTAPIHandler {
public: public:
RESTAPI_users_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_users_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string> std::vector<std::string>
{Poco::Net::HTTPRequest::HTTP_GET, {Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/users"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/users"}; };
void DoGet() final; void DoGet() final;

View File

@@ -9,12 +9,13 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_validate_sub_token_handler : public RESTAPIHandler { class RESTAPI_validate_sub_token_handler : public RESTAPIHandler {
public: public:
RESTAPI_validate_sub_token_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_validate_sub_token_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string> std::vector<std::string>
{Poco::Net::HTTPRequest::HTTP_GET, {Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {}; Internal) {};
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/validateSubToken"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/validateSubToken"}; };
void DoGet() final; void DoGet() final;

View File

@@ -9,12 +9,13 @@
namespace OpenWifi { namespace OpenWifi {
class RESTAPI_validate_token_handler : public RESTAPIHandler { class RESTAPI_validate_token_handler : public RESTAPIHandler {
public: public:
RESTAPI_validate_token_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) RESTAPI_validate_token_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string> std::vector<std::string>
{Poco::Net::HTTPRequest::HTTP_GET, {Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {}; Internal) {};
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/validateToken"}; }; static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/validateToken"}; };
void DoGet() final; void DoGet() final;

View File

@@ -74,8 +74,6 @@ using namespace std::chrono_literals;
#include "ow_version.h" #include "ow_version.h"
#define _OWDBG_ std::cout << __FILE__ << " : " << __LINE__ << std::endl;
namespace OpenWifi { namespace OpenWifi {
enum UNAUTHORIZED_REASON { enum UNAUTHORIZED_REASON {
@@ -97,7 +95,7 @@ namespace OpenWifi {
inline AppServiceRegistry(); inline AppServiceRegistry();
static AppServiceRegistry & instance() { static AppServiceRegistry & instance() {
static AppServiceRegistry *instance_= new AppServiceRegistry; static auto *instance_= new AppServiceRegistry;
return *instance_; return *instance_;
} }
@@ -1524,6 +1522,7 @@ namespace OpenWifi {
Poco::Logger &l, Poco::Logger &l,
std::vector<std::string> Methods, std::vector<std::string> Methods,
RESTAPI_GenericServer & Server, RESTAPI_GenericServer & Server,
uint64_t TransactionId,
bool Internal=false, bool Internal=false,
bool AlwaysAuthorize=true, bool AlwaysAuthorize=true,
bool RateLimited=false, bool RateLimited=false,
@@ -1533,11 +1532,13 @@ namespace OpenWifi {
Logger_(l), Logger_(l),
Methods_(std::move(Methods)), Methods_(std::move(Methods)),
Server_(Server), Server_(Server),
TransactionId_(TransactionId),
Internal_(Internal), Internal_(Internal),
AlwaysAuthorize_(AlwaysAuthorize), AlwaysAuthorize_(AlwaysAuthorize),
RateLimited_(RateLimited), RateLimited_(RateLimited),
MyRates_(Profile), MyRates_(Profile),
SubOnlyService_(SubscriberOnly){ SubOnlyService_(SubscriberOnly)
{
} }
inline bool RoleIsAuthorized(const std::string & Path, const std::string & Method, std::string & Reason) { inline bool RoleIsAuthorized(const std::string & Path, const std::string & Method, std::string & Reason) {
@@ -1994,12 +1995,13 @@ namespace OpenWifi {
Poco::JSON::Parser IncomingParser_; Poco::JSON::Parser IncomingParser_;
RESTAPI_GenericServer & Server_; RESTAPI_GenericServer & Server_;
RateLimit MyRates_; RateLimit MyRates_;
uint64_t TransactionId_;
}; };
class RESTAPI_UnknownRequestHandler : public RESTAPIHandler { class RESTAPI_UnknownRequestHandler : public RESTAPIHandler {
public: public:
RESTAPI_UnknownRequestHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server) RESTAPI_UnknownRequestHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId)
: RESTAPIHandler(bindings, L, std::vector<std::string>{}, Server) {} : RESTAPIHandler(bindings, L, std::vector<std::string>{}, Server, TransactionId) {}
inline void DoGet() override {}; inline void DoGet() override {};
inline void DoPost() override {}; inline void DoPost() override {};
inline void DoPut() override {}; inline void DoPut() override {};
@@ -2018,30 +2020,30 @@ namespace OpenWifi {
} }
template<typename T, typename... Args> template<typename T, typename... Args>
RESTAPIHandler * RESTAPI_Router(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server) { RESTAPIHandler * RESTAPI_Router(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server, uint64_t TransactionId) {
static_assert(test_has_PathName_method((T*)nullptr), "Class must have a static PathName() method."); static_assert(test_has_PathName_method((T*)nullptr), "Class must have a static PathName() method.");
if(RESTAPIHandler::ParseBindings(RequestedPath,T::PathName(),Bindings)) { if(RESTAPIHandler::ParseBindings(RequestedPath,T::PathName(),Bindings)) {
return new T(Bindings, Logger, Server, false); return new T(Bindings, Logger, Server, false, TransactionId);
} }
if constexpr (sizeof...(Args) == 0) { if constexpr (sizeof...(Args) == 0) {
return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server); return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server, TransactionId);
} else { } else {
return RESTAPI_Router<Args...>(RequestedPath, Bindings, Logger, Server); return RESTAPI_Router<Args...>(RequestedPath, Bindings, Logger, Server, TransactionId);
} }
} }
template<typename T, typename... Args> template<typename T, typename... Args>
RESTAPIHandler * RESTAPI_Router_I(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server) { RESTAPIHandler * RESTAPI_Router_I(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server, uint64_t TransactionId) {
static_assert(test_has_PathName_method((T*)nullptr), "Class must have a static PathName() method."); static_assert(test_has_PathName_method((T*)nullptr), "Class must have a static PathName() method.");
if(RESTAPIHandler::ParseBindings(RequestedPath,T::PathName(),Bindings)) { if(RESTAPIHandler::ParseBindings(RequestedPath,T::PathName(),Bindings)) {
return new T(Bindings, Logger, Server, true); return new T(Bindings, Logger, Server, true, TransactionId);
} }
if constexpr (sizeof...(Args) == 0) { if constexpr (sizeof...(Args) == 0) {
return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server); return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server, TransactionId);
} else { } else {
return RESTAPI_Router_I<Args...>(RequestedPath, Bindings, Logger, Server); return RESTAPI_Router_I<Args...>(RequestedPath, Bindings, Logger, Server, TransactionId);
} }
} }
@@ -2412,17 +2414,17 @@ namespace OpenWifi {
inline ALBHealthCheckServer * ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); } inline ALBHealthCheckServer * ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); }
Poco::Net::HTTPRequestHandler * RESTAPI_external_server(const char *Path, RESTAPIHandler::BindingMap &Bindings, Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings,
Poco::Logger & L, RESTAPI_GenericServer & S); Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t Id);
Poco::Net::HTTPRequestHandler * RESTAPI_internal_server(const char *Path, RESTAPIHandler::BindingMap &Bindings, Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings,
Poco::Logger & L, RESTAPI_GenericServer & S); Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t Id);
class RESTAPI_server : public SubSystemServer { class RESTAPI_ExtServer : public SubSystemServer {
public: public:
static RESTAPI_server *instance() { static RESTAPI_ExtServer *instance() {
static RESTAPI_server *instance_ = new RESTAPI_server; static RESTAPI_ExtServer *instance_ = new RESTAPI_ExtServer;
return instance_; return instance_;
} }
int Start() override; int Start() override;
@@ -2436,9 +2438,9 @@ namespace OpenWifi {
inline void reinitialize(Poco::Util::Application &self) override; inline void reinitialize(Poco::Util::Application &self) override;
inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path) { inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path, uint64_t Id) {
RESTAPIHandler::BindingMap Bindings; RESTAPIHandler::BindingMap Bindings;
return RESTAPI_external_server(Path, Bindings, Logger_, Server_); return RESTAPI_ExtRouter(Path, Bindings, Logger_, Server_, Id);
} }
private: private:
@@ -2446,18 +2448,18 @@ namespace OpenWifi {
Poco::ThreadPool Pool_; Poco::ThreadPool Pool_;
RESTAPI_GenericServer Server_; RESTAPI_GenericServer Server_;
RESTAPI_server() noexcept: RESTAPI_ExtServer() noexcept:
SubSystemServer("RESTAPIServer", "RESTAPIServer", "openwifi.restapi") SubSystemServer("RESTAPI_ExtServer", "RESTAPIServer", "openwifi.restapi")
{ {
} }
}; };
inline RESTAPI_server * RESTAPI_server() { return RESTAPI_server::instance(); }; inline RESTAPI_ExtServer * RESTAPI_ExtServer() { return RESTAPI_ExtServer::instance(); };
class RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory { class ExtRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
public: public:
RequestHandlerFactory(RESTAPI_GenericServer & Server) : explicit ExtRequestHandlerFactory(RESTAPI_GenericServer & Server) :
Logger_(RESTAPI_server::instance()->Logger()), Logger_(RESTAPI_ExtServer::instance()->Logger()),
Server_(Server) Server_(Server)
{ {
@@ -2466,15 +2468,16 @@ namespace OpenWifi {
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
Poco::URI uri(Request.getURI()); Poco::URI uri(Request.getURI());
auto *Path = uri.getPath().c_str(); auto *Path = uri.getPath().c_str();
return RESTAPI_server()->CallServer(Path); return RESTAPI_ExtServer()->CallServer(Path, TransactionId_++);
} }
private: private:
Poco::Logger &Logger_; static inline std::atomic_uint64_t TransactionId_ = 1;
RESTAPI_GenericServer &Server_; Poco::Logger &Logger_;
RESTAPI_GenericServer &Server_;
}; };
inline int RESTAPI_server::Start() { inline int RESTAPI_ExtServer::Start() {
Logger_.information("Starting."); Logger_.information("Starting.");
Server_.InitLogging(); Server_.InitLogging();
@@ -2493,7 +2496,7 @@ namespace OpenWifi {
Params->setMaxQueued(200); Params->setMaxQueued(200);
Params->setKeepAlive(true); Params->setKeepAlive(true);
auto NewServer = std::make_unique<Poco::Net::HTTPServer>(new RequestHandlerFactory(Server_), Pool_, Sock, Params); auto NewServer = std::make_unique<Poco::Net::HTTPServer>(new ExtRequestHandlerFactory(Server_), Pool_, Sock, Params);
NewServer->start(); NewServer->start();
RESTServers_.push_back(std::move(NewServer)); RESTServers_.push_back(std::move(NewServer));
} }
@@ -2501,11 +2504,11 @@ namespace OpenWifi {
return 0; return 0;
} }
class RESTAPI_InternalServer : public SubSystemServer { class RESTAPI_IntServer : public SubSystemServer {
public: public:
static RESTAPI_InternalServer *instance() { static RESTAPI_IntServer *instance() {
static RESTAPI_InternalServer *instance_ = new RESTAPI_InternalServer; static RESTAPI_IntServer *instance_ = new RESTAPI_IntServer;
return instance_; return instance_;
} }
@@ -2519,39 +2522,40 @@ namespace OpenWifi {
inline void reinitialize(Poco::Util::Application &self) override; inline void reinitialize(Poco::Util::Application &self) override;
inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path) { inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path, uint64_t Id) {
RESTAPIHandler::BindingMap Bindings; RESTAPIHandler::BindingMap Bindings;
return RESTAPI_internal_server(Path, Bindings, Logger_, Server_); return RESTAPI_IntRouter(Path, Bindings, Logger_, Server_, Id);
} }
private: private:
std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_; std::vector<std::unique_ptr<Poco::Net::HTTPServer>> RESTServers_;
Poco::ThreadPool Pool_; Poco::ThreadPool Pool_;
RESTAPI_GenericServer Server_; RESTAPI_GenericServer Server_;
RESTAPI_InternalServer() noexcept: SubSystemServer("RESTAPIInternalServer", "REST-ISRV", "openwifi.internal.restapi") RESTAPI_IntServer() noexcept: SubSystemServer("RESTAPI_IntServer", "REST-ISRV", "openwifi.internal.restapi")
{ {
} }
}; };
inline RESTAPI_InternalServer * RESTAPI_InternalServer() { return RESTAPI_InternalServer::instance(); }; inline RESTAPI_IntServer * RESTAPI_IntServer() { return RESTAPI_IntServer::instance(); };
class InternalRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory { class IntRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory {
public: public:
InternalRequestHandlerFactory(RESTAPI_GenericServer & Server) : explicit IntRequestHandlerFactory(RESTAPI_GenericServer & Server) :
Logger_(RESTAPI_InternalServer()->Logger()), Logger_(RESTAPI_IntServer()->Logger()),
Server_(Server){} Server_(Server){}
inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override {
Poco::URI uri(Request.getURI()); Poco::URI uri(Request.getURI());
auto *Path = uri.getPath().c_str(); auto *Path = uri.getPath().c_str();
return RESTAPI_InternalServer()->CallServer(Path); return RESTAPI_IntServer()->CallServer(Path, TransactionId_);
} }
private: private:
Poco::Logger & Logger_; static inline std::atomic_uint64_t TransactionId_ = 1;
RESTAPI_GenericServer & Server_; Poco::Logger &Logger_;
RESTAPI_GenericServer &Server_;
}; };
inline int RESTAPI_InternalServer::Start() { inline int RESTAPI_IntServer::Start() {
Logger_.information("Starting."); Logger_.information("Starting.");
Server_.InitLogging(); Server_.InitLogging();
@@ -2569,7 +2573,7 @@ namespace OpenWifi {
Params->setMaxQueued(200); Params->setMaxQueued(200);
Params->setKeepAlive(true); Params->setKeepAlive(true);
auto NewServer = std::make_unique<Poco::Net::HTTPServer>(new InternalRequestHandlerFactory(Server_), Pool_, Sock, Params); auto NewServer = std::make_unique<Poco::Net::HTTPServer>(new IntRequestHandlerFactory(Server_), Pool_, Sock, Params);
NewServer->start(); NewServer->start();
RESTServers_.push_back(std::move(NewServer)); RESTServers_.push_back(std::move(NewServer));
} }
@@ -2850,8 +2854,8 @@ namespace OpenWifi {
// add the default services // add the default services
SubSystems_.push_back(KafkaManager()); SubSystems_.push_back(KafkaManager());
SubSystems_.push_back(ALBHealthCheckServer()); SubSystems_.push_back(ALBHealthCheckServer());
SubSystems_.push_back(RESTAPI_server()); SubSystems_.push_back(RESTAPI_ExtServer());
SubSystems_.push_back(RESTAPI_InternalServer()); SubSystems_.push_back(RESTAPI_IntServer());
Poco::Net::initializeSSL(); Poco::Net::initializeSSL();
Poco::Net::HTTPStreamFactory::registerFactory(); Poco::Net::HTTPStreamFactory::registerFactory();
@@ -3421,14 +3425,14 @@ namespace OpenWifi {
Consumer.unsubscribe(); Consumer.unsubscribe();
} }
inline void RESTAPI_server::reinitialize(Poco::Util::Application &self) { inline void RESTAPI_ExtServer::reinitialize(Poco::Util::Application &self) {
MicroService::instance().LoadConfigurationFile(); MicroService::instance().LoadConfigurationFile();
Logger_.information("Reinitializing."); Logger_.information("Reinitializing.");
Stop(); Stop();
Start(); Start();
} }
void RESTAPI_InternalServer::reinitialize(Poco::Util::Application &self) { void RESTAPI_IntServer::reinitialize(Poco::Util::Application &self) {
MicroService::instance().LoadConfigurationFile(); MicroService::instance().LoadConfigurationFile();
Logger_.information("Reinitializing."); Logger_.information("Reinitializing.");
Stop(); Stop();
@@ -3437,12 +3441,13 @@ namespace OpenWifi {
class RESTAPI_system_command : public RESTAPIHandler { class RESTAPI_system_command : public RESTAPIHandler {
public: public:
RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal)
: RESTAPIHandler(bindings, L, : RESTAPIHandler(bindings, L,
std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST, std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST,
Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_GET,
Poco::Net::HTTPRequest::HTTP_OPTIONS}, Poco::Net::HTTPRequest::HTTP_OPTIONS},
Server, Server,
TransactionId,
Internal) {} Internal) {}
static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/system"};} static const std::list<const char *> PathName() { return std::list<const char *>{"/api/v1/system"};}
@@ -3752,7 +3757,7 @@ namespace OpenWifi {
if (AuthClient()->IsAuthorized( SessionToken_, UserInfo_, Expired, Sub)) { if (AuthClient()->IsAuthorized( SessionToken_, UserInfo_, Expired, Sub)) {
#endif #endif
if(Server_.LogIt(Request->getMethod(),true)) { if(Server_.LogIt(Request->getMethod(),true)) {
Logger_.debug(Poco::format("X-REQ-ALLOWED(%s): User='%s@%s' Method='%s' Path='%s", Logger_.debug(Poco::format("X-REQ-ALLOWED(%s): User='%s@%s' Method='%s' Path='%s'",
UserInfo_.userinfo.email, UserInfo_.userinfo.email,
Utils::FormatIPv6(Request->clientAddress().toString()), Utils::FormatIPv6(Request->clientAddress().toString()),
Request->clientAddress().toString(), Request->clientAddress().toString(),
@@ -3762,7 +3767,7 @@ namespace OpenWifi {
return true; return true;
} else { } else {
if(Server_.LogBadTokens(true)) { if(Server_.LogBadTokens(true)) {
Logger_.debug(Poco::format("X-REQ-DENIED(%s): Method='%s' Path='%s", Logger_.debug(Poco::format("X-REQ-DENIED(%s): Method='%s' Path='%s'",
Utils::FormatIPv6(Request->clientAddress().toString()), Utils::FormatIPv6(Request->clientAddress().toString()),
Request->getMethod(), Request->getURI())); Request->getMethod(), Request->getURI()));
} }