Search in sources :

Example 1 with Filter

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();
}
Also used : SessionIdStore(net.codestory.http.security.SessionIdStore) Routes(net.codestory.http.routes.Routes) Logger(org.slf4j.Logger) Properties(java.util.Properties) Context(net.codestory.http.Context) Payload(net.codestory.http.payload.Payload) LoggerFactory(org.slf4j.LoggerFactory) org.icij.datashare.web(org.icij.datashare.web) PayloadSupplier(net.codestory.http.filters.PayloadSupplier) TaskManager(org.icij.datashare.tasks.TaskManager) Map(java.util.Map) Filter(net.codestory.http.filters.Filter) TaskManagerRedis(org.icij.datashare.tasks.TaskManagerRedis) org.icij.datashare.session(org.icij.datashare.session) Context(net.codestory.http.Context) TaskManagerRedis(org.icij.datashare.tasks.TaskManagerRedis) TaskManager(org.icij.datashare.tasks.TaskManager) SessionIdStore(net.codestory.http.security.SessionIdStore) PayloadSupplier(net.codestory.http.filters.PayloadSupplier) Filter(net.codestory.http.filters.Filter) Payload(net.codestory.http.payload.Payload)

Example 2 with Filter

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());
}
Also used : BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter) CommonMode(org.icij.datashare.mode.CommonMode) Routes(net.codestory.http.routes.Routes) Properties(java.util.Properties) PipelineRegistry(org.icij.datashare.extension.PipelineRegistry) PropertiesProvider(org.icij.datashare.PropertiesProvider) SessionIdStore(net.codestory.http.security.SessionIdStore) Indexer(org.icij.datashare.text.indexing.Indexer) Filter(net.codestory.http.filters.Filter) BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter)

Example 3 with Filter

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"));
}
Also used : Routes(net.codestory.http.routes.Routes) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) CommonMode(org.icij.datashare.mode.CommonMode) NlpApp(org.icij.datashare.nlp.NlpApp) HashMap(java.util.HashMap) AbstractModels(org.icij.datashare.text.nlp.AbstractModels) RestAssert(net.codestory.rest.RestAssert) ArgumentCaptor(org.mockito.ArgumentCaptor) Collections.singleton(java.util.Collections.singleton) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) EmailPipeline(org.icij.datashare.nlp.EmailPipeline) Matchers.eq(org.mockito.Matchers.eq) Filter(net.codestory.http.filters.Filter) User(org.icij.datashare.user.User) Project.project(org.icij.datashare.text.Project.project) BatchDownload(org.icij.datashare.batch.BatchDownload) DatashareTimeRule(org.icij.datashare.test.DatashareTimeRule) Path(java.nio.file.Path) Pipeline(org.icij.datashare.text.nlp.Pipeline) org.icij.datashare.tasks(org.icij.datashare.tasks) Properties(java.util.Properties) PropertiesProvider(org.icij.datashare.PropertiesProvider) Indexer(org.icij.datashare.text.indexing.Indexer) String.format(java.lang.String.format) PipelineRegistry(org.icij.datashare.extension.PipelineRegistry) ShouldChain(net.codestory.rest.ShouldChain) Mockito(org.mockito.Mockito) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Paths(java.nio.file.Paths) LocalUserFilter(org.icij.datashare.session.LocalUserFilter) DatashareUser.local(org.icij.datashare.session.DatashareUser.local) org.junit(org.junit) NotNull(org.jetbrains.annotations.NotNull) MapAssert.entry(org.fest.assertions.MapAssert.entry) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ShouldChain(net.codestory.rest.ShouldChain) RestAssert(net.codestory.rest.RestAssert) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)

Aggregations

Properties (java.util.Properties)3 Filter (net.codestory.http.filters.Filter)3 Routes (net.codestory.http.routes.Routes)3 SessionIdStore (net.codestory.http.security.SessionIdStore)2 PropertiesProvider (org.icij.datashare.PropertiesProvider)2 PipelineRegistry (org.icij.datashare.extension.PipelineRegistry)2 CommonMode (org.icij.datashare.mode.CommonMode)2 Indexer (org.icij.datashare.text.indexing.Indexer)2 String.format (java.lang.String.format)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Collections.singleton (java.util.Collections.singleton)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 Collectors.toList (java.util.stream.Collectors.toList)1 Context (net.codestory.http.Context)1 PayloadSupplier (net.codestory.http.filters.PayloadSupplier)1 BasicAuthFilter (net.codestory.http.filters.basic.BasicAuthFilter)1