Skip to content

Commit

Permalink
ATO-1248: Add AuthSession To UserContext
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminWCO committed Nov 28, 2024
1 parent 7f5efd8 commit e3e522c
Show file tree
Hide file tree
Showing 49 changed files with 243 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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;
Expand Down Expand Up @@ -96,6 +97,7 @@ public AccountInterventionsHandler(ConfigurationService configurationService) {
protected AccountInterventionsHandler(
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuthenticationService authenticationService,
Expand All @@ -108,6 +110,7 @@ protected AccountInterventionsHandler(
AccountInterventionsRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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;
Expand All @@ -37,6 +38,7 @@ public class AccountRecoveryHandler extends BaseFrontendHandler<AccountRecoveryR
protected AccountRecoveryHandler(
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuthenticationService authenticationService,
Expand All @@ -46,6 +48,7 @@ protected AccountRecoveryHandler(
AccountRecoveryRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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;
Expand Down Expand Up @@ -52,6 +53,7 @@ public AuthenticationAuthCodeHandler(
DynamoAuthCodeService dynamoAuthCodeService,
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuthenticationService authenticationService,
Expand All @@ -61,6 +63,7 @@ public AuthenticationAuthCodeHandler(
AuthCodeRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import uk.gov.di.authentication.shared.lambda.BaseFrontendHandler;
import uk.gov.di.authentication.shared.serialization.Json;
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;
Expand All @@ -43,6 +44,7 @@ public class CheckEmailFraudBlockHandler extends BaseFrontendHandler<CheckEmailF
protected CheckEmailFraudBlockHandler(
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuthenticationService authenticationService,
Expand All @@ -52,6 +54,7 @@ protected CheckEmailFraudBlockHandler(
CheckEmailFraudBlockRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import uk.gov.di.authentication.shared.helpers.ReauthAuthenticationAttemptsHelper;
import uk.gov.di.authentication.shared.lambda.BaseFrontendHandler;
import uk.gov.di.authentication.shared.services.AuditService;
import uk.gov.di.authentication.shared.services.AuthSessionService;
import uk.gov.di.authentication.shared.services.AuthenticationAttemptsService;
import uk.gov.di.authentication.shared.services.AuthenticationService;
import uk.gov.di.authentication.shared.services.ClientService;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class CheckReAuthUserHandler extends BaseFrontendHandler<CheckReauthUserR
public CheckReAuthUserHandler(
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuthenticationService authenticationService,
Expand All @@ -72,6 +74,7 @@ public CheckReAuthUserHandler(
CheckReauthUserRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public CheckUserExistsHandler(
CheckUserExistsRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public LoginHandler(
LoginRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,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.AwsSqsClient;
import uk.gov.di.authentication.shared.services.ClientService;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class MfaHandler extends BaseFrontendHandler<MfaRequest>
public MfaHandler(
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
CodeGeneratorService codeGeneratorService,
CodeStorageService codeStorageService,
ClientSessionService clientSessionService,
Expand All @@ -78,6 +80,7 @@ public MfaHandler(
MfaRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import uk.gov.di.authentication.shared.lambda.BaseFrontendHandler;
import uk.gov.di.authentication.shared.serialization.Json;
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;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class MfaResetAuthorizeHandler extends BaseFrontendHandler<MfaResetReques
public MfaResetAuthorizeHandler(
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuthenticationService authenticationService,
Expand All @@ -55,6 +57,7 @@ public MfaResetAuthorizeHandler(
MfaResetRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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.AwsSqsClient;
import uk.gov.di.authentication.shared.services.ClientService;
Expand Down Expand Up @@ -70,6 +71,7 @@ public ResetPasswordHandler(
CodeStorageService codeStorageService,
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuditService auditService,
Expand All @@ -80,6 +82,7 @@ public ResetPasswordHandler(
ResetPasswordCompletionRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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.AwsSqsClient;
import uk.gov.di.authentication.shared.services.ClientService;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class ResetPasswordRequestHandler extends BaseFrontendHandler<ResetPasswo
public ResetPasswordRequestHandler(
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuthenticationService authenticationService,
Expand All @@ -73,6 +75,7 @@ public ResetPasswordRequestHandler(
ResetPasswordRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import uk.gov.di.authentication.shared.helpers.PersistentIdHelper;
import uk.gov.di.authentication.shared.lambda.BaseFrontendHandler;
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;
Expand All @@ -41,6 +42,7 @@ public class ReverificationResultHandler extends BaseFrontendHandler<Reverificat
public ReverificationResultHandler(
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuthenticationService authenticationService,
Expand All @@ -50,6 +52,7 @@ public ReverificationResultHandler(
ReverificationResultRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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.AwsSqsClient;
import uk.gov.di.authentication.shared.services.ClientService;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class SendNotificationHandler extends BaseFrontendHandler<SendNotificatio
public SendNotificationHandler(
ConfigurationService configurationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ClientService clientService,
AuthenticationService authenticationService,
Expand All @@ -102,6 +104,7 @@ public SendNotificationHandler(
SendNotificationRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public SignUpHandler(
SignupRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ public APIGatewayProxyResponseEvent handleRequest(
APIGatewayProxyRequestEvent input, Context context) {
ThreadContext.clearMap();
LOG.info("Start request received");

var session = sessionService.getSessionFromRequestHeaders(input.getHeaders()).orElse(null);
if (Objects.isNull(session)) {
return generateApiGatewayProxyErrorResponse(400, ErrorResponse.ERROR_1000);
} else {
attachSessionIdToLogs(session);
LOG.info("Start session retrieved");
}

attachLogFieldToLogs(
PERSISTENT_SESSION_ID, extractPersistentIdFromHeaders(input.getHeaders()));

Expand Down Expand Up @@ -174,7 +176,7 @@ public APIGatewayProxyResponseEvent handleRequest(
configurationService.getHeadersCaseInsensitive()));
}

var userContext = startService.buildUserContext(session, clientSession.get());
var userContext = startService.buildUserContext(session, null, clientSession.get());

attachLogFieldToLogs(
CLIENT_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import uk.gov.di.authentication.shared.helpers.PersistentIdHelper;
import uk.gov.di.authentication.shared.lambda.BaseFrontendHandler;
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;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class UpdateProfileHandler extends BaseFrontendHandler<UpdateProfileReque
protected UpdateProfileHandler(
AuthenticationService authenticationService,
SessionService sessionService,
AuthSessionService authSessionService,
ClientSessionService clientSessionService,
ConfigurationService configurationService,
AuditService auditService,
Expand All @@ -54,6 +56,7 @@ protected UpdateProfileHandler(
UpdateProfileRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ protected VerifyCodeHandler(
VerifyCodeRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public VerifyMfaCodeHandler(
VerifyMfaCodeRequest.class,
configurationService,
sessionService,
authSessionService,
clientSessionService,
clientService,
authenticationService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import uk.gov.di.authentication.frontendapi.entity.UserStartInfo;
import uk.gov.di.authentication.shared.conditions.DocAppUserHelper;
import uk.gov.di.authentication.shared.conditions.IdentityHelper;
import uk.gov.di.authentication.shared.entity.AuthSessionItem;
import uk.gov.di.authentication.shared.entity.ClientRegistry;
import uk.gov.di.authentication.shared.entity.ClientSession;
import uk.gov.di.authentication.shared.entity.MFAMethod;
Expand Down Expand Up @@ -64,8 +65,9 @@ public Session createNewSessionWithExistingIdAndClientSession(
return session;
}

public UserContext buildUserContext(Session session, ClientSession clientSession) {
var builder = UserContext.builder(session).withClientSession(clientSession);
public UserContext buildUserContext(
Session session, Optional<AuthSessionItem> authSession, ClientSession clientSession) {
var builder = UserContext.builder(session, authSession).withClientSession(clientSession);
UserContext userContext;
try {
var clientId =
Expand Down
Loading

0 comments on commit e3e522c

Please sign in to comment.