Search in sources :

Example 16 with RequestContextBO

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

the class AuthenticationServiceImplTest method authenticateLockedAccount.

@Test
void authenticateLockedAccount() {
    final String username = "username";
    final String password = "password";
    final AuthRequestBO authRequest = AuthRequestBO.builder().identifier(username).password(password).build();
    final AuthResponseBO tokens = RANDOM.nextObject(AuthResponseBO.class);
    final RequestContextBO requestContext = RequestContextBO.builder().build();
    Mockito.when(exchangeService.exchange(authRequest, "basic", "accessToken", requestContext)).thenReturn(tokens);
    Mockito.when(accountLocksService.getActiveLocksByAccountId(tokens.getEntityId())).thenReturn(Collections.singleton(AccountLockBO.builder().build()));
    assertThatThrownBy(() -> authenticationService.authenticate(authRequest, requestContext)).isInstanceOf(ServiceAuthorizationException.class).hasFieldOrPropertyWithValue("errorCode", ErrorCode.ACCOUNT_IS_LOCKED.getCode());
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) ServiceAuthorizationException(com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException) AuthRequestBO(com.nexblocks.authguard.service.model.AuthRequestBO) Test(org.junit.jupiter.api.Test)

Example 17 with RequestContextBO

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

the class AuthenticationServiceImplTest method authenticate.

@Test
void authenticate() {
    final String username = "username";
    final String password = "password";
    final AuthRequestBO authRequest = AuthRequestBO.builder().identifier(username).password(password).build();
    final AuthResponseBO tokens = RANDOM.nextObject(AuthResponseBO.class);
    final RequestContextBO requestContext = RequestContextBO.builder().build();
    Mockito.when(exchangeService.exchange(authRequest, "basic", "accessToken", requestContext)).thenReturn(tokens);
    Mockito.when(accountLocksService.getActiveLocksByAccountId(tokens.getEntityId())).thenReturn(Collections.emptyList());
    final Optional<AuthResponseBO> result = authenticationService.authenticate(authRequest, requestContext);
    assertThat(result).isPresent().contains(tokens);
}
Also used : RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) AuthRequestBO(com.nexblocks.authguard.service.model.AuthRequestBO) Test(org.junit.jupiter.api.Test)

Aggregations

RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)17 Test (org.junit.jupiter.api.Test)9 AccountBO (com.nexblocks.authguard.service.model.AccountBO)6 AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)5 AuthRequestDTO (com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)4 CreateAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO)4 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)4 Error (com.nexblocks.authguard.api.dto.entities.Error)3 CreateCompleteAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountRequestDTO)3 CreateCompleteAccountResponseDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountResponseDTO)3 CreateCredentialsRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO)3 CredentialsBO (com.nexblocks.authguard.service.model.CredentialsBO)3 ValidatableResponse (io.restassured.response.ValidatableResponse)3 AuthResponseDTO (com.nexblocks.authguard.api.dto.entities.AuthResponseDTO)2 ApplicationsService (com.nexblocks.authguard.service.ApplicationsService)2 IdempotencyException (com.nexblocks.authguard.service.exceptions.IdempotencyException)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Claim (com.auth0.jwt.interfaces.Claim)1