use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class ApiKeysRoute method verify.
@Override
public void verify(final Context context) {
final AuthRequestDTO authenticationRequest = authRequestBodyHandler.getValidated(context);
final Optional<AppBO> app = apiKeysService.validateApiKey(authenticationRequest.getToken());
if (app.isPresent()) {
context.status(200).json(app.get());
} else {
context.status(404).json(new Error(ErrorCode.API_KEY_DOES_NOT_EXIST.getCode(), "API key does not exist"));
}
}
use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class JwtApiKeyProviderTest method generateTokenApp.
@Test
void generateTokenApp() {
final JtiProvider jtiProvider = Mockito.mock(JtiProvider.class);
final JwtApiKeyProvider tokenProvider = newProviderInstance(jtiProvider);
final String jti = "tokenId";
final AppBO app = RANDOM.nextObject(AppBO.class);
Mockito.when(jtiProvider.next()).thenReturn(jti);
final AuthResponseBO tokens = tokenProvider.generateToken(app);
assertThat(tokens).isNotNull();
assertThat(tokens.getToken()).isNotNull();
assertThat(tokens.getRefreshToken()).isNull();
verifyToken(tokens.getToken().toString(), app.getId(), jti);
}
use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class ActorDomainVerifier method verifyActorDomain.
public static boolean verifyActorDomain(final Context context, final String domain) {
if (context.attribute("actor") instanceof AppBO) {
final AppBO actor = context.attribute("actor");
final boolean isAuthClient = actor.getRoles().contains(AuthGuardRoles.AUTH_CLIENT);
if (isAuthClient && !actor.getDomain().equals(domain)) {
context.status(403).json(new Error("", "An auth client violated its restrictions in the request"));
return false;
}
return true;
}
return true;
}
use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class ApiKeysServiceImplTest method validateApiKey.
@Test
void validateApiKey() {
final String appId = "app";
final String key = "key";
final AppBO app = AppBO.builder().id(appId).build();
Mockito.when(apiKeyExchange.verifyAndGetAppId(key)).thenReturn(CompletableFuture.completedFuture(Optional.of(appId)));
Mockito.when(applicationsService.getById(appId)).thenReturn(Optional.of(app));
final Optional<AppBO> actual = apiKeysService.validateApiKey(key);
assertThat(actual).contains(app);
}
use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class ApplicationsServiceImplTest method deactivate.
@Test
void deactivate() {
final AppDO app = random.nextObject(AppDO.class);
app.setActive(true);
Mockito.when(applicationsRepository.getById(app.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(app)));
Mockito.when(applicationsRepository.update(any())).thenAnswer(invocation -> CompletableFuture.completedFuture(Optional.of(invocation.getArgument(0, AppDO.class))));
final AppBO updated = applicationsService.deactivate(app.getId()).orElse(null);
assertThat(updated).isNotNull();
assertThat(updated.isActive()).isFalse();
}
Aggregations