Search in sources :

Example 11 with Message

use of com.nexblocks.authguard.emb.model.Message in project AuthGuard by AuthGuard.

the class SmsPasswordlessSubscriberTest method onWrongMessageType.

@Test
void onWrongMessageType() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().phoneNumber(PhoneNumberBO.builder().number("+178945632").build()).build();
    final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
    final Message message = Messages.passwordlessGenerated(messageBody).withEventType(EventType.ADMIN);
    smsPasswordlessSubscriber.onMessage(message);
    Mockito.verify(smsProvider, Mockito.never()).send(Mockito.any());
}
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) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody) Test(org.junit.jupiter.api.Test)

Example 12 with Message

use of com.nexblocks.authguard.emb.model.Message 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 13 with Message

use of com.nexblocks.authguard.emb.model.Message in project AuthGuard by AuthGuard.

the class SmsPasswordlessSubscriberTest method onValidMessageNoPhoneNumber.

@Test
void onValidMessageNoPhoneNumber() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().build();
    final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
    final Message message = Messages.passwordlessGenerated(messageBody);
    smsPasswordlessSubscriber.onMessage(message);
    Mockito.verify(smsProvider, Mockito.never()).send(Mockito.any());
}
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) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody) Test(org.junit.jupiter.api.Test)

Example 14 with Message

use of com.nexblocks.authguard.emb.model.Message in project AuthGuard by AuthGuard.

the class AccountLocker method processAuthMessage.

private void processAuthMessage(final AuthMessage authMessage) {
    if (authMessage.getEntityType() == EntityType.ACCOUNT) {
        final OffsetDateTime now = OffsetDateTime.now();
        final OffsetDateTime from = now.minusMinutes(config.getCheckPeriod());
        exchangeAttemptsRepository.findByEntityAndTimestamp(authMessage.getEntityId(), from).thenAccept(attempts -> {
            final long failedCount = attempts.stream().filter(attempt -> !attempt.isSuccessful()).count();
            if (failedCount >= config.getMaxAttempts()) {
                LOG.info("Account {} had {} failed attempts in the past {} minutes; a lock will be placed", authMessage.getEntityId(), attempts.size(), config.getCheckPeriod());
                final AccountLockBO lock = AccountLockBO.builder().accountId(authMessage.getEntityId()).expiresAt(now.plusMinutes(config.getLockPeriod())).build();
                accountLocksService.create(lock);
            }
        });
    } else {
        LOG.info("Skipping entity auth message for entity of type {}", authMessage.getEntityType());
    }
}
Also used : Logger(org.slf4j.Logger) EntityType(com.nexblocks.authguard.service.model.EntityType) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) EventType(com.nexblocks.authguard.emb.model.EventType) MessageSubscriber(com.nexblocks.authguard.emb.MessageSubscriber) OffsetDateTime(java.time.OffsetDateTime) AuthMessage(com.nexblocks.authguard.service.messaging.AuthMessage) Channel(com.nexblocks.authguard.emb.annotations.Channel) ExchangeAttemptsRepository(com.nexblocks.authguard.dal.persistence.ExchangeAttemptsRepository) Message(com.nexblocks.authguard.emb.model.Message) ConfigContext(com.nexblocks.authguard.config.ConfigContext) Named(com.google.inject.name.Named) ImmutableAccountLockerConfig(com.nexblocks.authguard.extensions.config.ImmutableAccountLockerConfig) AccountLocksService(com.nexblocks.authguard.service.AccountLocksService) AccountLockBO(com.nexblocks.authguard.service.model.AccountLockBO) AccountLockBO(com.nexblocks.authguard.service.model.AccountLockBO) OffsetDateTime(java.time.OffsetDateTime)

Example 15 with Message

use of com.nexblocks.authguard.emb.model.Message in project AuthGuard by AuthGuard.

the class EmailPasswordlessSubscriberTest method onWrongMessageType.

@Test
void onWrongMessageType() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().email(AccountEmailBO.builder().email("user@test.net").build()).build();
    final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
    final Message message = Messages.passwordlessGenerated(messageBody).withEventType(EventType.ADMIN);
    emailPasswordlessSubscriber.onMessage(message);
    Mockito.verify(emailProvider, Mockito.never()).send(Mockito.any());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody) Test(org.junit.jupiter.api.Test)

Aggregations

Message (com.nexblocks.authguard.emb.model.Message)16 AccountBO (com.nexblocks.authguard.service.model.AccountBO)15 Test (org.junit.jupiter.api.Test)15 AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)9 OtpMessageBody (com.nexblocks.authguard.basic.otp.OtpMessageBody)6 PasswordlessMessageBody (com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody)6 ImmutableTextMessage (com.nexblocks.authguard.external.sms.ImmutableTextMessage)6 OneTimePasswordBO (com.nexblocks.authguard.service.model.OneTimePasswordBO)6 ImmutableEmail (com.nexblocks.authguard.external.email.ImmutableEmail)3 ResetTokenMessage (com.nexblocks.authguard.service.messaging.ResetTokenMessage)3 Inject (com.google.inject.Inject)1 Named (com.google.inject.name.Named)1 ConfigContext (com.nexblocks.authguard.config.ConfigContext)1 ExchangeAttemptsRepository (com.nexblocks.authguard.dal.persistence.ExchangeAttemptsRepository)1 MessageSubscriber (com.nexblocks.authguard.emb.MessageSubscriber)1 Channel (com.nexblocks.authguard.emb.annotations.Channel)1 EventType (com.nexblocks.authguard.emb.model.EventType)1 ImmutableAccountLockerConfig (com.nexblocks.authguard.extensions.config.ImmutableAccountLockerConfig)1 AccountLocksService (com.nexblocks.authguard.service.AccountLocksService)1 AuthMessage (com.nexblocks.authguard.service.messaging.AuthMessage)1