aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-08-08 10:28:36 -0500
committerJorge Hernandez <jh1730@att.com>2018-08-08 12:29:54 -0500
commit0d62e1d1e8d0a7744a62f437605a4197ec6e3285 (patch)
treeb007ff5332a71fdb1387cf5212dc178f6650038f /policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http
parent7ff19ee29e708be8c7fb3fc4428db0f399c0b4df (diff)
generic jetty filter and cadi support
Change-Id: I363e44e85e1d89c6254218629010d5c3e1507e0a Issue-ID: POLICY-1043 Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http')
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java32
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java12
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java17
3 files changed, 49 insertions, 12 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java
index c1d1a353..a2dd948a 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * policy-endpoints
+ * ONAP
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -23,30 +23,38 @@ package org.onap.policy.common.endpoints.http.server;
import org.onap.policy.common.capabilities.Startable;
/**
- * A Jetty Server to server REST Requests
+ * Http Servlet Server interface
*/
public interface HttpServletServer extends Startable {
/**
- * factory for managing and tracking DMAAP sources
+ * Factory of Http Servlet Servers
*/
- public static HttpServletServerFactory factory = new IndexedHttpServletServerFactory();
+ HttpServletServerFactory factory = new IndexedHttpServletServerFactory();
/**
*
* @return port
*/
- public int getPort();
+ int getPort();
/**
* enables basic authentication with user and password on the the relative path relativeUriPath
*
- * @param user
- * @param password
- * @param relativeUriPath
+ * @param user user
+ * @param password password
+ * @param relativeUriPath relative path
*/
- public void setBasicAuthentication(String user, String password, String relativeUriPath);
+ void setBasicAuthentication(String user, String password, String relativeUriPath);
+
+ /**
+ * adds a filter at the specified path
+ *
+ * @param filterPath filter path
+ * @param filterClass filter class
+ */
+ void addFilterClass(String filterPath, String filterClass);
/**
* adds a JAX-RS servlet class to serve REST requests
@@ -57,7 +65,7 @@ public interface HttpServletServer extends Startable {
* @throws IllegalArgumentException unable to process because of invalid input
* @throws IllegalStateException unable to process because of invalid state
*/
- public void addServletClass(String servletPath, String restClass);
+ void addServletClass(String servletPath, String restClass);
/**
* adds a package containing JAX-RS classes to serve REST requests
@@ -68,7 +76,7 @@ public interface HttpServletServer extends Startable {
* @throws IllegalArgumentException unable to process because of invalid input
* @throws IllegalStateException unable to process because of invalid state
*/
- public void addServletPackage(String servletPath, String restPackage);
+ void addServletPackage(String servletPath, String restPackage);
/**
* blocking start of the http server
@@ -79,5 +87,5 @@ public interface HttpServletServer extends Startable {
* @throws IllegalArgumentException if arguments are invalid
* @throws InterruptedException if the blocking operation is interrupted
*/
- public boolean waitedStart(long maxWaitTime) throws InterruptedException;
+ boolean waitedStart(long maxWaitTime) throws InterruptedException;
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java
index c7d2b1bf..4a430b20 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Properties;
+import org.onap.aaf.cadi.filter.CadiFilter;
import org.onap.policy.common.endpoints.http.server.internal.JettyJerseyServer;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.slf4j.Logger;
@@ -222,6 +223,13 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
https = Boolean.parseBoolean(httpsString);
}
+ String aafString = properties.getProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
+ + serviceName + PolicyEndPointProperties.PROPERTY_AAF_SUFFIX);
+ boolean aaf = false;
+ if (aafString != null && !aafString.isEmpty()) {
+ aaf = Boolean.parseBoolean(httpsString);
+ }
+
HttpServletServer service = build(serviceName, https, hostName, servicePort, contextUriPath, swagger, managed);
if (userName != null && !userName.isEmpty() && password != null && !password.isEmpty()) {
service.setBasicAuthentication(userName, password, authUriPath);
@@ -241,6 +249,10 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
}
}
+ if (aaf) {
+ service.addFilterClass(contextUriPath, CadiFilter.class.getCanonicalName());
+ }
+
serviceList.add(service);
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java
index a4cc9b5f..b22a9401 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java
@@ -22,6 +22,8 @@ package org.onap.policy.common.endpoints.http.server.internal;
import com.fasterxml.jackson.annotation.JsonIgnore;
+import java.util.EnumSet;
+import javax.servlet.DispatcherType;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.HashLoginService;
@@ -175,6 +177,21 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable
this(name, false, host, port, contextPath);
}
+ @Override
+ public void addFilterClass(String aFilterPath, String aFilterClass) {
+ if (aFilterClass == null || aFilterClass.isEmpty()) {
+ throw new IllegalArgumentException("No filter class provided");
+ }
+
+ String filterPath = aFilterPath;
+ if (aFilterPath == null || aFilterPath.isEmpty()) {
+ filterPath = "/*";
+ }
+
+ context.addFilter(aFilterClass, filterPath,
+ EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
+ }
+
public ServerConnector httpsConnector() {
SslContextFactory sslContextFactory = new SslContextFactory();