Search in sources :

Example 1 with MFA_SMS

use of uk.gov.di.authentication.shared.entity.NotificationType.MFA_SMS in project di-authentication-api by alphagov.

the class VerifyCodeHandler method getOtpCodeForTestClient.

private Optional<String> getOtpCodeForTestClient(UserContext userContext, NotificationType notificationType) throws ClientNotFoundException {
    LOG.warn("TestClients are ENABLED");
    final String emailAddress = userContext.getSession().getEmailAddress();
    final Optional<String> generatedOTPCode = codeStorageService.getOtpCode(emailAddress, notificationType);
    return userContext.getClient().map(clientRegistry -> {
        if (clientRegistry.isTestClient() && clientRegistry.getTestClientEmailAllowlist().contains(emailAddress)) {
            LOG.info("Using TestClient with NotificationType {}", notificationType);
            switch(notificationType) {
                case VERIFY_EMAIL:
                    return configurationService.getTestClientVerifyEmailOTP();
                case VERIFY_PHONE_NUMBER:
                    return configurationService.getTestClientVerifyPhoneNumberOTP();
                case MFA_SMS:
                    return configurationService.getTestClientVerifyPhoneNumberOTP();
                default:
                    LOG.info("Returning the generated OTP for NotificationType {}", notificationType);
                    return generatedOTPCode;
            }
        } else {
            return generatedOTPCode;
        }
    }).orElseThrow(() -> new ClientNotFoundException(userContext.getSession()));
}
Also used : ClientRegistry(uk.gov.di.authentication.shared.entity.ClientRegistry) CodeStorageService(uk.gov.di.authentication.shared.services.CodeStorageService) SessionService(uk.gov.di.authentication.shared.services.SessionService) Context(com.amazonaws.services.lambda.runtime.Context) ConfigurationService(uk.gov.di.authentication.shared.services.ConfigurationService) MFA_SMS(uk.gov.di.authentication.shared.entity.NotificationType.MFA_SMS) RequestHeaderHelper.getHeaderValueFromHeaders(uk.gov.di.authentication.shared.helpers.RequestHeaderHelper.getHeaderValueFromHeaders) RequestHandler(com.amazonaws.services.lambda.runtime.RequestHandler) AuthenticationService(uk.gov.di.authentication.shared.services.AuthenticationService) APIGatewayProxyRequestEvent(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent) Session(uk.gov.di.authentication.shared.entity.Session) ClientService(uk.gov.di.authentication.shared.services.ClientService) ApiGatewayResponseHelper.generateEmptySuccessApiGatewayResponse(uk.gov.di.authentication.shared.helpers.ApiGatewayResponseHelper.generateEmptySuccessApiGatewayResponse) VERIFY_EMAIL(uk.gov.di.authentication.shared.entity.NotificationType.VERIFY_EMAIL) PersistentIdHelper.extractPersistentIdFromHeaders(uk.gov.di.authentication.shared.helpers.PersistentIdHelper.extractPersistentIdFromHeaders) CODE_BLOCKED_KEY_PREFIX(uk.gov.di.authentication.shared.services.CodeStorageService.CODE_BLOCKED_KEY_PREFIX) PERSISTENT_SESSION_ID(uk.gov.di.authentication.shared.helpers.LogLineHelper.LogFieldName.PERSISTENT_SESSION_ID) Map(java.util.Map) UserProfile(uk.gov.di.authentication.shared.entity.UserProfile) Map.entry(java.util.Map.entry) CLIENT_ID(uk.gov.di.authentication.shared.helpers.LogLineHelper.LogFieldName.CLIENT_ID) MetadataPair.pair(uk.gov.di.authentication.shared.services.AuditService.MetadataPair.pair) FrontendAuditableEvent(uk.gov.di.authentication.frontendapi.domain.FrontendAuditableEvent) AuditableEvent(uk.gov.di.authentication.shared.domain.AuditableEvent) VERIFY_PHONE_NUMBER(uk.gov.di.authentication.shared.entity.NotificationType.VERIFY_PHONE_NUMBER) IpAddressHelper(uk.gov.di.authentication.shared.helpers.IpAddressHelper) APIGatewayProxyResponseEvent(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent) AuditService(uk.gov.di.authentication.shared.services.AuditService) LogLineHelper.attachLogFieldToLogs(uk.gov.di.authentication.shared.helpers.LogLineHelper.attachLogFieldToLogs) CredentialTrustLevel(uk.gov.di.authentication.shared.entity.CredentialTrustLevel) ClientNotFoundException(uk.gov.di.authentication.shared.exceptions.ClientNotFoundException) VerifyCodeRequest(uk.gov.di.authentication.frontendapi.entity.VerifyCodeRequest) VectorOfTrust(uk.gov.di.authentication.shared.entity.VectorOfTrust) ErrorResponse(uk.gov.di.authentication.shared.entity.ErrorResponse) ValidationHelper(uk.gov.di.authentication.shared.helpers.ValidationHelper) BaseFrontendHandler(uk.gov.di.authentication.shared.lambda.BaseFrontendHandler) ClientSessionService(uk.gov.di.authentication.shared.services.ClientSessionService) List(java.util.List) Logger(org.apache.logging.log4j.Logger) RequestHeaders(uk.gov.di.authentication.shared.domain.RequestHeaders) RedisConnectionService(uk.gov.di.authentication.shared.services.RedisConnectionService) LogLineHelper.attachSessionIdToLogs(uk.gov.di.authentication.shared.helpers.LogLineHelper.attachSessionIdToLogs) ApiGatewayResponseHelper.generateApiGatewayProxyErrorResponse(uk.gov.di.authentication.shared.helpers.ApiGatewayResponseHelper.generateApiGatewayProxyErrorResponse) CloudwatchMetricsService(uk.gov.di.authentication.shared.services.CloudwatchMetricsService) Optional(java.util.Optional) LogManager(org.apache.logging.log4j.LogManager) UserContext(uk.gov.di.authentication.shared.state.UserContext) NotificationType(uk.gov.di.authentication.shared.entity.NotificationType) ClientNotFoundException(uk.gov.di.authentication.shared.exceptions.ClientNotFoundException)

Aggregations

Context (com.amazonaws.services.lambda.runtime.Context)1 RequestHandler (com.amazonaws.services.lambda.runtime.RequestHandler)1 APIGatewayProxyRequestEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent)1 APIGatewayProxyResponseEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent)1 List (java.util.List)1 Map (java.util.Map)1 Map.entry (java.util.Map.entry)1 Optional (java.util.Optional)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 FrontendAuditableEvent (uk.gov.di.authentication.frontendapi.domain.FrontendAuditableEvent)1 VerifyCodeRequest (uk.gov.di.authentication.frontendapi.entity.VerifyCodeRequest)1 AuditableEvent (uk.gov.di.authentication.shared.domain.AuditableEvent)1 RequestHeaders (uk.gov.di.authentication.shared.domain.RequestHeaders)1 ClientRegistry (uk.gov.di.authentication.shared.entity.ClientRegistry)1 CredentialTrustLevel (uk.gov.di.authentication.shared.entity.CredentialTrustLevel)1 ErrorResponse (uk.gov.di.authentication.shared.entity.ErrorResponse)1 NotificationType (uk.gov.di.authentication.shared.entity.NotificationType)1 MFA_SMS (uk.gov.di.authentication.shared.entity.NotificationType.MFA_SMS)1 VERIFY_EMAIL (uk.gov.di.authentication.shared.entity.NotificationType.VERIFY_EMAIL)1