Search in sources :

Example 26 with AuthResponseBO

use of com.nexblocks.authguard.service.model.AuthResponseBO 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 27 with AuthResponseBO

use of com.nexblocks.authguard.service.model.AuthResponseBO 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)

Example 28 with AuthResponseBO

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

the class ApiKeysServiceImpl method generateApiKey.

@Override
public ApiKeyBO generateApiKey(final AppBO app) {
    final AuthResponseBO token = apiKeyExchange.generateKey(app);
    final String generatedKey = (String) token.getToken();
    final ApiKeyBO persisted = create(ApiKeyBO.builder().appId(app.getId()).key(apiKeyHash.hash(generatedKey)).build());
    // we store the hashed version but we return back the clear version
    return persisted.withKey(generatedKey);
}
Also used : ApiKeyBO(com.nexblocks.authguard.service.model.ApiKeyBO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO)

Example 29 with AuthResponseBO

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

the class DefaultApiKeyExchangeTest method generateKey.

@Test
void generateKey() {
    final AppBO app = AppBO.builder().id("app").build();
    final AuthResponseBO expected = AuthResponseBO.builder().type("api_key").entityType(EntityType.APPLICATION).entityId(app.getId()).build();
    final AuthResponseBO actual = exchange.generateKey(app);
    assertThat(actual).isEqualToIgnoringGivenFields(expected, "token");
    assertThat(actual.getToken()).isNotNull();
}
Also used : AppBO(com.nexblocks.authguard.service.model.AppBO) AuthResponseBO(com.nexblocks.authguard.service.model.AuthResponseBO) Test(org.junit.jupiter.api.Test)

Aggregations

AuthResponseBO (com.nexblocks.authguard.service.model.AuthResponseBO)29 Test (org.junit.jupiter.api.Test)24 AccountBO (com.nexblocks.authguard.service.model.AccountBO)15 AuthRequestBO (com.nexblocks.authguard.service.model.AuthRequestBO)11 ServiceAuthorizationException (com.nexblocks.authguard.service.exceptions.ServiceAuthorizationException)10 AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)7 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)5 OtpConfig (com.nexblocks.authguard.basic.config.OtpConfig)4 OneTimePasswordDO (com.nexblocks.authguard.dal.model.OneTimePasswordDO)4 JwtConfig (com.nexblocks.authguard.service.config.JwtConfig)4 StrategyConfig (com.nexblocks.authguard.service.config.StrategyConfig)4 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)3 AuthRequestDTO (com.nexblocks.authguard.api.dto.requests.AuthRequestDTO)3 AppBO (com.nexblocks.authguard.service.model.AppBO)2 AuthResponseDTO (com.nexblocks.authguard.api.dto.entities.AuthResponseDTO)1 Error (com.nexblocks.authguard.api.dto.entities.Error)1 PasswordlessRequestDTO (com.nexblocks.authguard.api.dto.requests.PasswordlessRequestDTO)1 AccountTokensRepository (com.nexblocks.authguard.dal.cache.AccountTokensRepository)1 ServiceMapperImpl (com.nexblocks.authguard.service.mappers.ServiceMapperImpl)1 AccountLockBO (com.nexblocks.authguard.service.model.AccountLockBO)1