diff --git a/internal/context/context.go b/internal/context/context.go index ad9a08d..cef8857 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -120,6 +120,26 @@ func AddAusfUeContextToPool(ausfUeContext *AusfUeContext) { ausfContext.UePool.Store(ausfUeContext.Supi, ausfUeContext) } +func AddAusfUeContextToPoolIfNoOngoing(ausfUeContext *AusfUeContext) (existing *AusfUeContext, ok bool) { + for { + // TODO: model ServingNetworkName in the context key/lookup lifecycle if + // AUSF needs to separate the same SUPI across serving networks. + context, loaded := ausfContext.UePool.LoadOrStore(ausfUeContext.Supi, ausfUeContext) + if !loaded { + return nil, true + } + + existingContext := context.(*AusfUeContext) + if existingContext.AuthStatus == models.AusfUeAuthenticationAuthResult_ONGOING { + return existingContext, false + } + + if ausfContext.UePool.CompareAndSwap(ausfUeContext.Supi, existingContext, ausfUeContext) { + return existingContext, true + } + } +} + func CheckIfAusfUeContextExists(ref string) bool { _, ok := ausfContext.UePool.Load(ref) return ok diff --git a/internal/sbi/processor/ue_authentication.go b/internal/sbi/processor/ue_authentication.go index e519dbc..57b5815 100644 --- a/internal/sbi/processor/ue_authentication.go +++ b/internal/sbi/processor/ue_authentication.go @@ -360,7 +360,21 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat ausfUeContext.ServingNetworkName = snName ausfUeContext.AuthStatus = models.AusfUeAuthenticationAuthResult_ONGOING ausfUeContext.UdmUeauUrl = udmUrl - ausf_context.AddAusfUeContextToPool(ausfUeContext) + if updateAuthenticationInfo.ResynchronizationInfo != nil { + ausf_context.AddAusfUeContextToPool(ausfUeContext) + } else if existingContext, ok := ausf_context.AddAusfUeContextToPoolIfNoOngoing(ausfUeContext); !ok { + logger.UeAuthLog.Warnf("authentication already in progress for SUPI %s with status %s", + ueid, existingContext.AuthStatus) + problemDetails := models.ProblemDetails{ + Title: "Authentication already in progress", + Cause: "AUTHENTICATION_IN_PROGRESS", + Detail: "an authentication procedure for this SUPI is already in progress", + Status: http.StatusConflict, + } + c.Set(sbi.IN_PB_DETAILS_CTX_STR, problemDetails.Cause) + c.JSON(http.StatusConflict, problemDetails) + return + } logger.UeAuthLog.Infof("Add SuciSupiPair (%s, %s) to map.\n", supiOrSuci, ueid) ausf_context.AddSuciSupiPairToMap(supiOrSuci, ueid)