@@ -468,7 +468,7 @@ func (t *BaseMiddleware) UpdateRequestSession(r *http.Request) bool {
468468
469469 // Reset session state, useful for benchmarks when request object stays the same.
470470 session .Reset ()
471- // Mark session as restored for
471+ // Mark session as restored; (makes invoke `SET key val XX` in further calls)
472472 session .MarkAsRestored ()
473473
474474 if ! t .Spec .GlobalConfig .LocalSessionCache .DisableCacheSessionState {
@@ -653,6 +653,7 @@ func (t *BaseMiddleware) CheckSessionAndIdentityForValidKey(originalKey string,
653653 if found {
654654 t .Logger ().Debug ("--> Key found in local cache" )
655655 session := cachedVal .(user.SessionState ).Clone ()
656+ session .MarkAsRestored ()
656657 if err := t .ApplyPolicies (& session ); err != nil {
657658 t .Logger ().Error (err )
658659 return session , false
@@ -704,6 +705,18 @@ func (t *BaseMiddleware) CheckSessionAndIdentityForValidKey(originalKey string,
704705 // If not in Session, and got it from AuthHandler, create a session with a new TTL
705706 t .Logger ().Info ("Recreating session for key: " , t .Gw .obfuscateKey (key ))
706707
708+ {
709+ // insert new session
710+ clonedSession := session .Clone ()
711+ clonedSession .MarkAsNew ()
712+
713+ lifetime := clonedSession .Lifetime (t .Spec .GetSessionLifetimeRespectsKeyExpiration (), t .Spec .SessionLifetime , t .Gw .GetConfig ().ForceGlobalSessionLifetime , t .Gw .GetConfig ().GlobalSessionLifetime )
714+ if err := t .Gw .GlobalSessionManager .UpdateSession (key , & clonedSession , lifetime , false ); err != nil {
715+ t .Logger ().WithError (err ).Error ("Cant copy session from AuthManager into GlobalSessionManager" )
716+ return user.SessionState {}, false
717+ }
718+ }
719+
707720 // cache it
708721 if ! t .Spec .GlobalConfig .LocalSessionCache .DisableCacheSessionState {
709722 go t .Gw .SessionCache .Set (cacheKey , session .Clone (), cache .DefaultExpiration )
@@ -719,7 +732,6 @@ func (t *BaseMiddleware) CheckSessionAndIdentityForValidKey(originalKey string,
719732 t .Logger ().Debug ("Lifetime is: " , session .Lifetime (t .Spec .GetSessionLifetimeRespectsKeyExpiration (), t .Spec .SessionLifetime , t .Gw .GetConfig ().ForceGlobalSessionLifetime , t .Gw .GetConfig ().GlobalSessionLifetime ))
720733
721734 session .Touch ()
722- session .MarkAsNew () // mark remote MDCB session as new to make possible save it into the local storage (local redis)
723735
724736 return session , found
725737 }
0 commit comments