From d27f03c789b8aa13f40469e4fef510dc936d9350 Mon Sep 17 00:00:00 2001 From: BenjaminWCO Date: Thu, 24 Oct 2024 17:00:27 +0100 Subject: [PATCH] ATO-983: Set InternalCommonSubjectIdentifier in AuthSession --- .../frontendapi/helpers/SessionHelper.java | 21 +++++++------ .../lambda/CheckUserExistsHandler.java | 31 ++++++++++++++++--- .../frontendapi/lambda/LoginHandler.java | 16 +++++----- .../frontendapi/lambda/SignUpHandler.java | 10 +++--- .../frontendapi/lambda/VerifyCodeHandler.java | 7 +++-- .../lambda/VerifyMfaCodeHandler.java | 7 +++-- .../lambda/CheckUserExistsHandlerTest.java | 28 +++++++++++++++++ .../api/CheckUserExistsIntegrationTest.java | 4 +++ .../shared/entity/AuthSessionItem.java | 19 ++++++++++-- 9 files changed, 110 insertions(+), 33 deletions(-) diff --git a/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/helpers/SessionHelper.java b/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/helpers/SessionHelper.java index dfe1b013fb..b40a4fbb03 100644 --- a/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/helpers/SessionHelper.java +++ b/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/helpers/SessionHelper.java @@ -3,9 +3,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import uk.gov.di.authentication.frontendapi.lambda.VerifyMfaCodeHandler; -import uk.gov.di.authentication.shared.entity.Session; +import uk.gov.di.authentication.shared.entity.AuthSessionItem; import uk.gov.di.authentication.shared.entity.UserProfile; import uk.gov.di.authentication.shared.helpers.ClientSubjectHelper; +import uk.gov.di.authentication.shared.services.AuthSessionService; import uk.gov.di.authentication.shared.services.AuthenticationService; import uk.gov.di.authentication.shared.services.ConfigurationService; import uk.gov.di.authentication.shared.services.SessionService; @@ -16,16 +17,18 @@ public class SessionHelper { public static void updateSessionWithSubject( UserContext userContext, - AuthenticationService authenticationService, - ConfigurationService configurationService, + AuthSessionItem authSession, SessionService sessionService, - Session session) { + AuthSessionService authSessionService, + AuthenticationService authenticationService, + ConfigurationService configurationService) { LOG.info("Calculating internal common subject identifier"); + var session = userContext.getSession(); UserProfile userProfile = userContext.getUserProfile().isPresent() ? userContext.getUserProfile().get() : authenticationService.getUserProfileByEmail(session.getEmailAddress()); - var internalCommonSubjectIdentifier = + var internalCommonSubjectId = session.getInternalCommonSubjectIdentifier() != null ? session.getInternalCommonSubjectIdentifier() : ClientSubjectHelper.getSubjectWithSectorIdentifier( @@ -34,9 +37,9 @@ public static void updateSessionWithSubject( authenticationService) .getValue(); LOG.info("Setting internal common subject identifier in user session"); - sessionService.storeOrUpdateSession( - userContext - .getSession() - .setInternalCommonSubjectIdentifier(internalCommonSubjectIdentifier)); + session.setInternalCommonSubjectIdentifier(internalCommonSubjectId); + sessionService.storeOrUpdateSession(session); + authSession.setInternalCommonSubjectId(internalCommonSubjectId); + authSessionService.updateSession(authSession); } } diff --git a/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/lambda/CheckUserExistsHandler.java b/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/lambda/CheckUserExistsHandler.java index 92948b6edd..b05803a297 100644 --- a/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/lambda/CheckUserExistsHandler.java +++ b/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/lambda/CheckUserExistsHandler.java @@ -12,6 +12,7 @@ import uk.gov.di.authentication.frontendapi.entity.CheckUserExistsResponse; import uk.gov.di.authentication.frontendapi.entity.LockoutInformation; import uk.gov.di.authentication.shared.domain.AuditableEvent; +import uk.gov.di.authentication.shared.entity.AuthSessionItem; import uk.gov.di.authentication.shared.entity.ErrorResponse; import uk.gov.di.authentication.shared.entity.JourneyType; import uk.gov.di.authentication.shared.entity.MFAMethodType; @@ -22,6 +23,7 @@ import uk.gov.di.authentication.shared.lambda.BaseFrontendHandler; import uk.gov.di.authentication.shared.serialization.Json.JsonException; import uk.gov.di.authentication.shared.services.AuditService; +import uk.gov.di.authentication.shared.services.AuthSessionService; import uk.gov.di.authentication.shared.services.AuthenticationService; import uk.gov.di.authentication.shared.services.ClientService; import uk.gov.di.authentication.shared.services.ClientSessionService; @@ -50,10 +52,12 @@ public class CheckUserExistsHandler extends BaseFrontendHandler