summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2013-09-09 11:49:21 -0400
committerAde Lee <alee@redhat.com>2013-09-17 20:11:42 -0400
commit8c437a7491b8e96451f677055ef89bed7b38af7d (patch)
tree93c57fbba0588335298a63f544526b7486752b80
parent4cc83279da87304638b73b9bcca0efe418b0aa07 (diff)
downloadpki-8c437a7491b8e96451f677055ef89bed7b38af7d.tar.gz
pki-8c437a7491b8e96451f677055ef89bed7b38af7d.tar.xz
pki-8c437a7491b8e96451f677055ef89bed7b38af7d.zip
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.
-rw-r--r--base/common/src/com/netscape/certsrv/client/PKIErrorInterceptor.java2
-rw-r--r--base/common/src/com/netscape/cms/authorization/ACLInterceptor.java28
-rw-r--r--base/common/src/com/netscape/cms/authorization/AuthMethodInterceptor.java27
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 7d29b9fd9..7d20bab86 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 1e7adf190..590f548f7 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 c9e442769..527b9f685 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.");