Search in sources :

Example 1 with ImmutableTextMessage

use of com.nexblocks.authguard.external.sms.ImmutableTextMessage in project AuthGuard by AuthGuard.

the class SmsPasswordlessSubscriber method sendEmail.

private void sendEmail(final AccountBO account, final AccountTokenDO accountToken) {
    if (account.getPhoneNumber() != null) {
        final ImmutableMap.Builder<String, String> parameters = ImmutableMap.builder();
        if (account.getFirstName() != null) {
            parameters.put("firstName", account.getFirstName());
        }
        if (account.getLastName() != null) {
            parameters.put("lastName", account.getLastName());
        }
        final ImmutableTextMessage sms = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(parameters.put("token", accountToken.getToken()).build()).build();
        smsProvider.send(sms);
    } else {
        LOG.error("A passwordless token was generated for an account without a phone number. Account: {}, token ID: {}", account.getId(), accountToken.getId());
    }
}
Also used : ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with ImmutableTextMessage

use of com.nexblocks.authguard.external.sms.ImmutableTextMessage in project AuthGuard by AuthGuard.

the class SmsOtpSubscriberTest method onValidMessage.

@Test
void onValidMessage() {
    final OneTimePasswordBO otp = OneTimePasswordBO.builder().password("password").build();
    final AccountBO account = AccountBO.builder().phoneNumber(PhoneNumberBO.builder().number("+178945632").build()).firstName("first").lastName("second").build();
    final OtpMessageBody messageBody = new OtpMessageBody(otp, account, true, false);
    final Message message = Messages.otpGenerated(messageBody);
    final ImmutableTextMessage expectedEmail = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(ImmutableMap.of("password", otp.getPassword(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
    otpSubscriber.onMessage(message);
    final ArgumentCaptor<ImmutableTextMessage> sentSmsCaptor = ArgumentCaptor.forClass(ImmutableTextMessage.class);
    Mockito.verify(smsProvider).send(sentSmsCaptor.capture());
    assertThat(sentSmsCaptor.getValue()).isEqualTo(expectedEmail);
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) OtpMessageBody(com.nexblocks.authguard.basic.otp.OtpMessageBody) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Message(com.nexblocks.authguard.emb.model.Message) OneTimePasswordBO(com.nexblocks.authguard.service.model.OneTimePasswordBO) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Test(org.junit.jupiter.api.Test)

Example 3 with ImmutableTextMessage

use of com.nexblocks.authguard.external.sms.ImmutableTextMessage in project AuthGuard by AuthGuard.

the class SmsPasswordlessSubscriberTest method onValidMessage.

@Test
void onValidMessage() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().phoneNumber(PhoneNumberBO.builder().number("+178945632").build()).firstName("first").lastName("second").build();
    final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
    final Message message = Messages.passwordlessGenerated(messageBody);
    final ImmutableTextMessage expectedSms = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(ImmutableMap.of("token", accountToken.getToken(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
    smsPasswordlessSubscriber.onMessage(message);
    final ArgumentCaptor<ImmutableTextMessage> sentSmsCaptor = ArgumentCaptor.forClass(ImmutableTextMessage.class);
    Mockito.verify(smsProvider).send(sentSmsCaptor.capture());
    assertThat(sentSmsCaptor.getValue()).isEqualTo(expectedSms);
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody) Test(org.junit.jupiter.api.Test)

Example 4 with ImmutableTextMessage

use of com.nexblocks.authguard.external.sms.ImmutableTextMessage in project AuthGuard by AuthGuard.

the class SmsOtpSubscriber method sendEmail.

private void sendEmail(final AccountBO account, final OneTimePasswordBO otp) {
    if (account.getPhoneNumber() != null) {
        final ImmutableMap.Builder<String, String> parameters = ImmutableMap.builder();
        if (account.getFirstName() != null) {
            parameters.put("firstName", account.getFirstName());
        }
        if (account.getLastName() != null) {
            parameters.put("lastName", account.getLastName());
        }
        final ImmutableTextMessage sms = ImmutableTextMessage.builder().to(account.getPhoneNumber().getNumber()).parameters(parameters.put("password", otp.getPassword()).build()).build();
        smsProvider.send(sms);
    } else {
        LOG.error("An email OTP was generated for an account without a phone number. Account: {}, password ID: {}", account.getId(), otp.getId());
    }
}
Also used : ImmutableTextMessage(com.nexblocks.authguard.external.sms.ImmutableTextMessage) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableTextMessage (com.nexblocks.authguard.external.sms.ImmutableTextMessage)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 Message (com.nexblocks.authguard.emb.model.Message)2 AccountBO (com.nexblocks.authguard.service.model.AccountBO)2 Test (org.junit.jupiter.api.Test)2 OtpMessageBody (com.nexblocks.authguard.basic.otp.OtpMessageBody)1 PasswordlessMessageBody (com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody)1 AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)1 OneTimePasswordBO (com.nexblocks.authguard.service.model.OneTimePasswordBO)1