@@ -351,7 +351,7 @@ public static SessionInformationHolder getSession(AppIdentifier appIdentifier, M
351351 accessToken .sessionHandle ,
352352 Utils .hashSHA256 (accessToken .refreshTokenHash1 ),
353353 System .currentTimeMillis () +
354- config .getRefreshTokenValidity ());
354+ config .getRefreshTokenValidity (), sessionInfo . useStaticKey );
355355 }
356356 storage .commitTransaction (con );
357357
@@ -423,7 +423,7 @@ public static SessionInformationHolder getSession(AppIdentifier appIdentifier, M
423423 Utils .hashSHA256 (accessToken .refreshTokenHash1 ),
424424 System .currentTimeMillis () + Config .getConfig (tenantIdentifierWithStorage , main )
425425 .getRefreshTokenValidity (),
426- sessionInfo .lastUpdatedSign );
426+ sessionInfo .lastUpdatedSign , sessionInfo . useStaticKey );
427427 if (!success ) {
428428 continue ;
429429 }
@@ -473,7 +473,7 @@ public static SessionInformationHolder refreshSession(Main main, @Nonnull String
473473 UnsupportedJWTSigningAlgorithmException , AccessTokenPayloadError {
474474 try {
475475 return refreshSession (new AppIdentifier (null , null ), main , refreshToken , antiCsrfToken ,
476- enableAntiCsrf , accessTokenVersion );
476+ enableAntiCsrf , accessTokenVersion , null );
477477 } catch (TenantOrAppNotFoundException e ) {
478478 throw new IllegalStateException (e );
479479 }
@@ -482,7 +482,8 @@ public static SessionInformationHolder refreshSession(Main main, @Nonnull String
482482 public static SessionInformationHolder refreshSession (AppIdentifier appIdentifier , Main main ,
483483 @ Nonnull String refreshToken ,
484484 @ Nullable String antiCsrfToken , boolean enableAntiCsrf ,
485- AccessToken .VERSION accessTokenVersion )
485+ AccessToken .VERSION accessTokenVersion ,
486+ Boolean shouldUseStaticKey )
486487 throws StorageTransactionLogicException ,
487488 UnauthorisedException , StorageQueryException , TokenTheftDetectedException ,
488489 UnsupportedJWTSigningAlgorithmException , AccessTokenPayloadError , TenantOrAppNotFoundException {
@@ -498,14 +499,15 @@ public static SessionInformationHolder refreshSession(AppIdentifier appIdentifie
498499
499500 return refreshSessionHelper (refreshTokenInfo .tenantIdentifier .withStorage (
500501 StorageLayer .getStorage (refreshTokenInfo .tenantIdentifier , main )),
501- main , refreshToken , refreshTokenInfo , enableAntiCsrf , accessTokenVersion );
502+ main , refreshToken , refreshTokenInfo , enableAntiCsrf , accessTokenVersion , shouldUseStaticKey );
502503 }
503504
504505 private static SessionInformationHolder refreshSessionHelper (
505506 TenantIdentifierWithStorage tenantIdentifierWithStorage , Main main , String refreshToken ,
506507 RefreshToken .RefreshTokenInfo refreshTokenInfo ,
507508 boolean enableAntiCsrf ,
508- AccessToken .VERSION accessTokenVersion )
509+ AccessToken .VERSION accessTokenVersion ,
510+ Boolean shouldUseStaticKey )
509511 throws StorageTransactionLogicException , UnauthorisedException , StorageQueryException ,
510512 TokenTheftDetectedException , UnsupportedJWTSigningAlgorithmException , AccessTokenPayloadError ,
511513 TenantOrAppNotFoundException {
@@ -530,7 +532,16 @@ private static SessionInformationHolder refreshSessionHelper(
530532 throw new UnauthorisedException ("Session missing in db or has expired" );
531533 }
532534
535+ boolean useStaticKey = shouldUseStaticKey != null ? shouldUseStaticKey : sessionInfo .useStaticKey ;
536+
533537 if (sessionInfo .refreshTokenHash2 .equals (Utils .hashSHA256 (Utils .hashSHA256 (refreshToken )))) {
538+ if (useStaticKey != sessionInfo .useStaticKey ) {
539+ // We do not update anything except the static key status
540+ storage .updateSessionInfo_Transaction (tenantIdentifierWithStorage , con , sessionHandle ,
541+ sessionInfo .refreshTokenHash2 , sessionInfo .expiry ,
542+ useStaticKey );
543+ }
544+
534545 // at this point, the input refresh token is the parent one.
535546 storage .commitTransaction (con );
536547 String antiCsrfToken = enableAntiCsrf ? UUID .randomUUID ().toString () : null ;
@@ -542,7 +553,7 @@ private static SessionInformationHolder refreshSessionHelper(
542553 main , sessionHandle ,
543554 sessionInfo .userId , Utils .hashSHA256 (newRefreshToken .token ),
544555 Utils .hashSHA256 (refreshToken ), sessionInfo .userDataInJWT , antiCsrfToken ,
545- null , accessTokenVersion , sessionInfo . useStaticKey );
556+ null , accessTokenVersion , useStaticKey );
546557
547558 TokenInfo idRefreshToken = new TokenInfo (UUID .randomUUID ().toString (),
548559 newRefreshToken .expiry , newRefreshToken .createdTime );
@@ -560,13 +571,13 @@ private static SessionInformationHolder refreshSessionHelper(
560571 .equals (sessionInfo .refreshTokenHash2 ))) {
561572 storage .updateSessionInfo_Transaction (tenantIdentifierWithStorage , con , sessionHandle ,
562573 Utils .hashSHA256 (Utils .hashSHA256 (refreshToken )),
563- System .currentTimeMillis () + config .getRefreshTokenValidity ());
574+ System .currentTimeMillis () + config .getRefreshTokenValidity (), useStaticKey );
564575
565576 storage .commitTransaction (con );
566577
567578 return refreshSessionHelper (tenantIdentifierWithStorage , main , refreshToken ,
568579 refreshTokenInfo , enableAntiCsrf ,
569- accessTokenVersion );
580+ accessTokenVersion , shouldUseStaticKey );
570581 }
571582
572583 storage .commitTransaction (con );
@@ -613,7 +624,19 @@ private static SessionInformationHolder refreshSessionHelper(
613624 throw new UnauthorisedException ("Session missing in db or has expired" );
614625 }
615626
627+ boolean useStaticKey = shouldUseStaticKey != null ? shouldUseStaticKey : sessionInfo .useStaticKey ;
628+
616629 if (sessionInfo .refreshTokenHash2 .equals (Utils .hashSHA256 (Utils .hashSHA256 (refreshToken )))) {
630+ if (sessionInfo .useStaticKey != useStaticKey ) {
631+ // We do not update anything except the static key status
632+ boolean success = storage .updateSessionInfo_Transaction (sessionHandle ,
633+ sessionInfo .refreshTokenHash2 , sessionInfo .expiry ,
634+ sessionInfo .lastUpdatedSign , useStaticKey );
635+ if (!success ) {
636+ continue ;
637+ }
638+ }
639+
617640 // at this point, the input refresh token is the parent one.
618641 String antiCsrfToken = enableAntiCsrf ? UUID .randomUUID ().toString () : null ;
619642
@@ -624,7 +647,7 @@ private static SessionInformationHolder refreshSessionHelper(
624647 sessionHandle ,
625648 sessionInfo .userId , Utils .hashSHA256 (newRefreshToken .token ),
626649 Utils .hashSHA256 (refreshToken ), sessionInfo .userDataInJWT , antiCsrfToken ,
627- null , accessTokenVersion , sessionInfo . useStaticKey );
650+ null , accessTokenVersion , useStaticKey );
628651
629652 TokenInfo idRefreshToken = new TokenInfo (UUID .randomUUID ().toString (), newRefreshToken .expiry ,
630653 newRefreshToken .createdTime );
@@ -644,13 +667,13 @@ private static SessionInformationHolder refreshSessionHelper(
644667 Utils .hashSHA256 (Utils .hashSHA256 (refreshToken )),
645668 System .currentTimeMillis () +
646669 Config .getConfig (tenantIdentifierWithStorage , main ).getRefreshTokenValidity (),
647- sessionInfo .lastUpdatedSign );
670+ sessionInfo .lastUpdatedSign , useStaticKey );
648671 if (!success ) {
649672 continue ;
650673 }
651674 return refreshSessionHelper (tenantIdentifierWithStorage , main , refreshToken , refreshTokenInfo ,
652675 enableAntiCsrf ,
653- accessTokenVersion );
676+ accessTokenVersion , shouldUseStaticKey );
654677 }
655678
656679 throw new TokenTheftDetectedException (sessionHandle , sessionInfo .userId );
0 commit comments