use of net.codestory.http.filters.Filter in project datashare by ICIJ.
the class ServerMode method configure.
@Override
protected void configure() {
super.configure();
String authUsersProviderClassName = propertiesProvider.get("authUsersProvider").orElse("org.icij.datashare.session.UsersInRedis");
String batchQueueType = propertiesProvider.get("batchQueueType").orElse("org.icij.datashare.extract.MemoryBlockingQueue");
bind(TaskManager.class).toInstance(new TaskManagerRedis(propertiesProvider, getBlockingQueue(propertiesProvider, batchQueueType, "ds:batchdownload:queue")));
Class<? extends UsersWritable> authUsersProviderClass = UsersInRedis.class;
try {
authUsersProviderClass = (Class<? extends UsersWritable>) Class.forName(authUsersProviderClassName);
logger.info("setting auth users provider to {}", authUsersProviderClass);
} catch (ClassNotFoundException e) {
logger.warn("\"{}\" auth users provider class not found. Setting provider to {}", authUsersProviderClassName, authUsersProviderClass);
}
bind(UsersWritable.class).to(authUsersProviderClass);
bind(SessionIdStore.class).to(RedisSessionIdStore.class);
bind(ApiKeyStore.class).to(ApiKeyStoreAdapter.class);
String authFilterClassName = propertiesProvider.get("authFilter").orElse("");
Class<? extends Filter> authFilterClass = OAuth2CookieFilter.class;
if (!authFilterClassName.isEmpty()) {
try {
authFilterClass = (Class<? extends Filter>) Class.forName(authFilterClassName);
logger.info("setting auth filter to {}", authFilterClass);
} catch (ClassNotFoundException e) {
logger.warn("\"{}\" auth filter class not found. Setting filter to {}", authFilterClassName, authFilterClass);
}
}
bind(Filter.class).to(authFilterClass);
if (authFilterClass.equals(BasicAuthAdaptorFilter.class)) {
bind(ApiKeyFilter.class).toInstance(new ApiKeyFilter(null, apiKey -> null) {
@Override
public Payload apply(String uri, Context context, PayloadSupplier nextFilter) throws Exception {
return nextFilter.get();
}
});
}
bind(StatusResource.class).asEagerSingleton();
configurePersistence();
}
use of net.codestory.http.filters.Filter in project datashare by ICIJ.
the class UserTaskResourceTest method setupAppWith.
private void setupAppWith(String... userLogins) {
final PropertiesProvider propertiesProvider = new PropertiesProvider();
taskManager = new TaskManagerMemory(propertiesProvider);
configure(new CommonMode(new Properties()) {
@Override
protected void configure() {
bind(PropertiesProvider.class).toInstance(propertiesProvider);
bind(PipelineRegistry.class).toInstance(mock(PipelineRegistry.class));
bind(SessionIdStore.class).toInstance(SessionIdStore.inMemory());
bind(TaskManager.class).toInstance(taskManager);
bind(Filter.class).toInstance(new BasicAuthFilter("/", "ds", DatashareUser.users(userLogins)));
bind(TaskFactory.class).toInstance(mock(TaskFactory.class));
bind(Indexer.class).toInstance(mock(Indexer.class));
}
@Override
protected Routes addModeConfiguration(Routes routes) {
return routes.add(TaskResource.class).filter(Filter.class);
}
}.createWebConfiguration());
}
use of net.codestory.http.filters.Filter in project datashare by ICIJ.
the class TaskResourceTest method test_index_file_and_filter.
@Test
public void test_index_file_and_filter() {
RestAssert response = post("/api/task/batchUpdate/index/" + getClass().getResource("/docs/doc.txt").getPath().substring(1), "{\"options\":{\"filter\": true}}");
ShouldChain responseBody = response.should().haveType("application/json");
List<String> taskNames = taskManager.waitTasksToBeDone(1, SECONDS).stream().map(t -> t.name).collect(toList());
responseBody.should().contain(format("{\"name\":\"%s\"", taskNames.get(0)));
responseBody.should().contain(format("{\"name\":\"%s\"", taskNames.get(1)));
verify(taskFactory).createScanIndexTask(eq(local()), eq("extract:report"));
}
Aggregations