Jersey 2: Migrate request filters

The signature has changed for the method ContainerRequestFilter.filter(),
and the ResourceFilter interface along with the ResourceFilters annotation
no longer exist in Jersey 2.

A future commit will address the ResourceFilters annotation for filters
registration.

Reference: https://jakartaee.github.io/rest/apidocs/2.1.6/javax/ws/rs/container/ContainerRequestFilter.html#filter(javax.ws.rs.container.ContainerRequestContext)
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/APIVersionFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/APIVersionFilter.java
index db9536d..4039296 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/APIVersionFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/APIVersionFilter.java
@@ -9,10 +9,8 @@
 import org.springframework.stereotype.Component;
 
 import com.sun.jersey.api.NotFoundException;
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerRequestFilter;
-import com.sun.jersey.spi.container.ContainerResponseFilter;
-import com.sun.jersey.spi.container.ResourceFilter;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
 
@@ -25,23 +23,12 @@
 @Component
 @Provider
 public class APIVersionFilter
-        implements ContainerRequestFilter, ResourceFilter {
+        implements ContainerRequestFilter {
 
     @Autowired
     private KustvaktConfiguration config;
 
-    @Override
-    public ContainerRequestFilter getRequestFilter () {
-        return this;
-    }
-
-    @Override
-    public ContainerResponseFilter getResponseFilter () {
-        return null;
-    }
-
-    @Override
-    public ContainerRequest filter (ContainerRequest request) {
+    public void filter (ContainerRequestContext request) {
         List<PathSegment> pathSegments = request.getPathSegments();
         String version = pathSegments.get(0).getPath();
 
@@ -52,7 +39,6 @@
             // KustvaktException(StatusCodes.UNSUPPORTED_API_VERSION,
             // "API " + version + " is unsupported.", version));
         }
-        return request;
     }
 
 }
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/AdminFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/AdminFilter.java
index dd794b4..30cf182 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/AdminFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/AdminFilter.java
@@ -1,6 +1,7 @@
 package de.ids_mannheim.korap.web.filter;
 
 import javax.servlet.ServletContext;
+import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.ext.Provider;
@@ -8,10 +9,6 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerRequestFilter;
-import com.sun.jersey.spi.container.ContainerResponseFilter;
-
 import de.ids_mannheim.korap.dao.AdminDao;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.exceptions.StatusCodes;
@@ -34,8 +31,8 @@
     private KustvaktResponseHandler kustvaktResponseHandler;
 
     @Override
-    public ContainerRequest filter (ContainerRequest request) {
-        ContainerRequest superRequest = super.filter(request);
+    public void filter (ContainerRequestContext context) {
+        super.filter(context);
         String username = "guest";
         
         // legacy support for kustvakt core
@@ -45,34 +42,22 @@
             // adminToken = adminToken.substring(6);
             if (adminToken
                     .equals(servletContext.getInitParameter("adminToken"))) {
-                return superRequest;
+                return;
             }
         }
 
-        SecurityContext securityContext = superRequest.getSecurityContext();
+        SecurityContext securityContext = context.getSecurityContext();
         TokenContext tokenContext = (TokenContext) securityContext
                 .getUserPrincipal();
         
         if (tokenContext != null) {
             username = tokenContext.getUsername();
             if (adminDao.isAdmin(username)) {
-                return superRequest;
+                return;
             }
         }
         throw kustvaktResponseHandler.throwit(new KustvaktException(
                 StatusCodes.AUTHORIZATION_FAILED,
                 "Unauthorized operation for user: " + username, username));
     }
-
-
-    @Override
-    public ContainerRequestFilter getRequestFilter () {
-        return this;
-    }
-
-
-    @Override
-    public ContainerResponseFilter getResponseFilter () {
-        return null;
-    }
 }
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/AuthenticationFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/AuthenticationFilter.java
index 1f54669..74224b0 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/AuthenticationFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/AuthenticationFilter.java
@@ -4,11 +4,10 @@
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.glassfish.jersey.server.ContainerRequest;
 
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerRequestFilter;
-import com.sun.jersey.spi.container.ContainerResponseFilter;
-import com.sun.jersey.spi.container.ResourceFilter;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 
 import de.ids_mannheim.korap.authentication.AuthenticationManager;
 import de.ids_mannheim.korap.authentication.http.AuthorizationData;
@@ -33,7 +32,7 @@
 @Component
 @Provider
 public class AuthenticationFilter
-        implements ContainerRequestFilter, ResourceFilter {
+        implements ContainerRequestFilter {
 
     @Autowired
     private HttpAuthorizationHandler authorizationHandler;
@@ -45,7 +44,7 @@
     private KustvaktResponseHandler kustvaktResponseHandler;
 
     @Override
-    public ContainerRequest filter (ContainerRequest request) {
+    public void filter (ContainerRequestContext request) {
         String host = request.getHeaderValue(ContainerRequest.HOST);
         String ua = request.getHeaderValue(ContainerRequest.USER_AGENT);
 
@@ -97,11 +96,10 @@
                 throw kustvaktResponseHandler.throwit(e);
             }
         }
-        return request;
     }
 
 
-    private void checkContext (TokenContext context, ContainerRequest request)
+    private void checkContext (TokenContext context, ContainerRequestContext request)
             throws KustvaktException {
         if (context == null) {
             throw new KustvaktException(StatusCodes.AUTHENTICATION_FAILED,
@@ -121,16 +119,4 @@
                     "Access token is expired");
         }
     }
-
-
-    @Override
-    public ContainerRequestFilter getRequestFilter () {
-        return this;
-    }
-
-
-    @Override
-    public ContainerResponseFilter getResponseFilter () {
-        return null;
-    }
 }
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/BlockingFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/BlockingFilter.java
index 8375b62..2704057 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/BlockingFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/BlockingFilter.java
@@ -5,10 +5,8 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerRequestFilter;
-import com.sun.jersey.spi.container.ContainerResponseFilter;
-import com.sun.jersey.spi.container.ResourceFilter;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.exceptions.StatusCodes;
@@ -24,13 +22,13 @@
  */
 @Component
 @Provider
-public class BlockingFilter implements ContainerRequestFilter, ResourceFilter {
+public class BlockingFilter implements ContainerRequestFilter {
 
     @Autowired
     private KustvaktResponseHandler kustvaktResponseHandler;
 
     @Override
-    public ContainerRequest filter (ContainerRequest request) {
+    public void filter (ContainerRequestContext request) {
         TokenContext context;
 
         try {
@@ -46,20 +44,5 @@
                     StatusCodes.AUTHORIZATION_FAILED,
                     "Unauthorized operation for user: guest", "guest"));
         }
-
-
-        return request;
-    }
-
-
-    @Override
-    public ContainerRequestFilter getRequestFilter () {
-        return this;
-    }
-
-
-    @Override
-    public ContainerResponseFilter getResponseFilter () {
-        return null;
     }
 }
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoFilter.java
index b15f5e3..4bb33d6 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoFilter.java
@@ -1,12 +1,11 @@
 package de.ids_mannheim.korap.web.filter;
 
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.ext.Provider;
 
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerRequestFilter;
-import com.sun.jersey.spi.container.ContainerResponseFilter;
-import com.sun.jersey.spi.container.ResourceFilter;
+import org.glassfish.jersey.server.ContainerRequest;
 
 import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
 import de.ids_mannheim.korap.constant.TokenType;
@@ -19,10 +18,10 @@
  * @date 08/02/2016
  */
 @Provider
-public class DemoFilter implements ContainerRequestFilter, ResourceFilter {
+public class DemoFilter implements ContainerRequestFilter {
 
     @Override
-    public ContainerRequest filter (ContainerRequest request) {
+    public void filter (ContainerRequestContext request) {
         String authentication =
                 request.getHeaderValue(ContainerRequest.AUTHORIZATION);
         if (authentication == null || authentication.isEmpty()) {
@@ -33,7 +32,6 @@
                 request.setSecurityContext(createContext());
             }
         }
-        return request;
     }
 
 
@@ -52,16 +50,4 @@
         context.setUsername("demo");
         return new KustvaktContext(context);
     }
-
-
-    @Override
-    public ContainerRequestFilter getRequestFilter () {
-        return this;
-    }
-
-
-    @Override
-    public ContainerResponseFilter getResponseFilter () {
-        return null;
-    }
 }
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoUserFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoUserFilter.java
index e546c12..3d24717 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoUserFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoUserFilter.java
@@ -2,6 +2,8 @@
 
 import java.security.Principal;
 
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.Provider;
@@ -9,10 +11,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerRequestFilter;
-import com.sun.jersey.spi.container.ContainerResponseFilter;
-import com.sun.jersey.spi.container.ResourceFilter;
+import org.glassfish.jersey.server.ContainerRequest;
 
 import de.ids_mannheim.korap.config.KustvaktConfiguration;
 import de.ids_mannheim.korap.constant.TokenType;
@@ -26,7 +25,7 @@
  */
 @Provider
 @Component
-public class DemoUserFilter implements ContainerRequestFilter, ResourceFilter {
+public class DemoUserFilter implements ContainerRequestFilter {
 
     @Context
     UriInfo info;
@@ -35,7 +34,7 @@
 
 
     @Override
-    public ContainerRequest filter (ContainerRequest request) {
+    public void filter (ContainerRequestContext request) {
         String host = request.getHeaderValue(ContainerRequest.HOST);
         String ua = request.getHeaderValue(ContainerRequest.USER_AGENT);
         String authentication = request
@@ -53,9 +52,7 @@
             if (pr == null)
                 request.setSecurityContext(new KustvaktContext(
                         createShorterToken(host, ua)));
-
         }
-        return request;
     }
 
 
@@ -71,16 +68,4 @@
         c.setTokenType(TokenType.BASIC);
         return c;
     }
-
-
-    @Override
-    public ContainerRequestFilter getRequestFilter () {
-        return this;
-    }
-
-
-    @Override
-    public ContainerResponseFilter getResponseFilter () {
-        return null;
-    }
 }
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/NonDemoBlockingFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/NonDemoBlockingFilter.java
index 47cd086..b17f7a7 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/NonDemoBlockingFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/NonDemoBlockingFilter.java
@@ -5,10 +5,8 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerRequestFilter;
-import com.sun.jersey.spi.container.ContainerResponseFilter;
-import com.sun.jersey.spi.container.ResourceFilter;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.exceptions.StatusCodes;
@@ -27,13 +25,13 @@
 @Component
 @Provider
 public class NonDemoBlockingFilter
-        implements ContainerRequestFilter, ResourceFilter {
+        implements ContainerRequestFilter {
 
     @Autowired
     private KustvaktResponseHandler kustvaktResponseHandler;
 
     @Override
-    public ContainerRequest filter (ContainerRequest request) {
+    public void filter (ContainerRequestContext request) {
         TokenContext context;
         try {
             context = (TokenContext) request.getUserPrincipal();
@@ -48,18 +46,5 @@
                     new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
                             "Operation is not permitted for guest users"));
         }
-        return request;
-    }
-
-
-    @Override
-    public ContainerRequestFilter getRequestFilter () {
-        return this;
-    }
-
-
-    @Override
-    public ContainerResponseFilter getResponseFilter () {
-        return null;
     }
 }
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
index 939cc84..26d84a8 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
@@ -16,10 +16,8 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import com.sun.jersey.spi.container.ContainerRequest;
-import com.sun.jersey.spi.container.ContainerRequestFilter;
-import com.sun.jersey.spi.container.ContainerResponseFilter;
-import com.sun.jersey.spi.container.ResourceFilter;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 
 import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
@@ -43,7 +41,7 @@
  */
 @Component
 @Provider
-public class PiwikFilter implements ContainerRequestFilter, ResourceFilter {
+public class PiwikFilter implements ContainerRequestFilter {
 
     private WebTarget service;
     //    private static final String SERVICE = "http://localhost:8888";
@@ -68,7 +66,7 @@
     }
 
 
-    private void send (ContainerRequest request) {
+    private void send (ContainerRequestContext request) {
         Random random = new SecureRandom();
         Locale l = null;
         if (request.getAcceptableLanguages() != null)
@@ -118,7 +116,7 @@
 
 
     @Override
-    public ContainerRequest filter (ContainerRequest request) {
+    public void filter (ContainerRequestContext request) {
         if (ENABLED) {
             try {
                 TokenContext context = (TokenContext) request
@@ -137,18 +135,5 @@
             }
             send(request);
         }
-        return request;
-    }
-
-
-    @Override
-    public ContainerRequestFilter getRequestFilter () {
-        return this;
-    }
-
-
-    @Override
-    public ContainerResponseFilter getResponseFilter () {
-        return null;
     }
 }