Search in sources :

Example 1 with SessionDO

use of com.nexblocks.authguard.dal.model.SessionDO in project AuthGuard by AuthGuard.

the class SessionsServiceImpl method create.

@Override
public SessionBO create(final SessionBO session) {
    final SessionDO sessionDO = serviceMapper.toDO(session);
    sessionDO.setId(ID.generate());
    sessionDO.setSessionToken(cryptographicRandom.base64Url(config.getRandomSize()));
    return sessionsRepository.save(sessionDO).thenApply(created -> {
        emb.publish(CHANNEL, Messages.created(created));
        return serviceMapper.toBO(created);
    }).join();
}
Also used : SessionsService(com.nexblocks.authguard.service.SessionsService) ServiceMapper(com.nexblocks.authguard.service.mappers.ServiceMapper) SessionsConfig(com.nexblocks.authguard.service.config.SessionsConfig) SessionsRepository(com.nexblocks.authguard.dal.cache.SessionsRepository) SessionDO(com.nexblocks.authguard.dal.model.SessionDO) MessageBus(com.nexblocks.authguard.emb.MessageBus) CryptographicRandom(com.nexblocks.authguard.service.random.CryptographicRandom) Inject(com.google.inject.Inject) Messages(com.nexblocks.authguard.emb.Messages) SessionBO(com.nexblocks.authguard.service.model.SessionBO) Optional(java.util.Optional) ConfigContext(com.nexblocks.authguard.config.ConfigContext) Named(com.google.inject.name.Named) ID(com.nexblocks.authguard.service.util.ID) SessionDO(com.nexblocks.authguard.dal.model.SessionDO)

Example 2 with SessionDO

use of com.nexblocks.authguard.dal.model.SessionDO in project AuthGuard by AuthGuard.

the class SessionsServiceImplTest method deleteByToken.

@Test
void deleteByToken() {
    final SessionDO sessionDO = SessionDO.builder().id("session-id").accountId("account").sessionToken("token").data(Collections.singletonMap("key", "value")).build();
    Mockito.when(repository.deleteByToken(sessionDO.getSessionToken())).thenReturn(CompletableFuture.completedFuture(Optional.of(sessionDO)));
    final SessionBO expected = serviceMapper.toBO(sessionDO);
    final Optional<SessionBO> actual = service.deleteByToken(sessionDO.getSessionToken());
    assertThat(actual).contains(expected);
}
Also used : SessionDO(com.nexblocks.authguard.dal.model.SessionDO) SessionBO(com.nexblocks.authguard.service.model.SessionBO) Test(org.junit.jupiter.api.Test)

Example 3 with SessionDO

use of com.nexblocks.authguard.dal.model.SessionDO in project AuthGuard by AuthGuard.

the class SessionsServiceImplTest method getByToken.

@Test
void getByToken() {
    final SessionDO sessionDO = SessionDO.builder().id("session-id").accountId("account").sessionToken("token").data(Collections.singletonMap("key", "value")).build();
    Mockito.when(repository.getByToken(sessionDO.getSessionToken())).thenReturn(CompletableFuture.completedFuture(Optional.of(sessionDO)));
    final SessionBO expected = serviceMapper.toBO(sessionDO);
    final Optional<SessionBO> actual = service.getByToken(sessionDO.getSessionToken());
    assertThat(actual).contains(expected);
}
Also used : SessionDO(com.nexblocks.authguard.dal.model.SessionDO) SessionBO(com.nexblocks.authguard.service.model.SessionBO) Test(org.junit.jupiter.api.Test)

Example 4 with SessionDO

use of com.nexblocks.authguard.dal.model.SessionDO in project AuthGuard by AuthGuard.

the class SessionsServiceImplTest method getById.

@Test
void getById() {
    final SessionDO sessionDO = SessionDO.builder().id("session-id").accountId("account").data(Collections.singletonMap("key", "value")).build();
    Mockito.when(repository.getById(sessionDO.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(sessionDO)));
    final SessionBO expected = serviceMapper.toBO(sessionDO);
    final Optional<SessionBO> actual = service.getById(sessionDO.getId());
    assertThat(actual).contains(expected);
}
Also used : SessionDO(com.nexblocks.authguard.dal.model.SessionDO) SessionBO(com.nexblocks.authguard.service.model.SessionBO) Test(org.junit.jupiter.api.Test)

Aggregations

SessionDO (com.nexblocks.authguard.dal.model.SessionDO)4 SessionBO (com.nexblocks.authguard.service.model.SessionBO)4 Test (org.junit.jupiter.api.Test)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 SessionsService (com.nexblocks.authguard.service.SessionsService)1 SessionsConfig (com.nexblocks.authguard.service.config.SessionsConfig)1 ServiceMapper (com.nexblocks.authguard.service.mappers.ServiceMapper)1 CryptographicRandom (com.nexblocks.authguard.service.random.CryptographicRandom)1 ID (com.nexblocks.authguard.service.util.ID)1 Optional (java.util.Optional)1