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());
}
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);
}
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);
}
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();
}
Aggregations