use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.
the class ActionTokenServiceImplTest method verifyTokenExpired.
@Test
void verifyTokenExpired() {
final AccountTokenDO accountToken = AccountTokenDO.builder().expiresAt(OffsetDateTime.now().minusMinutes(1)).additionalInformation(ImmutableMap.of("action", "something")).build();
Mockito.when(accountTokensRepository.getByToken("action-token")).thenReturn(CompletableFuture.completedFuture(Optional.of(accountToken)));
final Try<ActionTokenBO> actual = actionTokenService.verifyToken("action-token", "something");
assertThat(actual.isFailure());
assertThat(((ServiceException) actual.getCause()).getErrorCode()).isEqualTo(ErrorCode.EXPIRED_TOKEN.getCode());
}
use of com.nexblocks.authguard.dal.model.AccountTokenDO in project AuthGuard by AuthGuard.
the class ActionTokenServiceImpl method verifyToken.
@Override
public Try<ActionTokenBO> verifyToken(final String token, final String action) {
final Optional<AccountTokenDO> persisted = accountTokensRepository.getByToken(token).join();
if (persisted.isEmpty()) {
return Try.failure(new ServiceException(ErrorCode.TOKEN_EXPIRED_OR_DOES_NOT_EXIST, "Token was not found"));
}
final OffsetDateTime now = OffsetDateTime.now();
if (persisted.get().getExpiresAt().isBefore(now)) {
return Try.failure(new ServiceException(ErrorCode.EXPIRED_TOKEN, "Token has expired"));
}
final String allowedAction = persisted.get().getAdditionalInformation().get("action");
if (allowedAction == null || !allowedAction.equals(action)) {
return Try.failure(new ServiceException(ErrorCode.INVALID_TOKEN, "Token was created for a different action"));
}
return Try.success(ActionTokenBO.builder().accountId(persisted.get().getAssociatedAccountId()).token(token).action(action).build());
}
use of com.nexblocks.authguard.dal.model.AccountTokenDO 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);
}
}
use of com.nexblocks.authguard.dal.model.AccountTokenDO 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);
}
}
use of com.nexblocks.authguard.dal.model.AccountTokenDO 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());
}
Aggregations