mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-11-02 19:57:46 +00:00
Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
@@ -10,30 +10,21 @@ namespace OpenWifi {
|
|||||||
void RESTAPI_validate_apikey::DoGet() {
|
void RESTAPI_validate_apikey::DoGet() {
|
||||||
Poco::URI URI(Request->getURI());
|
Poco::URI URI(Request->getURI());
|
||||||
auto Parameters = URI.getQueryParameters();
|
auto Parameters = URI.getQueryParameters();
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
for(auto const &i:Parameters) {
|
for(auto const &i:Parameters) {
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
if (i.first == "apikey") {
|
if (i.first == "apikey") {
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
// can we find this token?
|
// can we find this token?
|
||||||
SecurityObjects::UserInfoAndPolicy SecObj;
|
SecurityObjects::UserInfoAndPolicy SecObj;
|
||||||
bool Expired = false;
|
bool Expired = false;
|
||||||
std::uint64_t expiresOn=0;
|
std::uint64_t expiresOn=0;
|
||||||
std::cout << __LINE__ << " > " << i.second << std::endl;
|
|
||||||
if (AuthService()->IsValidApiKey(i.second, SecObj.webtoken, SecObj.userinfo, Expired, expiresOn)) {
|
if (AuthService()->IsValidApiKey(i.second, SecObj.webtoken, SecObj.userinfo, Expired, expiresOn)) {
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
Poco::JSON::Object Answer;
|
Poco::JSON::Object Answer;
|
||||||
SecObj.to_json(Answer);
|
SecObj.to_json(Answer);
|
||||||
Answer.set("expiresOn", expiresOn);
|
Answer.set("expiresOn", expiresOn);
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
return ReturnObject(Answer);
|
return ReturnObject(Answer);
|
||||||
}
|
}
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
|
return UnAuthorized(RESTAPI::Errors::ACCESS_DENIED);
|
||||||
}
|
}
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
}
|
}
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,7 @@ namespace OpenWifi {
|
|||||||
10000);
|
10000);
|
||||||
Poco::JSON::Object::Ptr Response;
|
Poco::JSON::Object::Ptr Response;
|
||||||
|
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
auto StatusCode = Req.Do(Response);
|
auto StatusCode = Req.Do(Response);
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
if(StatusCode==Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT) {
|
if(StatusCode==Poco::Net::HTTPServerResponse::HTTP_GATEWAY_TIMEOUT) {
|
||||||
Contacted = false;
|
Contacted = false;
|
||||||
return false;
|
return false;
|
||||||
@@ -91,25 +89,18 @@ namespace OpenWifi {
|
|||||||
|
|
||||||
Contacted = true;
|
Contacted = true;
|
||||||
if(StatusCode==Poco::Net::HTTPServerResponse::HTTP_OK) {
|
if(StatusCode==Poco::Net::HTTPServerResponse::HTTP_OK) {
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
if(Response->has("tokenInfo") && Response->has("userInfo") && Response->has("expiresOn")) {
|
if(Response->has("tokenInfo") && Response->has("userInfo") && Response->has("expiresOn")) {
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
UInfo.from_json(Response);
|
UInfo.from_json(Response);
|
||||||
Expired = false;
|
Expired = false;
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
ApiKeyCache_.update(SessionToken, ApiKeyCacheEntry{ .UserInfo = UInfo, .ExpiresOn = Response->get("expiresOn")});
|
ApiKeyCache_.update(SessionToken, ApiKeyCacheEntry{ .UserInfo = UInfo, .ExpiresOn = Response->get("expiresOn")});
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
poco_error(Logger(),fmt::format("Failed to retrieve api key={} for TID={}", SessionToken, TID));
|
poco_error(Logger(),fmt::format("Failed to retrieve api key={} for TID={}", SessionToken, TID));
|
||||||
}
|
}
|
||||||
std::cout << __LINE__ << std::endl;
|
|
||||||
Expired = false;
|
Expired = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -672,7 +672,6 @@ namespace OpenWifi {
|
|||||||
return Allowed;
|
return Allowed;
|
||||||
} else if(!Internal_ && Request->has("X-API-KEY")) {
|
} else if(!Internal_ && Request->has("X-API-KEY")) {
|
||||||
SessionToken_ = Request->get("X-API-KEY", "");
|
SessionToken_ = Request->get("X-API-KEY", "");
|
||||||
std::cout << "SessionToken: " << SessionToken_ << std::endl;
|
|
||||||
#ifdef TIP_SECURITY_SERVICE
|
#ifdef TIP_SECURITY_SERVICE
|
||||||
std::uint64_t expiresOn;
|
std::uint64_t expiresOn;
|
||||||
if (AuthService()->IsValidApiKey(SessionToken_, UserInfo_.webtoken, UserInfo_.userinfo, Expired, expiresOn)) {
|
if (AuthService()->IsValidApiKey(SessionToken_, UserInfo_.webtoken, UserInfo_.userinfo, Expired, expiresOn)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user