Search in sources :

Example 11 with SessionBO

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

the class SessionVerifierTest method verifyExpiredSession.

@Test
void verifyExpiredSession() {
    final SessionsService sessionsService = Mockito.mock(SessionsService.class);
    final SessionVerifier sessionVerifier = new SessionVerifier(sessionsService);
    final SessionBO session = SessionBO.builder().id("session-id").sessionToken("token").accountId("account-id").expiresAt(OffsetDateTime.now().minus(Duration.ofMinutes(20))).build();
    Mockito.when(sessionsService.getByToken(session.getSessionToken())).thenReturn(Optional.of(session));
    final Either<Exception, String> result = sessionVerifier.verifyAccountToken("session-id");
    assertThat(result.isLeft());
    assertThat(result.getLeft()).isInstanceOf(ServiceAuthorizationException.class);
}
Also used : SessionsService(com.nexblocks.authguard.service.SessionsService) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) SessionBO(com.nexblocks.authguard.service.model.SessionBO) Test(org.junit.jupiter.api.Test)

Example 12 with SessionBO

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

the class SessionVerifierTest method verify.

@Test
void verify() {
    final SessionsService sessionsService = Mockito.mock(SessionsService.class);
    final SessionVerifier sessionVerifier = new SessionVerifier(sessionsService);
    final SessionBO session = SessionBO.builder().id("session-id").sessionToken("token").accountId("account-id").expiresAt(OffsetDateTime.now().plus(Duration.ofMinutes(20))).build();
    Mockito.when(sessionsService.getByToken(session.getSessionToken())).thenReturn(Optional.of(session));
    final Either<Exception, String> accountId = sessionVerifier.verifyAccountToken(session.getSessionToken());
    assertThat(accountId.get()).isEqualTo(session.getAccountId());
}
Also used : SessionsService(com.nexblocks.authguard.service.SessionsService) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) SessionBO(com.nexblocks.authguard.service.model.SessionBO) Test(org.junit.jupiter.api.Test)

Aggregations

SessionBO (com.nexblocks.authguard.service.model.SessionBO)12 Test (org.junit.jupiter.api.Test)6 SessionDO (com.nexblocks.authguard.dal.model.SessionDO)4 TokensResponse (com.nexblocks.authguard.jwt.oauth.TokensResponse)3 SessionsService (com.nexblocks.authguard.service.SessionsService)3 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)3 Inject (com.google.inject.Inject)1 Named (com.google.inject.name.Named)1 ConfigContext (com.nexblocks.authguard.config.ConfigContext)1 SessionsRepository (com.nexblocks.authguard.dal.cache.SessionsRepository)1 MessageBus (com.nexblocks.authguard.emb.MessageBus)1 Messages (com.nexblocks.authguard.emb.Messages)1 SessionsConfig (com.nexblocks.authguard.service.config.SessionsConfig)1 ServiceMapper (com.nexblocks.authguard.service.mappers.ServiceMapper)1 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)1 CryptographicRandom (com.nexblocks.authguard.service.random.CryptographicRandom)1 ID (com.nexblocks.authguard.service.util.ID)1 Optional (java.util.Optional)1