From 7ae12a0e3b9fa4afc8814a7f653eda5243f61fa3 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Sun, 24 Dec 2023 11:45:29 +0000 Subject: [PATCH] Refactor: Move authorization return context logic --- ...and_mobility_subscription_data_document.go | 1 + ...i_amf3_gpp_access_registration_document.go | 3 +++ ...f_non3_gpp_access_registration_document.go | 3 +++ .../api_amf_subscription_info_document.go | 1 + .../api_authentication_data_document.go | 2 ++ .../api_authentication_so_r_document.go | 2 ++ .../api_authentication_status_document.go | 2 ++ internal/sbi/datarepository/api_default.go | 27 +++++++++++++++++++ ...pi_event_amf_subscription_info_document.go | 3 +++ ...al_influence_data_subscription_document.go | 3 +++ .../sbi/datarepository/api_influence_data.go | 1 + .../api_provisioned_data_document.go | 1 + ...pi_query_amf_subscription_info_document.go | 1 + .../api_sdm_subscription_document.go | 2 ++ .../api_sdm_subscriptions_collection.go | 2 ++ ...pi_session_management_subscription_data.go | 1 + .../api_smf_registration_document.go | 3 +++ .../api_smf_registrations_collection.go | 1 + ...mf_selection_subscription_data_document.go | 1 + ...s_management_subscription_data_document.go | 1 + .../api_sms_subscription_data_document.go | 1 + .../api_smsf3_gpp_registration_document.go | 3 +++ ...api_smsf_non3_gpp_registration_document.go | 3 +++ .../datarepository/api_trace_data_document.go | 1 + internal/sbi/datarepository/routers.go | 9 +++++++ internal/util/nf_authorization.go | 8 +----- 26 files changed, 79 insertions(+), 7 deletions(-) diff --git a/internal/sbi/datarepository/api_access_and_mobility_subscription_data_document.go b/internal/sbi/datarepository/api_access_and_mobility_subscription_data_document.go index 373c76d..eac4cf4 100644 --- a/internal/sbi/datarepository/api_access_and_mobility_subscription_data_document.go +++ b/internal/sbi/datarepository/api_access_and_mobility_subscription_data_document.go @@ -25,6 +25,7 @@ import ( func HTTPQueryAmData(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_amf3_gpp_access_registration_document.go b/internal/sbi/datarepository/api_amf3_gpp_access_registration_document.go index c301099..368d294 100644 --- a/internal/sbi/datarepository/api_amf3_gpp_access_registration_document.go +++ b/internal/sbi/datarepository/api_amf3_gpp_access_registration_document.go @@ -25,6 +25,7 @@ import ( func HTTPAmfContext3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -79,6 +80,7 @@ func HTTPAmfContext3gpp(c *gin.Context) { func HTTPCreateAmfContext3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -133,6 +135,7 @@ func HTTPCreateAmfContext3gpp(c *gin.Context) { func HTTPQueryAmfContext3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_amf_non3_gpp_access_registration_document.go b/internal/sbi/datarepository/api_amf_non3_gpp_access_registration_document.go index e365be2..12c2326 100644 --- a/internal/sbi/datarepository/api_amf_non3_gpp_access_registration_document.go +++ b/internal/sbi/datarepository/api_amf_non3_gpp_access_registration_document.go @@ -25,6 +25,7 @@ import ( func HTTPAmfContextNon3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -79,6 +80,7 @@ func HTTPAmfContextNon3gpp(c *gin.Context) { func HTTPCreateAmfContextNon3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -133,6 +135,7 @@ func HTTPCreateAmfContextNon3gpp(c *gin.Context) { func HTTPQueryAmfContextNon3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_amf_subscription_info_document.go b/internal/sbi/datarepository/api_amf_subscription_info_document.go index 6f57285..e5933c9 100644 --- a/internal/sbi/datarepository/api_amf_subscription_info_document.go +++ b/internal/sbi/datarepository/api_amf_subscription_info_document.go @@ -25,6 +25,7 @@ import ( func HTTPModifyAmfSubscriptionInfo(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_authentication_data_document.go b/internal/sbi/datarepository/api_authentication_data_document.go index 1786f19..04c2a2f 100644 --- a/internal/sbi/datarepository/api_authentication_data_document.go +++ b/internal/sbi/datarepository/api_authentication_data_document.go @@ -25,6 +25,7 @@ import ( func HTTPModifyAuthentication(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -79,6 +80,7 @@ func HTTPModifyAuthentication(c *gin.Context) { func HTTPQueryAuthSubsData(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_authentication_so_r_document.go b/internal/sbi/datarepository/api_authentication_so_r_document.go index 422dfba..0d771e8 100644 --- a/internal/sbi/datarepository/api_authentication_so_r_document.go +++ b/internal/sbi/datarepository/api_authentication_so_r_document.go @@ -25,6 +25,7 @@ import ( func HTTPCreateAuthenticationSoR(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -79,6 +80,7 @@ func HTTPCreateAuthenticationSoR(c *gin.Context) { func HTTPQueryAuthSoR(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_authentication_status_document.go b/internal/sbi/datarepository/api_authentication_status_document.go index bd5300a..c15fc69 100644 --- a/internal/sbi/datarepository/api_authentication_status_document.go +++ b/internal/sbi/datarepository/api_authentication_status_document.go @@ -25,6 +25,7 @@ import ( func HTTPCreateAuthenticationStatus(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -79,6 +80,7 @@ func HTTPCreateAuthenticationStatus(c *gin.Context) { func HTTPQueryAuthenticationStatus(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_default.go b/internal/sbi/datarepository/api_default.go index e795866..a536667 100644 --- a/internal/sbi/datarepository/api_default.go +++ b/internal/sbi/datarepository/api_default.go @@ -60,6 +60,7 @@ func getDataFromRequestBody(c *gin.Context, data interface{}) error { func HTTPApplicationDataPfdsAppIdDelete(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -71,6 +72,7 @@ func HTTPApplicationDataPfdsAppIdDelete(c *gin.Context) { func HTTPApplicationDataPfdsAppIdGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -82,6 +84,7 @@ func HTTPApplicationDataPfdsAppIdGet(c *gin.Context) { func HTTPApplicationDataPfdsAppIdPut(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -100,6 +103,7 @@ func HTTPApplicationDataPfdsAppIdPut(c *gin.Context) { func HTTPApplicationDataPfdsGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -127,6 +131,7 @@ func HTTPExposureDataSubsToNotifySubIdPut(c *gin.Context) { func HTTPPolicyDataBdtDataBdtReferenceIdDelete(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -142,6 +147,7 @@ func HTTPPolicyDataBdtDataBdtReferenceIdDelete(c *gin.Context) { func HTTPPolicyDataBdtDataBdtReferenceIdGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -157,6 +163,7 @@ func HTTPPolicyDataBdtDataBdtReferenceIdGet(c *gin.Context) { func HTTPPolicyDataBdtDataBdtReferenceIdPut(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -178,6 +185,7 @@ func HTTPPolicyDataBdtDataBdtReferenceIdPut(c *gin.Context) { func HTTPPolicyDataBdtDataGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -192,6 +200,7 @@ func HTTPPolicyDataBdtDataGet(c *gin.Context) { func HTTPPolicyDataPlmnsPlmnIdUePolicySetGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -207,6 +216,7 @@ func HTTPPolicyDataPlmnsPlmnIdUePolicySetGet(c *gin.Context) { func HTTPPolicyDataSponsorConnectivityDataSponsorIdGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -222,6 +232,7 @@ func HTTPPolicyDataSponsorConnectivityDataSponsorIdGet(c *gin.Context) { func HTTPPolicyDataSubsToNotifyPost(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -247,6 +258,7 @@ func HTTPPolicyDataSubsToNotifyPost(c *gin.Context) { func HTTPPolicyDataSubsToNotifySubsIdDelete(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -262,6 +274,7 @@ func HTTPPolicyDataSubsToNotifySubsIdDelete(c *gin.Context) { func HTTPPolicyDataSubsToNotifySubsIdPut(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -283,6 +296,7 @@ func HTTPPolicyDataSubsToNotifySubsIdPut(c *gin.Context) { func HTTPPolicyDataUesUeIdAmDataGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -298,6 +312,7 @@ func HTTPPolicyDataUesUeIdAmDataGet(c *gin.Context) { func HTTPPolicyDataUesUeIdOperatorSpecificDataGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -313,6 +328,7 @@ func HTTPPolicyDataUesUeIdOperatorSpecificDataGet(c *gin.Context) { func HTTPPolicyDataUesUeIdOperatorSpecificDataPatch(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -334,6 +350,7 @@ func HTTPPolicyDataUesUeIdOperatorSpecificDataPatch(c *gin.Context) { func HTTPPolicyDataUesUeIdOperatorSpecificDataPut(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -355,6 +372,7 @@ func HTTPPolicyDataUesUeIdOperatorSpecificDataPut(c *gin.Context) { func HTTPPolicyDataUesUeIdSmDataGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -370,6 +388,7 @@ func HTTPPolicyDataUesUeIdSmDataGet(c *gin.Context) { func HTTPPolicyDataUesUeIdSmDataPatch(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -391,6 +410,7 @@ func HTTPPolicyDataUesUeIdSmDataPatch(c *gin.Context) { func HTTPPolicyDataUesUeIdSmDataUsageMonIdDelete(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -407,6 +427,7 @@ func HTTPPolicyDataUesUeIdSmDataUsageMonIdDelete(c *gin.Context) { func HTTPPolicyDataUesUeIdSmDataUsageMonIdGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -423,8 +444,10 @@ func HTTPPolicyDataUesUeIdSmDataUsageMonIdGet(c *gin.Context) { func HTTPPolicyDataUesUeIdSmDataUsageMonIdPut(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } + var usageMonData models.UsageMonData if err := getDataFromRequestBody(c, &usageMonData); err != nil { @@ -444,6 +467,7 @@ func HTTPPolicyDataUesUeIdSmDataUsageMonIdPut(c *gin.Context) { func HTTPPolicyDataUesUeIdUePolicySetGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -459,6 +483,7 @@ func HTTPPolicyDataUesUeIdUePolicySetGet(c *gin.Context) { func HTTPPolicyDataUesUeIdUePolicySetPatch(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -480,8 +505,10 @@ func HTTPPolicyDataUesUeIdUePolicySetPatch(c *gin.Context) { func HTTPPolicyDataUesUeIdUePolicySetPut(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } + var uePolicySet models.UePolicySet if err := getDataFromRequestBody(c, &uePolicySet); err != nil { diff --git a/internal/sbi/datarepository/api_event_amf_subscription_info_document.go b/internal/sbi/datarepository/api_event_amf_subscription_info_document.go index ea1f4f6..cafc881 100644 --- a/internal/sbi/datarepository/api_event_amf_subscription_info_document.go +++ b/internal/sbi/datarepository/api_event_amf_subscription_info_document.go @@ -25,8 +25,10 @@ import ( func HTTPCreateAMFSubscriptions(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } + var amfSubscriptionInfoArray []models.AmfSubscriptionInfo requestBody, err := c.GetRawData() @@ -79,6 +81,7 @@ func HTTPCreateAMFSubscriptions(c *gin.Context) { func HTTPRemoveAmfSubscriptionsInfo(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_individual_influence_data_subscription_document.go b/internal/sbi/datarepository/api_individual_influence_data_subscription_document.go index 432c4dd..2e25950 100644 --- a/internal/sbi/datarepository/api_individual_influence_data_subscription_document.go +++ b/internal/sbi/datarepository/api_individual_influence_data_subscription_document.go @@ -25,6 +25,7 @@ import ( func HTTPApplicationDataInfluenceDataSubsToNotifySubscriptionIdDelete(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -58,6 +59,7 @@ func HTTPApplicationDataInfluenceDataSubsToNotifySubscriptionIdDelete(c *gin.Con func HTTPApplicationDataInfluenceDataSubsToNotifySubscriptionIdGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -87,6 +89,7 @@ func HTTPApplicationDataInfluenceDataSubsToNotifySubscriptionIdGet(c *gin.Contex func HTTPApplicationDataInfluenceDataSubsToNotifySubscriptionIdPut(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_influence_data.go b/internal/sbi/datarepository/api_influence_data.go index a56a9e0..40e2b66 100644 --- a/internal/sbi/datarepository/api_influence_data.go +++ b/internal/sbi/datarepository/api_influence_data.go @@ -25,6 +25,7 @@ import ( func HTTPApplicationDataInfluenceDataGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_provisioned_data_document.go b/internal/sbi/datarepository/api_provisioned_data_document.go index 8570acd..19f666a 100644 --- a/internal/sbi/datarepository/api_provisioned_data_document.go +++ b/internal/sbi/datarepository/api_provisioned_data_document.go @@ -25,6 +25,7 @@ import ( func HTTPQueryProvisionedData(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_query_amf_subscription_info_document.go b/internal/sbi/datarepository/api_query_amf_subscription_info_document.go index 9282db5..d03b854 100644 --- a/internal/sbi/datarepository/api_query_amf_subscription_info_document.go +++ b/internal/sbi/datarepository/api_query_amf_subscription_info_document.go @@ -25,6 +25,7 @@ import ( func HTTPGetAmfSubscriptionInfo(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_sdm_subscription_document.go b/internal/sbi/datarepository/api_sdm_subscription_document.go index fed5229..147db1e 100644 --- a/internal/sbi/datarepository/api_sdm_subscription_document.go +++ b/internal/sbi/datarepository/api_sdm_subscription_document.go @@ -25,6 +25,7 @@ import ( func HTTPRemovesdmSubscriptions(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -52,6 +53,7 @@ func HTTPRemovesdmSubscriptions(c *gin.Context) { func HTTPUpdatesdmsubscriptions(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_sdm_subscriptions_collection.go b/internal/sbi/datarepository/api_sdm_subscriptions_collection.go index 218ee4e..d6fa03b 100644 --- a/internal/sbi/datarepository/api_sdm_subscriptions_collection.go +++ b/internal/sbi/datarepository/api_sdm_subscriptions_collection.go @@ -25,6 +25,7 @@ import ( func HTTPCreateSdmSubscriptions(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -82,6 +83,7 @@ func HTTPCreateSdmSubscriptions(c *gin.Context) { func HTTPQuerysdmsubscriptions(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_session_management_subscription_data.go b/internal/sbi/datarepository/api_session_management_subscription_data.go index 208c5d6..5bef2a7 100644 --- a/internal/sbi/datarepository/api_session_management_subscription_data.go +++ b/internal/sbi/datarepository/api_session_management_subscription_data.go @@ -25,6 +25,7 @@ import ( func HTTPQuerySmData(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_smf_registration_document.go b/internal/sbi/datarepository/api_smf_registration_document.go index a5fa7ad..7187986 100644 --- a/internal/sbi/datarepository/api_smf_registration_document.go +++ b/internal/sbi/datarepository/api_smf_registration_document.go @@ -25,6 +25,7 @@ import ( func HTTPCreateSmfContextNon3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -79,6 +80,7 @@ func HTTPCreateSmfContextNon3gpp(c *gin.Context) { func HTTPDeleteSmfContext(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -106,6 +108,7 @@ func HTTPDeleteSmfContext(c *gin.Context) { func HTTPQuerySmfRegistration(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_smf_registrations_collection.go b/internal/sbi/datarepository/api_smf_registrations_collection.go index 878dc44..6d7b8e2 100644 --- a/internal/sbi/datarepository/api_smf_registrations_collection.go +++ b/internal/sbi/datarepository/api_smf_registrations_collection.go @@ -25,6 +25,7 @@ import ( func HTTPQuerySmfRegList(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_smf_selection_subscription_data_document.go b/internal/sbi/datarepository/api_smf_selection_subscription_data_document.go index 1fe086d..5fd29f2 100644 --- a/internal/sbi/datarepository/api_smf_selection_subscription_data_document.go +++ b/internal/sbi/datarepository/api_smf_selection_subscription_data_document.go @@ -25,6 +25,7 @@ import ( func HTTPQuerySmfSelectData(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_sms_management_subscription_data_document.go b/internal/sbi/datarepository/api_sms_management_subscription_data_document.go index 55c2b1d..d210c24 100644 --- a/internal/sbi/datarepository/api_sms_management_subscription_data_document.go +++ b/internal/sbi/datarepository/api_sms_management_subscription_data_document.go @@ -25,6 +25,7 @@ import ( func HTTPQuerySmsMngData(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_sms_subscription_data_document.go b/internal/sbi/datarepository/api_sms_subscription_data_document.go index 4bd3410..644bc06 100644 --- a/internal/sbi/datarepository/api_sms_subscription_data_document.go +++ b/internal/sbi/datarepository/api_sms_subscription_data_document.go @@ -25,6 +25,7 @@ import ( func HTTPQuerySmsData(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_smsf3_gpp_registration_document.go b/internal/sbi/datarepository/api_smsf3_gpp_registration_document.go index f6ab34e..761f38a 100644 --- a/internal/sbi/datarepository/api_smsf3_gpp_registration_document.go +++ b/internal/sbi/datarepository/api_smsf3_gpp_registration_document.go @@ -25,6 +25,7 @@ import ( func HTTPCreateSmsfContext3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -79,6 +80,7 @@ func HTTPCreateSmsfContext3gpp(c *gin.Context) { func HTTPDeleteSmsfContext3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -105,6 +107,7 @@ func HTTPDeleteSmsfContext3gpp(c *gin.Context) { func HTTPQuerySmsfContext3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_smsf_non3_gpp_registration_document.go b/internal/sbi/datarepository/api_smsf_non3_gpp_registration_document.go index 7380c2d..d874dc6 100644 --- a/internal/sbi/datarepository/api_smsf_non3_gpp_registration_document.go +++ b/internal/sbi/datarepository/api_smsf_non3_gpp_registration_document.go @@ -25,6 +25,7 @@ import ( func HTTPCreateSmsfContextNon3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -79,6 +80,7 @@ func HTTPCreateSmsfContextNon3gpp(c *gin.Context) { func HTTPDeleteSmsfContextNon3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -105,6 +107,7 @@ func HTTPDeleteSmsfContextNon3gpp(c *gin.Context) { func HTTPQuerySmsfContextNon3gpp(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/api_trace_data_document.go b/internal/sbi/datarepository/api_trace_data_document.go index a98724d..513c140 100644 --- a/internal/sbi/datarepository/api_trace_data_document.go +++ b/internal/sbi/datarepository/api_trace_data_document.go @@ -25,6 +25,7 @@ import ( func HTTPQueryTraceData(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/sbi/datarepository/routers.go b/internal/sbi/datarepository/routers.go index 7c92bcd..d5405fc 100644 --- a/internal/sbi/datarepository/routers.go +++ b/internal/sbi/datarepository/routers.go @@ -46,6 +46,7 @@ func NewRouter() *gin.Engine { func subMsgShortDispatchHandlerFunc(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -62,6 +63,7 @@ func subMsgShortDispatchHandlerFunc(c *gin.Context) { func subMsgDispatchHandlerFunc(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -87,6 +89,7 @@ func subMsgDispatchHandlerFunc(c *gin.Context) { func eeMsgShortDispatchHandlerFunc(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -109,6 +112,7 @@ func eeMsgShortDispatchHandlerFunc(c *gin.Context) { func eeMsgDispatchHandlerFunc(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -131,6 +135,7 @@ func eeMsgDispatchHandlerFunc(c *gin.Context) { func appMsgDispatchHandlerFunc(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -155,6 +160,7 @@ func appMsgDispatchHandlerFunc(c *gin.Context) { func expoMsgDispatchHandlerFunc(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -232,6 +238,7 @@ func Index(c *gin.Context) { func HandleAppDataInfluDataSubsToNotifyConflictDelete(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -247,6 +254,7 @@ func HandleAppDataInfluDataSubsToNotifyConflictDelete(c *gin.Context) { func HandleAppDataInfluDataSubsToNotifyConflictGet(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } @@ -262,6 +270,7 @@ func HandleAppDataInfluDataSubsToNotifyConflictGet(c *gin.Context) { func HandleAppDataInfluDataSubsToNotifyConflictPut(c *gin.Context) { auth_err := authorizationCheck(c) if auth_err != nil { + c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()}) return } diff --git a/internal/util/nf_authorization.go b/internal/util/nf_authorization.go index 48fe6af..1b38ad5 100644 --- a/internal/util/nf_authorization.go +++ b/internal/util/nf_authorization.go @@ -1,8 +1,6 @@ package util import ( - "net/http" - "github.com/gin-gonic/gin" "github.com/free5gc/openapi/oauth" @@ -11,12 +9,8 @@ import ( func AuthorizationCheck(c *gin.Context, serviceName string) error { if udr_context.GetSelf().OAuth2Required { - oauth_err := oauth.VerifyOAuth(c.Request.Header.Get("Authorization"), serviceName, + return oauth.VerifyOAuth(c.Request.Header.Get("Authorization"), serviceName, udr_context.GetSelf().NrfCertPem) - if oauth_err != nil { - c.JSON(http.StatusUnauthorized, gin.H{"error": oauth_err.Error()}) - return oauth_err - } } return nil }