Unified ResourceFilters and SearchResourceFilters.

Deprecated SearchResourceFilters.

Change-Id: Ic1015779231a8c056395d518c08f4a53c60daec2
diff --git a/Changes b/Changes
index 6910751..af50e78 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 # version 0.73.3-SNAPSHOT
 
+- Unified ResourceFilters and SearchResourceFilters.
 - Remove corpusQuery param in the statistics web-service (close #758).
 - Moved NamedVCLoader to the init package.
 - Clean up Spring XML configs.
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index d69f3c6..9fa7e85 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -74,6 +74,10 @@
     private int validationStringLength;
     @Deprecated
     private int validationEmaillength;
+    
+    // EM: determine if search and match info services restricted 
+    // to logged in users. This replaces @SearchResourceFilters
+    private boolean isLoginRequired;
 
     private byte[] sharedSecret;
     private int longTokenTTL;
@@ -191,6 +195,9 @@
                 .getProperty("default.foundry.structure", "base");
 
         // security configuration
+        isLoginRequired = Boolean
+                .valueOf(properties.getProperty("login.required", "false"));
+
         inactiveTime = TimeUtils.convertTimeToSeconds(
                 properties.getProperty("security.idleTimeoutDuration", "10M"));
         allowMultiLogIn = Boolean
diff --git a/src/main/java/de/ids_mannheim/korap/core/web/controller/SearchController.java b/src/main/java/de/ids_mannheim/korap/core/web/controller/SearchController.java
index 1a8a09a..82e068e 100644
--- a/src/main/java/de/ids_mannheim/korap/core/web/controller/SearchController.java
+++ b/src/main/java/de/ids_mannheim/korap/core/web/controller/SearchController.java
@@ -28,7 +28,6 @@
 import de.ids_mannheim.korap.web.filter.AuthenticationFilter;
 import de.ids_mannheim.korap.web.filter.DemoUserFilter;
 import de.ids_mannheim.korap.web.utils.ResourceFilters;
-import de.ids_mannheim.korap.web.utils.SearchResourceFilters;
 import jakarta.servlet.ServletContext;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.ws.rs.DefaultValue;
@@ -150,7 +149,7 @@
     @POST
     @Path("{version}/search")
     @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
-    @SearchResourceFilters
+    //@SearchResourceFilters
     public Response searchPost (@Context SecurityContext context,
             @Context Locale locale, @Context HttpHeaders headers,
             String jsonld) {
@@ -210,7 +209,7 @@
     @GET
     @Path("{version}/search")
     @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
-    @SearchResourceFilters
+    //@SearchResourceFilters
     public Response searchGet (@Context SecurityContext securityContext,
             @Context HttpServletRequest request, @Context HttpHeaders headers,
             @Context Locale locale, @QueryParam("q") String q,
@@ -246,12 +245,13 @@
         return Response.ok(result).build();
     }
 
+    // EM: unified resource filter and search resource filters
     // EM: legacy support
     @Deprecated
     @GET
     @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
     @Path("{version}/corpus/{corpusId}/{docId}/{textId}/{matchId}/matchInfo")
-    @SearchResourceFilters
+    //@SearchResourceFilters
     public Response getMatchInfo (@Context SecurityContext ctx,
             @Context HttpHeaders headers, @Context Locale locale,
             @PathParam("corpusId") String corpusId,
@@ -310,7 +310,7 @@
     @GET
     @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
     @Path("{version}/corpus/{corpusId}/{docId}/{textId}/{matchId}")
-    @SearchResourceFilters
+    //@SearchResourceFilters
     public Response retrieveMatchInfo (@Context SecurityContext ctx,
             @Context HttpHeaders headers, @Context Locale locale,
             @PathParam("corpusId") String corpusId,
diff --git a/src/main/java/de/ids_mannheim/korap/web/utils/ResourceFiltersFeature.java b/src/main/java/de/ids_mannheim/korap/web/utils/ResourceFiltersFeature.java
index 9e4a0ce..0485104 100644
--- a/src/main/java/de/ids_mannheim/korap/web/utils/ResourceFiltersFeature.java
+++ b/src/main/java/de/ids_mannheim/korap/web/utils/ResourceFiltersFeature.java
@@ -1,5 +1,13 @@
 package de.ids_mannheim.korap.web.utils;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.web.filter.DemoUserFilter;
 import jakarta.ws.rs.container.DynamicFeature;
 import jakarta.ws.rs.container.ResourceInfo;
 import jakarta.ws.rs.core.FeatureContext;
@@ -14,6 +22,9 @@
 @Provider
 public class ResourceFiltersFeature implements DynamicFeature {
 
+    @Autowired
+    public KustvaktConfiguration config;
+    
     @Override
     public void configure (ResourceInfo resourceInfo, FeatureContext context) {
         ResourceFilters filtersAnnotation = resourceInfo.getResourceMethod()
@@ -21,10 +32,16 @@
         if (filtersAnnotation == null)
             filtersAnnotation = resourceInfo.getResourceClass()
                     .getAnnotation(ResourceFilters.class);
-
+        
         if (filtersAnnotation != null) {
-            for (Class<?> filter : filtersAnnotation.value())
+            Class<?>[] filterArray = filtersAnnotation.value();
+            List<Class<?>> filterList = new ArrayList<>(Arrays.asList(filterArray));
+            if (config.isLoginRequired()) {
+                filterList.remove(DemoUserFilter.class);
+            }
+            for (Class<?> filter : filterList) {
                 context.register(filter);
+            }
         }
     }
 }
diff --git a/src/main/java/de/ids_mannheim/korap/web/utils/SearchResourceFilters.java b/src/main/java/de/ids_mannheim/korap/web/utils/SearchResourceFilters.java
index 60b226a..249793b 100644
--- a/src/main/java/de/ids_mannheim/korap/web/utils/SearchResourceFilters.java
+++ b/src/main/java/de/ids_mannheim/korap/web/utils/SearchResourceFilters.java
@@ -21,6 +21,7 @@
  * overrides
  * the class value.
  */
+@Deprecated
 @Target({ ElementType.TYPE, ElementType.METHOD })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface SearchResourceFilters {}
diff --git a/src/main/java/de/ids_mannheim/korap/web/utils/SearchResourceFiltersFeature.java b/src/main/java/de/ids_mannheim/korap/web/utils/SearchResourceFiltersFeature.java
index 6063aa0..341817e 100644
--- a/src/main/java/de/ids_mannheim/korap/web/utils/SearchResourceFiltersFeature.java
+++ b/src/main/java/de/ids_mannheim/korap/web/utils/SearchResourceFiltersFeature.java
@@ -8,8 +8,6 @@
 import org.springframework.stereotype.Component;
 
 import de.ids_mannheim.korap.web.filter.APIVersionFilter;
-import jakarta.annotation.PostConstruct;
-import jakarta.annotation.Priority;
 import jakarta.ws.rs.container.DynamicFeature;
 import jakarta.ws.rs.container.ResourceInfo;
 import jakarta.ws.rs.core.FeatureContext;
@@ -21,6 +19,7 @@
  * classes for a resource method annotated with
  * {@link ResourceFilters}.
  */
+@Deprecated
 @Provider
 @Component
 public class SearchResourceFiltersFeature implements DynamicFeature {
diff --git a/src/main/resources/kustvakt.conf b/src/main/resources/kustvakt.conf
index 1072e63..a45eb41 100644
--- a/src/main/resources/kustvakt.conf
+++ b/src/main/resources/kustvakt.conf
@@ -52,17 +52,6 @@
 availability.regex.public = ACA.*|QAO-NC
 availability.regex.all = QAO.*
 
-
-# Define resource filters for search and match info API
-# AuthenticationFilter activates authentication using OAuth2 tokens
-# DemoUserFilter allows access to API without login
-# 
-# Default values: AuthenticationFilter,DemoUserFilter
-#
-search.resource.filters=AuthenticationFilter,DemoUserFilter
-
-
-
 # options referring to the security module!
 
 # OAuth 
diff --git a/src/test/resources/kustvakt-dnb.conf b/src/test/resources/kustvakt-dnb.conf
index b23d474..c6dbdf1 100644
--- a/src/test/resources/kustvakt-dnb.conf
+++ b/src/test/resources/kustvakt-dnb.conf
@@ -68,15 +68,6 @@
 availability.regex.all = QAO.*
 
 
-# Define resource filters for search and match info API
-# AuthenticationFilter activates authentication using OAuth2 tokens
-# DemoUserFilter allows access to API without login
-# 
-# Default values: AuthenticationFilter,DemoUserFilter
-#
-search.resource.filters=AuthenticationFilter,DemoUserFilter
-
-
 # options referring to the security module!
 
 # OAuth
diff --git a/src/test/resources/kustvakt-icc.conf b/src/test/resources/kustvakt-icc.conf
index a87e3f0..965eb4c 100644
--- a/src/test/resources/kustvakt-icc.conf
+++ b/src/test/resources/kustvakt-icc.conf
@@ -60,7 +60,8 @@
 # 
 # Default values: AuthenticationFilter,DemoUserFilter
 #
-search.resource.filters=AuthenticationFilter
+#search.resource.filters=AuthenticationFilter
+login.required = true
 
 
 # options referring to the security module!
diff --git a/src/test/resources/kustvakt-test.conf b/src/test/resources/kustvakt-test.conf
index b9c8f74..eb94008 100644
--- a/src/test/resources/kustvakt-test.conf
+++ b/src/test/resources/kustvakt-test.conf
@@ -66,15 +66,6 @@
 availability.regex.all = QAO.*
 
 
-# Define resource filters for search and match info API
-# AuthenticationFilter activates authentication using OAuth2 tokens
-# DemoUserFilter allows access to API without login
-# 
-# Default values: AuthenticationFilter,DemoUserFilter
-#
-search.resource.filters=AuthenticationFilter,DemoUserFilter
-
-
 # options referring to the security module!
 
 # OAuth