Search in sources :

Example 51 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.

the class ActionTokenServiceImplTest method generateFromBasicAuth.

@Test
void generateFromBasicAuth() {
    final AuthRequestBO authRequest = AuthRequestBO.builder().identifier("username").password("password").build();
    final AccountBO account = AccountBO.builder().id("account").build();
    Mockito.when(basicAuthProvider.getAccount(authRequest)).thenReturn(Either.right(account));
    Mockito.when(accountTokensRepository.save(Mockito.any())).thenReturn(CompletableFuture.completedFuture(null));
    final Try<ActionTokenBO> actual = actionTokenService.generateFromBasicAuth(authRequest, "something");
    final ActionTokenBO expected = ActionTokenBO.builder().accountId(account.getId()).validFor(Duration.ofMinutes(5).toSeconds()).build();
    assertThat(actual.isSuccess());
    assertThat(actual.get()).isEqualToIgnoringGivenFields(expected, "token");
    assertThat(actual.get().getToken()).isNotNull();
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) AuthRequestBO(com.nexblocks.authguard.service.model.AuthRequestBO) ActionTokenBO(com.nexblocks.authguard.service.model.ActionTokenBO) Test(org.junit.jupiter.api.Test)

Example 52 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.

the class SmsPasswordlessSubscriber method onMessage.

@Override
public void onMessage(final Message message) {
    if (message.getEventType() == EventType.PASSWORDLESS_GENERATED) {
        final PasswordlessMessageBody messageBody = (PasswordlessMessageBody) message.getMessageBody();
        final AccountBO account = messageBody.getAccount();
        final AccountTokenDO accountToken = messageBody.getAccountToken();
        sendEmail(account, accountToken);
    }
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody)

Example 53 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.

the class EmailPasswordlessSubscriber method onMessage.

@Override
public void onMessage(final Message message) {
    if (message.getEventType() == EventType.PASSWORDLESS_GENERATED) {
        final PasswordlessMessageBody messageBody = (PasswordlessMessageBody) message.getMessageBody();
        final AccountBO account = messageBody.getAccount();
        final AccountTokenDO accountToken = messageBody.getAccountToken();
        sendEmail(account, accountToken);
    }
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody)

Example 54 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO 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)

Example 55 with AccountBO

use of com.nexblocks.authguard.service.model.AccountBO in project AuthGuard by AuthGuard.

the class EmailResetTokenSubscriberTest 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 ResetTokenMessage messageBody = new ResetTokenMessage(account, accountToken);
    final Message message = Messages.passwordlessGenerated(messageBody).withEventType(EventType.ADMIN);
    emailResetTokenSubscriber.onMessage(message);
    Mockito.verify(emailProvider, Mockito.never()).send(Mockito.any());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) ResetTokenMessage(com.nexblocks.authguard.service.messaging.ResetTokenMessage) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ResetTokenMessage(com.nexblocks.authguard.service.messaging.ResetTokenMessage) Test(org.junit.jupiter.api.Test)

Aggregations

AccountBO (com.nexblocks.authguard.service.model.AccountBO)55 Test (org.junit.jupiter.api.Test)43 AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)21 Message (com.nexblocks.authguard.emb.model.Message)15 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)15 OtpMessageBody (com.nexblocks.authguard.basic.otp.OtpMessageBody)8 PasswordlessMessageBody (com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody)8 OneTimePasswordBO (com.nexblocks.authguard.service.model.OneTimePasswordBO)8 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)7 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)6 ImmutableTextMessage (com.nexblocks.authguard.external.sms.ImmutableTextMessage)6 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)6 ImmutableEmail (com.nexblocks.authguard.external.email.ImmutableEmail)5 JwtConfig (com.nexblocks.authguard.service.config.JwtConfig)5 StrategyConfig (com.nexblocks.authguard.service.config.StrategyConfig)5 ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)5 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)5 CreateAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO)4 OtpConfig (com.nexblocks.authguard.basic.config.OtpConfig)4 CreateCompleteAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountRequestDTO)3