use of com.nexblocks.authguard.service.messaging.AuthMessage in project AuthGuard by AuthGuard.
the class AccountLockerTest method onMessageAuthNotAccount.
@Test
void onMessageAuthNotAccount() {
// data
final AuthMessage authMessage = AuthMessage.success("basic", "session", EntityType.APPLICATION, "account");
final Message<Object> message = Message.builder().eventType(EventType.AUTHENTICATION).bodyType(AuthMessage.class).messageBody(authMessage).timestamp(OffsetDateTime.now()).build();
// call
accountLocker.onMessage(message);
// verify
Mockito.verifyZeroInteractions(exchangeAttemptsRepository, accountLocksService);
}
use of com.nexblocks.authguard.service.messaging.AuthMessage in project AuthGuard by AuthGuard.
the class AccountLockerTest method onMessageNoLock.
@Test
void onMessageNoLock() {
// data
final AuthMessage authMessage = AuthMessage.success("basic", "session", EntityType.ACCOUNT, "account");
final Message<Object> message = Message.builder().eventType(EventType.AUTHENTICATION).bodyType(AuthMessage.class).messageBody(authMessage).timestamp(OffsetDateTime.now()).build();
// mocks
Mockito.when(exchangeAttemptsRepository.findByEntityAndTimestamp(Mockito.any(), Mockito.any())).thenReturn(CompletableFuture.completedFuture(Collections.emptyList()));
// call
accountLocker.onMessage(message);
// verify
final ArgumentCaptor<OffsetDateTime> timeArgumentCaptor = ArgumentCaptor.forClass(OffsetDateTime.class);
Mockito.verify(exchangeAttemptsRepository).findByEntityAndTimestamp(Mockito.eq("account"), timeArgumentCaptor.capture());
assertThat(timeArgumentCaptor.getValue()).isBetween(OffsetDateTime.now().minusMinutes(config.getCheckPeriod()).minusMinutes(1), OffsetDateTime.now().minusMinutes(config.getCheckPeriod()).plusMinutes(1));
Mockito.verifyZeroInteractions(accountLocksService);
}
use of com.nexblocks.authguard.service.messaging.AuthMessage in project AuthGuard by AuthGuard.
the class ExchangeServiceImpl method exchangeFailure.
private void exchangeFailure(final AuthRequestBO authRequest, final RequestContextBO requestContext, final Exception e, final String fromTokenType, final String toTokenType) {
if (ServiceAuthorizationException.class.isAssignableFrom(e.getClass())) {
final ServiceAuthorizationException sae = (ServiceAuthorizationException) e;
final AuthMessage authMessage = AuthMessage.failure(fromTokenType, toTokenType, sae.getEntityType(), sae.getEntityId(), sae);
if (sae.getEntityType() == EntityType.ACCOUNT) {
final ExchangeAttemptBO attempt = createBaseAttempt(authRequest, requestContext).exchangeFrom(fromTokenType).exchangeTo(toTokenType).successful(false).entityId(sae.getEntityId()).build();
exchangeAttemptsService.create(attempt);
}
emb.publish(CHANNEL, Messages.auth(authMessage));
} else {
final AuthMessage authMessage = AuthMessage.failure(fromTokenType, toTokenType, e);
emb.publish(CHANNEL, Messages.auth(authMessage));
}
}
Aggregations