Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Service authorization check via OAuth token #23

Merged
merged 5 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,14 @@ func (c *UDRContext) GetTokenCtx(scope, targetNF string) (
return oauth.GetTokenCtx(models.NfType_UDR,
c.NfId, c.NrfUri, scope, targetNF)
}

func (context *UDRContext) AuthorizationCheck(token, serviceName string) error {
if !context.OAuth2Required {
return nil
}
err := oauth.VerifyOAuth(token, serviceName, context.NrfCertPem)
if err != nil {
return err
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (

// HTTPQueryAmData - Retrieves the access and mobility subscription data of a UE
func HTTPQueryAmData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")
req.Params["servingPlmnId"] = c.Params.ByName("servingPlmnId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (

// HTTPAmfContext3gpp - To modify the AMF context data of a UE using 3gpp access in the UDR
func HTTPAmfContext3gpp(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

var patchItemArray []models.PatchItem

requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -72,6 +78,12 @@ func HTTPAmfContext3gpp(c *gin.Context) {

// HTTPCreateAmfContext3gpp - To store the AMF context data of a UE using 3gpp access in the UDR
func HTTPCreateAmfContext3gpp(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

var amf3GppAccessRegistration models.Amf3GppAccessRegistration

requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -121,6 +133,12 @@ func HTTPCreateAmfContext3gpp(c *gin.Context) {

// HTTPQueryAmfContext3gpp - Retrieves the AMF context data of a UE using 3gpp access
func HTTPQueryAmfContext3gpp(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (

// HTTPAmfContextNon3gpp - To modify the AMF context data of a UE using non 3gpp access in the UDR
func HTTPAmfContextNon3gpp(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

var patchItemArray []models.PatchItem

requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -72,6 +78,12 @@ func HTTPAmfContextNon3gpp(c *gin.Context) {

// HTTPCreateAmfContextNon3gpp - To store the AMF context data of a UE using non-3gpp access in the UDR
func HTTPCreateAmfContextNon3gpp(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

var amfNon3GppAccessRegistration models.AmfNon3GppAccessRegistration

requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -121,6 +133,12 @@ func HTTPCreateAmfContextNon3gpp(c *gin.Context) {

// HTTPQueryAmfContextNon3gpp - Retrieves the AMF context data of a UE using non-3gpp access
func HTTPQueryAmfContextNon3gpp(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (

// HTTPModifyAmfSubscriptionInfo - modify the AMF Subscription Info
func HTTPModifyAmfSubscriptionInfo(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

var patchItemArray []models.PatchItem

requestBody, err := c.GetRawData()
Expand Down
12 changes: 12 additions & 0 deletions internal/sbi/datarepository/api_authentication_data_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (

// HTTPModifyAuthentication - modify the authentication subscription data of a UE
func HTTPModifyAuthentication(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

var patchItemArray []models.PatchItem

requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -72,6 +78,12 @@ func HTTPModifyAuthentication(c *gin.Context) {

// HTTPQueryAuthSubsData - Retrieves the authentication subscription data of a UE
func HTTPQueryAuthSubsData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
12 changes: 12 additions & 0 deletions internal/sbi/datarepository/api_authentication_so_r_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (

// HTTPCreateAuthenticationSoR - To store the SoR acknowledgement information of a UE
func HTTPCreateAuthenticationSoR(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

var sorData models.SorData

requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -72,6 +78,12 @@ func HTTPCreateAuthenticationSoR(c *gin.Context) {

// HTTPQueryAuthSoR - Retrieves the SoR acknowledgement information of a UE
func HTTPQueryAuthSoR(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
12 changes: 12 additions & 0 deletions internal/sbi/datarepository/api_authentication_status_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (

// HTTPCreateAuthenticationStatus - To store the Authentication Status data of a UE
func HTTPCreateAuthenticationStatus(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

var authEvent models.AuthEvent

requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -72,6 +78,12 @@ func HTTPCreateAuthenticationStatus(c *gin.Context) {

// HTTPQueryAuthenticationStatus - Retrieves the Authentication Status of a UE
func HTTPQueryAuthenticationStatus(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": auth_err.Error()})
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
Loading