Skip to content

Commit

Permalink
BAU: refactor AuthenticateRequest to a record
Browse files Browse the repository at this point in the history
  • Loading branch information
alhcomer committed Oct 9, 2024
1 parent 45bd1c4 commit 26efbd0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,5 @@
import com.google.gson.annotations.Expose;
import uk.gov.di.authentication.shared.validation.Required;

public class AuthenticateRequest {

@Expose @Required private String email;

@Expose @Required private String password;

public AuthenticateRequest() {}

public AuthenticateRequest(String email, String password) {
this.email = email;
this.password = password;
}

public String getEmail() {
return email;
}

public String getPassword() {
return password;
}
}
public record AuthenticateRequest(
@Expose @Required String email, @Expose @Required String password) {}
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,15 @@ public APIGatewayProxyResponseEvent authenticateRequestHandler(
try {
AuthenticateRequest loginRequest =
objectMapper.readValue(input.getBody(), AuthenticateRequest.class);
auditContext = auditContext.withEmail(loginRequest.getEmail());
boolean userHasAccount = authenticationService.userExists(loginRequest.getEmail());
auditContext = auditContext.withEmail(loginRequest.email());
boolean userHasAccount = authenticationService.userExists(loginRequest.email());
if (!userHasAccount) {
auditService.submitAuditEvent(
AUTH_ACCOUNT_MANAGEMENT_AUTHENTICATE_FAILURE, auditContext);
return generateApiGatewayProxyErrorResponse(400, ErrorResponse.ERROR_1010);
}
boolean hasValidCredentials =
authenticationService.login(
loginRequest.getEmail(), loginRequest.getPassword());
authenticationService.login(loginRequest.email(), loginRequest.password());
if (!hasValidCredentials) {
auditService.submitAuditEvent(
AUTH_ACCOUNT_MANAGEMENT_AUTHENTICATE_FAILURE, auditContext);
Expand Down

0 comments on commit 26efbd0

Please sign in to comment.