Commit 2a07047a authored by HFJ's avatar HFJ

add ProblemDetails

parent 97246fa7
......@@ -29,6 +29,7 @@
#include <map>
#include "ausf_config.hpp"
#include "curl.hpp"
#include "ProblemDetails.h"
using namespace config;
extern ausf_config ausf_cfg;
......@@ -82,8 +83,24 @@ void DefaultApiImpl::ue_authentications_auth_ctx_id5g_aka_confirmation_put(
const std::string &authCtxId, const ConfirmationData &confirmationData,
Pistache::Http::ResponseWriter &response) {
// seaf --> ausf
ProblemDetails problemDetails;
nlohmann::json problemDetails_json = {};
Logger::ausf_server().debug("Handling 5g-aka-confirmation-put...");
if(SUPI_AUSF.empty()) //no ue-authentications request ever
{
problemDetails.setCause("SERVING_NETWORK_NOT_AUTHORIZED");
problemDetails.setStatus(403);
problemDetails.setDetail("Serving Network Not Authorized");
to_json(problemDetails_json,problemDetails);
Logger::ausf_server().error("Serving Network Not Authorized");
Logger::ausf_server().info("Send 403 Forbidden response to AUSF");
response.send(Pistache::Http::Code::Forbidden, problemDetails_json.dump());
return;
}
/*---------------------getting params---------------------------------*/
Logger::ausf_server().info("Received authCtxId %s", authCtxId.c_str()); // authCtxId
Logger::ausf_server().info("Received res* %s", confirmationData.getResStar().c_str()); // res*(const char*) "0ddc2f64bd8dc35906fad44499e18525"
......@@ -163,7 +180,7 @@ void DefaultApiImpl::ue_authentications_auth_ctx_id5g_aka_confirmation_put(
time(&rawtime);
char buf[32];
strftime(buf, sizeof(buf), "%FT%TZ", gmtime(&rawtime));
confirmResultInfo["timeStamp"] = buf; //PARAM
confirmResultInfo["timeStamp"] = buf; //timestamp generated
// confirmResultInfo["timeStamp"] = "2020-08-12T17:02:51.128672225+09:00"; //PARAM
confirmResultInfo["authType"] = AUTH_TYPE; //authType stored in ausf
......@@ -228,6 +245,11 @@ void DefaultApiImpl::ue_authentications_post(
Curl::curl_http_client(udmUri, Method, AuthInfo.dump() , Response);
Logger::ausf_server().error("response: %s",Response.c_str());
ProblemDetails problemDetails;
nlohmann::json problemDetails_json = {};
nlohmann::json response_data = {};
try
{
......@@ -236,9 +258,18 @@ void DefaultApiImpl::ue_authentications_post(
catch (nlohmann::json::exception &e)
{
Logger::ausf_server().info("Could not get Json content from UDM response");
//TODO: error handling
problemDetails.setCause("CONTEXT_NOT_FOUND");
problemDetails.setStatus(404);
problemDetails.setDetail("Resource corresponding to User " + supi + " not found in UDM");
to_json(problemDetails_json,problemDetails);
Logger::ausf_server().error("Resource corresponding to User " + supi + " not found in UDM");
Logger::ausf_server().info("Send 404 Not_Found response to AUSF");
response.send(Pistache::Http::Code::Not_Found, problemDetails_json.dump());
return;
}
cout << response_data.dump() << endl;
std::string authType_udm = response_data.at("authType"); //AuthType
Logger::ausf_server().debug("authType %s",authType_udm.c_str());
......@@ -304,9 +335,6 @@ void DefaultApiImpl::ue_authentications_post(
AUTH_TYPE = authType_udm; //store authType in ausf
KAUSF_TMP = conv::uint8_to_hex_string(kausf_ausf,32); //store kausf_tmp in ausf
/*----------------ausf --> seaf-----------*/
//---form UEAuthenticationCtx
UEAuthenticationCtx UEAuthCtx;
......@@ -344,10 +372,6 @@ void DefaultApiImpl::ue_authentications_post(
ausf_5gAuthData.setHxresStar(hxresStar_s);
UEAuthCtx.setR5gAuthData(ausf_5gAuthData);
Logger::ausf_server().debug("autn_udm %s",autn_udm.c_str());
Logger::ausf_server().debug("autn_ausf %s",conv::uint8_to_hex_string(autn_ausf,16).c_str());
Logger::ausf_server().debug("autn_stored %s",autn_s.c_str());
nlohmann::json UEAuthCtx_json;
to_json(UEAuthCtx_json,UEAuthCtx);
Logger::ausf_server().debug("auth response:\n %s",UEAuthCtx_json.dump().c_str());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment