>From 8f8eb0959af7b99b76261eca5bcee682035beb01 Mon Sep 17 00:00:00 2001
From: Ade Lee <alee@redhat.com>
Date: Mon, 9 Sep 2013 11:49:21 -0400
Subject: [PATCH 153/154] Change interceptors to use jaxrs 2.0

RESTEasy 3.0.1 provides JAX-RS 2.0 interceptors.  We need to either use these
or the proprietary ones in order to compile.  These ones appear to be working just fine.

It does turn out that the change to getStringHeaders() is not yet implemented in 3.0.1
so we'll have to fix that.
---
 .../certsrv/client/PKIErrorInterceptor.java        |  2 +-
 .../netscape/cms/authorization/ACLInterceptor.java | 28 ++++++++--------------
 .../cms/authorization/AuthMethodInterceptor.java   | 27 ++++++++-------------
 3 files changed, 21 insertions(+), 36 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/client/PKIErrorInterceptor.java b/base/common/src/com/netscape/certsrv/client/PKIErrorInterceptor.java
index 7d29b9fd9d024f55166a4e68981b1c7a971de255..7d20bab8616a6c3c092a321c58d071e7c403fba0 100644
--- a/base/common/src/com/netscape/certsrv/client/PKIErrorInterceptor.java
+++ b/base/common/src/com/netscape/certsrv/client/PKIErrorInterceptor.java
@@ -34,7 +34,7 @@ public class PKIErrorInterceptor implements ClientErrorInterceptor {
         if (code < 400)
             return;
 
-        MultivaluedMap<String, String> headers = response.getHeaders();
+        MultivaluedMap<String, String> headers = response.getStringHeaders();
         String contentType = headers.getFirst("Content-Type");
 
         // handle XML content only
diff --git a/base/common/src/com/netscape/cms/authorization/ACLInterceptor.java b/base/common/src/com/netscape/cms/authorization/ACLInterceptor.java
index 1e7adf1906cccddbf2be30205c559ad97d283459..590f548f7dd959a4a796b036e590f889efc0952c 100644
--- a/base/common/src/com/netscape/cms/authorization/ACLInterceptor.java
+++ b/base/common/src/com/netscape/cms/authorization/ACLInterceptor.java
@@ -24,17 +24,14 @@ import java.security.Principal;
 import java.util.Properties;
 
 import javax.servlet.ServletContext;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.ext.Provider;
 
-import org.jboss.resteasy.annotations.interception.Precedence;
-import org.jboss.resteasy.annotations.interception.ServerInterceptor;
-import org.jboss.resteasy.core.ResourceMethod;
-import org.jboss.resteasy.core.ServerResponse;
+import org.jboss.resteasy.core.ResourceMethodInvoker;
 import org.jboss.resteasy.spi.Failure;
-import org.jboss.resteasy.spi.HttpRequest;
-import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
 
 import com.netscape.certsrv.acls.ACLMapping;
 import com.netscape.certsrv.apps.CMS;
@@ -51,9 +48,7 @@ import com.netscape.cmscore.realm.PKIPrincipal;
  * @author Endi S. Dewata
  */
 @Provider
-@ServerInterceptor
-@Precedence("SECURITY")
-public class ACLInterceptor implements PreProcessInterceptor {
+public class ACLInterceptor implements ContainerRequestFilter {
 
     Properties authProperties;
 
@@ -73,13 +68,10 @@ public class ACLInterceptor implements PreProcessInterceptor {
     }
 
     @Override
-    public ServerResponse preProcess(
-            HttpRequest request,
-            ResourceMethod resourceMethod
-        ) throws Failure, ForbiddenException {
+    public void filter(ContainerRequestContext requestContext) throws IOException {
+        ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) requestContext.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
+        Method method = methodInvoker.getMethod();
 
-        // Get ACL mapping for the method.
-        Method method = resourceMethod.getMethod();
         ACLMapping aclMapping = method.getAnnotation(ACLMapping.class);
 
         // If not available, get ACL mapping for the class.
@@ -91,7 +83,7 @@ public class ACLInterceptor implements PreProcessInterceptor {
         // If still not available, it's unprotected, allow request.
         if (aclMapping == null) {
             CMS.debug("ACLInterceptor: No ACL mapping.");
-            return null;
+            return;
         }
 
         Principal principal = securityContext.getUserPrincipal();
@@ -126,7 +118,7 @@ public class ACLInterceptor implements PreProcessInterceptor {
             // If no property defined, allow request.
             if (value == null) {
                 CMS.debug("ACLInterceptor: No ACL configuration.");
-                return null;
+                return;
             }
 
             String values[] = value.split(",");
@@ -161,6 +153,6 @@ public class ACLInterceptor implements PreProcessInterceptor {
         }
 
         // Allow request.
-        return null;
+        return;
     }
 }
diff --git a/base/common/src/com/netscape/cms/authorization/AuthMethodInterceptor.java b/base/common/src/com/netscape/cms/authorization/AuthMethodInterceptor.java
index c9e442769fcb5dbd599f419850e1fcb8861b7b1e..527b9f685a435c88ddac836bdf228f534e3b295d 100644
--- a/base/common/src/com/netscape/cms/authorization/AuthMethodInterceptor.java
+++ b/base/common/src/com/netscape/cms/authorization/AuthMethodInterceptor.java
@@ -26,17 +26,14 @@ import java.util.HashSet;
 import java.util.Properties;
 
 import javax.servlet.ServletContext;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.SecurityContext;
 import javax.ws.rs.ext.Provider;
 
-import org.jboss.resteasy.annotations.interception.Precedence;
-import org.jboss.resteasy.annotations.interception.ServerInterceptor;
-import org.jboss.resteasy.core.ResourceMethod;
-import org.jboss.resteasy.core.ServerResponse;
+import org.jboss.resteasy.core.ResourceMethodInvoker;
 import org.jboss.resteasy.spi.Failure;
-import org.jboss.resteasy.spi.HttpRequest;
-import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
 
 import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.authentication.AuthMethodMapping;
@@ -50,9 +47,7 @@ import com.netscape.cmscore.realm.PKIPrincipal;
  * @author Endi S. Dewata
  */
 @Provider
-@ServerInterceptor
-@Precedence("SECURITY")
-public class AuthMethodInterceptor implements PreProcessInterceptor {
+public class AuthMethodInterceptor implements ContainerRequestFilter {
 
     Properties authProperties;
 
@@ -83,13 +78,11 @@ public class AuthMethodInterceptor implements PreProcessInterceptor {
     }
 
     @Override
-    public ServerResponse preProcess(
-            HttpRequest request,
-            ResourceMethod resourceMethod
-        ) throws Failure, ForbiddenException {
+    public void filter(ContainerRequestContext requestContext) throws IOException {
+        ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) requestContext.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
+        Method method = methodInvoker.getMethod();
+        Class<?> clazz = methodInvoker.getResourceClass();
 
-        Class<?> clazz = resourceMethod.getResourceClass();
-        Method method = resourceMethod.getMethod();
         CMS.debug("AuthMethodInterceptor: "+clazz.getSimpleName()+"."+method.getName()+"()");
 
         // Get authentication mapping for the method.
@@ -130,7 +123,7 @@ public class AuthMethodInterceptor implements PreProcessInterceptor {
             if (principal == null) {
                 if (authMethods.isEmpty() || authMethods.contains("anonymous") || authMethods.contains("*")) {
                     CMS.debug("AuthMethodInterceptor: anonymous access allowed");
-                    return null;
+                    return;
                 }
                 CMS.debug("AuthMethodInterceptor: anonymous access not allowed");
                 throw new ForbiddenException("Anonymous access not allowed.");
@@ -161,7 +154,7 @@ public class AuthMethodInterceptor implements PreProcessInterceptor {
 
             if (authMethods.isEmpty() || authMethods.contains(authManager) || authMethods.contains("*")) {
                 CMS.debug("AuthMethodInterceptor: "+authManager+" allowed");
-                return null;
+                return;
             }
 
             throw new ForbiddenException("Authentication method not allowed.");
-- 
1.8.3.1

