use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class ApplicationsServiceImplTest method activate.
@Test
void activate() {
final AppDO app = random.nextObject(AppDO.class);
app.setActive(false);
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.activate(app.getId()).orElse(null);
assertThat(updated).isNotNull();
assertThat(updated.isActive()).isTrue();
}
use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class TestAccessManager method manage.
@Override
public void manage(@NotNull final Handler handler, @NotNull final Context context, @NotNull final Set<Role> set) throws Exception {
final AppBO app = AppBO.builder().addRoles("authguard_admin").build();
context.attribute("actor", app);
handler.handle(context);
}
use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class AuthorizationHandler method populateBearerActor.
private void populateBearerActor(final Context context, final String apiKey) {
final Optional<AppBO> actorApp = apiKeysService.validateApiKey(apiKey);
if (actorApp.isPresent()) {
LOG.info("Authenticated actor {} with bearer token", actorApp.get().getId());
context.attribute("actor", actorApp.get());
} else {
LOG.info("Failed to authenticate actor with bearer token");
context.status(401).json(new Error("401", "Failed to authenticate with bearer scheme"));
}
}
use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class ApiKeysServiceImplTest method generateApiKey.
@Test
void generateApiKey() {
final String appId = "app";
final String key = "key";
final AppBO app = AppBO.builder().id(appId).build();
Mockito.when(applicationsService.getById(appId)).thenReturn(Optional.of(app));
Mockito.when(apiKeysRepository.save(Mockito.any())).thenAnswer(invocation -> CompletableFuture.completedFuture(invocation.getArgument(0, ApiKeyDO.class)));
Mockito.when(apiKeyExchange.generateKey(app)).thenReturn(AuthResponseBO.builder().token(key).build());
final ApiKeyBO actual = apiKeysService.generateApiKey(appId);
assertThat(actual.getAppId()).isEqualTo(appId);
assertThat(actual.getKey()).isEqualTo(key);
// verify that we persisted the hashed key and not the clear key
final ArgumentCaptor<ApiKeyDO> argumentCaptor = ArgumentCaptor.forClass(ApiKeyDO.class);
Mockito.verify(apiKeysRepository).save(argumentCaptor.capture());
final ApiKeyDO persisted = argumentCaptor.getValue();
assertThat(persisted.getKey()).isEqualTo(apiKeyHash.hash(key));
}
use of com.nexblocks.authguard.service.model.AppBO in project AuthGuard by AuthGuard.
the class ApplicationsServiceImplTest method create.
@Test
void create() {
final AppBO app = random.nextObject(AppBO.class);
final String idempotentKey = "idempotent-key";
final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(idempotentKey).build();
Mockito.when(accountsService.getById(app.getParentAccountId())).thenReturn(Optional.of(random.nextObject(AccountBO.class)));
Mockito.when(applicationsRepository.save(any())).thenAnswer(invocation -> CompletableFuture.completedFuture(invocation.getArgument(0, AppDO.class)));
Mockito.when(idempotencyService.performOperation(Mockito.any(), Mockito.eq(idempotentKey), Mockito.eq(app.getEntityType()))).thenAnswer(invocation -> {
return CompletableFuture.completedFuture(invocation.getArgument(0, Supplier.class).get());
});
final AppBO created = applicationsService.create(app, requestContext);
final List<PermissionBO> expectedPermissions = app.getPermissions().stream().map(permission -> permission.withEntityType(null)).collect(Collectors.toList());
assertThat(created).isEqualToIgnoringGivenFields(app.withPermissions(expectedPermissions), "id", "createdAt", "lastModified", "entityType");
Mockito.verify(messageBus, Mockito.times(1)).publish(eq("apps"), any());
}
Aggregations