diff options
author | efiacor <fiachra.corcoran@est.tech> | 2022-12-07 10:56:27 +0000 |
---|---|---|
committer | efiacor <fiachra.corcoran@est.tech> | 2022-12-07 15:59:59 +0000 |
commit | bda6aeaa60607ab4fe5af508156019d7bd5c0ce4 (patch) | |
tree | 24bae3847c1139ba9aed95ce286277202aae9a93 /datarouter-prov/src | |
parent | b37d32a39c7096e39fc389f15d150e8c2b8c54c2 (diff) |
[DMAAP-DR] Remove AAF/TLS phase 1
Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Change-Id: Ifeae01dd8e7f0a737d8b74594a8061ae3d4ea647
Issue-ID: DMAAP-1642
Diffstat (limited to 'datarouter-prov/src')
56 files changed, 272 insertions, 843 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/Authorizer.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/Authorizer.java index fb62f192..48ad7bdd 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/Authorizer.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/Authorizer.java @@ -24,8 +24,8 @@ package org.onap.dmaap.datarouter.authz;
+import jakarta.servlet.http.HttpServletRequest;
import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
/**
* A Data Router API that requires authorization of incoming requests creates an instance of a class that implements
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java index 761df097..48e31bfe 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java @@ -26,7 +26,7 @@ package org.onap.dmaap.datarouter.authz.impl; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.util.Map; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.onap.dmaap.datarouter.authz.AuthorizationResponse; import org.onap.dmaap.datarouter.authz.Authorizer; import org.onap.dmaap.datarouter.authz.impl.AuthzResource.ResourceType; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java index 52629ffb..1942b148 100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java @@ -31,6 +31,10 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; import java.net.InetAddress; import java.net.UnknownHostException; import java.security.cert.X509Certificate; @@ -44,10 +48,6 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.UUID; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.Nullable; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java index eada4862..a0df71ce 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java @@ -31,8 +31,8 @@ import com.att.eelf.configuration.EELFManager; import java.io.IOException; import java.io.InvalidObjectException; import java.util.List; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.json.JSONObject; import org.onap.dmaap.datarouter.authz.AuthorizationResponse; import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java index de27c652..5182cc23 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java @@ -28,10 +28,11 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InvalidObjectException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.json.JSONException; import org.json.JSONObject; import org.onap.dmaap.datarouter.authz.AuthorizationResponse; @@ -53,8 +54,7 @@ import org.onap.dmaap.datarouter.provisioning.eelf.EelfMsgs; public class FeedServlet extends ProxyServlet { - //Adding EELF Logger Rally:US664892 - private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(FeedServlet.class); + private static final EELFLogger eelfLogger = EELFManager.getInstance().getLogger(FeedServlet.class); /** * Delete the Feed at the address /feed/<feednumber>. diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java index 432ea3c0..94303e96 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java @@ -26,10 +26,10 @@ package org.onap.dmaap.datarouter.provisioning; import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.sendResponseError; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InvalidObjectException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java index efa1c102..06959eef 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java @@ -39,8 +39,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.Properties; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.json.JSONArray; import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord; import org.onap.dmaap.datarouter.provisioning.beans.LogRecord; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java index 9cde4804..5f7ed337 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java @@ -28,6 +28,7 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import jakarta.servlet.ServletOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -38,9 +39,8 @@ import java.text.SimpleDateFormat; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import org.onap.dmaap.datarouter.provisioning.beans.DeliveryRecord;
import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord;
import org.onap.dmaap.datarouter.provisioning.beans.ExpiryRecord;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProvRunner.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProvRunner.java index 8a0ef448..747530ab 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProvRunner.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProvRunner.java @@ -73,12 +73,12 @@ import org.onap.dmaap.datarouter.provisioning.utils.SynchronizerTask; */ public class ProvRunner { - public static final EELFLogger intlogger = EELFManager.getInstance() - .getLogger("org.onap.dmaap.datarouter.provisioning.internal"); + public static final EELFLogger intlogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.internal"); private static Server provServer; private static AafPropsUtils aafPropsUtils; private static Properties provProperties; + private static Boolean tlsEnabled; /** * Starts the Data Router Provisioning server. @@ -91,14 +91,16 @@ public class ProvRunner { intlogger.error("Data Router Provisioning database init failure. Exiting."); exit(1); } - // Set up AAF properties - try { - aafPropsUtils = new AafPropsUtils(new File(getProvProperties().getProperty( - "org.onap.dmaap.datarouter.provserver.aafprops.path", - "/opt/app/osaaf/local/org.onap.dmaap-dr.props"))); - } catch (IOException e) { - intlogger.error("NODE0314 Failed to load AAF props. Exiting", e); - exit(1); + if (Boolean.TRUE.equals(getTlsEnabled())) { + // Set up AAF properties + try { + aafPropsUtils = new AafPropsUtils(new File(getProvProperties().getProperty( + "org.onap.dmaap.datarouter.provserver.aafprops.path", + "/opt/app/osaaf/local/org.onap.dmaap-dr.props"))); + } catch (IOException e) { + intlogger.error("NODE0314 Failed to load AAF props. Exiting", e); + exit(1); + } } // Daemon to clean up the log directory on a daily basis Timer rolex = new Timer(); @@ -138,11 +140,11 @@ public class ProvRunner { public static Properties getProvProperties() { if (provProperties == null) { - try { + try (FileInputStream props = new FileInputStream(getProperty( + "org.onap.dmaap.datarouter.provserver.properties", + "/opt/app/datartr/etc/provserver.properties"))) { provProperties = new Properties(); - provProperties.load(new FileInputStream(getProperty( - "org.onap.dmaap.datarouter.provserver.properties", - "/opt/app/datartr/etc/provserver.properties"))); + provProperties.load(props); } catch (IOException e) { intlogger.error("Failed to load PROV properties: " + e.getMessage(), e); exit(1); @@ -154,4 +156,12 @@ public class ProvRunner { public static AafPropsUtils getAafPropsUtils() { return aafPropsUtils; } + + public static Boolean getTlsEnabled() { + if (tlsEnabled == null) { + tlsEnabled = Boolean.parseBoolean(getProvProperties() + .getProperty("org.onap.dmaap.datarouter.provserver.tlsenabled", "true")); + } + return tlsEnabled; + } } diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProvServer.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProvServer.java index e1d4568f..9eb91178 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProvServer.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProvServer.java @@ -23,16 +23,13 @@ package org.onap.dmaap.datarouter.provisioning; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.security.Security; -import java.util.EnumSet; import java.util.Properties; -import javax.servlet.DispatcherType; -import javax.servlet.ServletException; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.CustomRequestLog; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; -import org.eclipse.jetty.server.NCSARequestLog; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.SslConnectionFactory; @@ -40,21 +37,17 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.RequestLogHandler; -import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.jetbrains.annotations.NotNull; import org.onap.dmaap.datarouter.provisioning.utils.AafPropsUtils; -import org.onap.dmaap.datarouter.provisioning.utils.DRProvCadiFilter; -import org.onap.dmaap.datarouter.provisioning.utils.ThrottleFilter; public class ProvServer { - public static final EELFLogger intlogger = EELFManager.getInstance() - .getLogger("InternalLog"); + public static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); private static Server server; @@ -69,9 +62,6 @@ public class ProvServer { } private static Server createProvServer(Properties provProps) { - final int httpsPort = Integer.parseInt( - provProps.getProperty("org.onap.dmaap.datarouter.provserver.https.port", "8443")); - Security.setProperty("networkaddress.cache.ttl", "4"); QueuedThreadPool queuedThreadPool = getQueuedThreadPool(); @@ -81,48 +71,52 @@ public class ProvServer { server.setDumpAfterStart(false); server.setDumpBeforeStop(false); - NCSARequestLog ncsaRequestLog = getRequestLog(provProps); - RequestLogHandler requestLogHandler = new RequestLogHandler(); - requestLogHandler.setRequestLog(ncsaRequestLog); - - server.setRequestLog(ncsaRequestLog); - - HttpConfiguration httpConfiguration = getHttpConfiguration(httpsPort); + HttpConfiguration httpConfiguration = getHttpConfiguration(); //HTTP Connector try (ServerConnector httpServerConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration))) { httpServerConnector.setPort(Integer.parseInt(provProps.getProperty( - "org.onap.dmaap.datarouter.provserver.http.port", "8080"))); + "org.onap.dmaap.datarouter.provserver.http.port", "80"))); httpServerConnector.setAcceptQueueSize(2); httpServerConnector.setIdleTimeout(30000); - SslContextFactory sslContextFactory = getSslContextFactory(provProps); - - // HTTPS configuration - HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration); - httpsConfiguration.setRequestHeaderSize(8192); - - // HTTPS connector - try (ServerConnector httpsServerConnector = new ServerConnector(server, - new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), - new HttpConnectionFactory(httpsConfiguration))) { - httpsServerConnector.setPort(httpsPort); - httpsServerConnector.setIdleTimeout(30000); - httpsServerConnector.setAcceptQueueSize(2); - - ServletContextHandler servletContextHandler = getServletContextHandler(provProps); - ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection(); - contextHandlerCollection.addHandler(servletContextHandler); - - // Server's Handler collection - HandlerCollection handlerCollection = new HandlerCollection(); - handlerCollection.setHandlers(new Handler[]{contextHandlerCollection, new DefaultHandler()}); - handlerCollection.addHandler(requestLogHandler); - - server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector}); - server.setHandler(handlerCollection); + ServletContextHandler servletContextHandler = getServletContextHandler(provProps); + ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection(); + contextHandlerCollection.addHandler(servletContextHandler); + + CustomRequestLog customRequestLog = getCustomRequestLog(provProps); + RequestLogHandler requestLogHandler = new RequestLogHandler(); + requestLogHandler.setRequestLog(customRequestLog); + + server.setRequestLog(customRequestLog); + + // Server's Handler collection + HandlerCollection handlerCollection = new HandlerCollection(); + handlerCollection.setHandlers(new Handler[]{contextHandlerCollection, new DefaultHandler()}); + handlerCollection.addHandler(requestLogHandler); + + if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) { + // HTTPS configuration + int httpsPort = Integer.parseInt( + provProps.getProperty("org.onap.dmaap.datarouter.provserver.https.port", "443")); + httpConfiguration.setSecureScheme("https"); + httpConfiguration.setSecurePort(httpsPort); + HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration); + httpsConfiguration.setRequestHeaderSize(8192); + // HTTPS connector + try (ServerConnector httpsServerConnector = new ServerConnector(server, + new SslConnectionFactory(getSslContextFactory(provProps), HttpVersion.HTTP_1_1.asString()), + new HttpConnectionFactory(httpsConfiguration))) { + httpsServerConnector.setPort(httpsPort); + httpsServerConnector.setIdleTimeout(30000); + httpsServerConnector.setAcceptQueueSize(2); + server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector}); + } + } else { + server.setConnectors(new Connector[]{httpServerConnector}); } + server.setHandler(handlerCollection); } return server; } @@ -138,7 +132,7 @@ public class ProvServer { } @NotNull - private static SslContextFactory getSslContextFactory(Properties provProps) { + private static SslContextFactory.Server getSslContextFactory(Properties provProps) { SslContextFactory sslContextFactory = new SslContextFactory.Server(); sslContextFactory.setKeyStoreType(AafPropsUtils.KEYSTORE_TYPE_PROPERTY); sslContextFactory.setKeyStorePath(ProvRunner.getAafPropsUtils().getKeystorePathProperty()); @@ -149,7 +143,6 @@ public class ProvServer { sslContextFactory.setTrustStorePath(ProvRunner.getAafPropsUtils().getTruststorePathProperty()); sslContextFactory.setTrustStorePassword(ProvRunner.getAafPropsUtils().getTruststorePassProperty()); - sslContextFactory.setWantClientAuth(true); sslContextFactory.setExcludeCipherSuites( "SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA", @@ -169,28 +162,20 @@ public class ProvServer { intlogger.info("Unsupported ciphers: " + String.join(",", sslContextFactory.getExcludeCipherSuites())); intlogger.info("Supported ciphers: " + String.join(",", sslContextFactory.getIncludeCipherSuites())); - return sslContextFactory; + return (SslContextFactory.Server) sslContextFactory; } @NotNull - private static NCSARequestLog getRequestLog(Properties provProps) { - NCSARequestLog ncsaRequestLog = new NCSARequestLog(); - ncsaRequestLog.setFilename(provProps.getProperty( - "org.onap.dmaap.datarouter.provserver.accesslog.dir") + "/request.log.yyyy_mm_dd"); - ncsaRequestLog.setFilenameDateFormat("yyyyMMdd"); - ncsaRequestLog.setRetainDays(90); - ncsaRequestLog.setAppend(true); - ncsaRequestLog.setExtended(false); - ncsaRequestLog.setLogCookies(false); - ncsaRequestLog.setLogTimeZone("GMT"); - return ncsaRequestLog; + private static CustomRequestLog getCustomRequestLog(Properties provProps) { + String filename = provProps.getProperty( + "org.onap.dmaap.datarouter.provserver.accesslog.dir") + "/request.log.yyyy_mm_dd"; + String format = "yyyyMMdd"; + return new CustomRequestLog(filename, format); } @NotNull - private static HttpConfiguration getHttpConfiguration(int httpsPort) { + private static HttpConfiguration getHttpConfiguration() { HttpConfiguration httpConfiguration = new HttpConfiguration(); - httpConfiguration.setSecureScheme("https"); - httpConfiguration.setSecurePort(httpsPort); httpConfiguration.setOutputBufferSize(32768); httpConfiguration.setRequestHeaderSize(8192); httpConfiguration.setResponseHeaderSize(8192); @@ -214,23 +199,6 @@ public class ProvServer { servletContextHandler.addServlet(new ServletHolder(new InternalServlet()), "/internal/*"); servletContextHandler.addServlet(new ServletHolder(new RouteServlet()), "/internal/route/*"); servletContextHandler.addServlet(new ServletHolder(new DRFeedsServlet()), "/"); - servletContextHandler.addFilter(new FilterHolder(new ThrottleFilter()), - "/publish/*", EnumSet.of(DispatcherType.REQUEST)); - setCadiFilter(servletContextHandler, provProps); return servletContextHandler; } - - private static void setCadiFilter(ServletContextHandler servletContextHandler, Properties provProps) { - if (Boolean.parseBoolean(provProps.getProperty( - "org.onap.dmaap.datarouter.provserver.cadi.enabled", "false"))) { - try { - servletContextHandler.addFilter(new FilterHolder(new DRProvCadiFilter( - true, ProvRunner.getAafPropsUtils().getPropAccess())), "/*", EnumSet.of(DispatcherType.REQUEST)); - intlogger.info("PROV0001 AAF CADI filter enabled"); - } catch (ServletException e) { - intlogger.error("PROV0001 Failed to add CADI filter to server"); - } - - } - } } diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java index 089ea755..49be5aa0 100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java @@ -26,6 +26,10 @@ package org.onap.dmaap.datarouter.provisioning; import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.sendResponseError; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -36,10 +40,6 @@ import java.security.KeyStore; import java.security.KeyStoreException; import java.util.Collections; import java.util.List; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; @@ -47,6 +47,7 @@ import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.BasicHttpEntity; @@ -79,22 +80,27 @@ public class ProxyServlet extends BaseServlet { public void init(ServletConfig config) throws ServletException { super.init(config); try { - // Set up keystore - String type = AafPropsUtils.KEYSTORE_TYPE_PROPERTY; - String store = ProvRunner.getAafPropsUtils().getKeystorePathProperty(); - String pass = ProvRunner.getAafPropsUtils().getKeystorePassProperty(); - KeyStore keyStore = readStore(store, pass, type); - // Set up truststore - store = ProvRunner.getAafPropsUtils().getTruststorePathProperty(); - pass = ProvRunner.getAafPropsUtils().getTruststorePassProperty(); - KeyStore trustStore = readStore(store, pass, AafPropsUtils.TRUESTSTORE_TYPE_PROPERTY); - - // We are connecting with the node name, but the certificate will have the CNAME - // So we need to accept a non-matching certificate name - SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore, + if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) { + // Set up keystore + String type = AafPropsUtils.KEYSTORE_TYPE_PROPERTY; + String store = ProvRunner.getAafPropsUtils().getKeystorePathProperty(); + String pass = ProvRunner.getAafPropsUtils().getKeystorePassProperty(); + KeyStore keyStore = readStore(store, pass, type); + // Set up truststore + store = ProvRunner.getAafPropsUtils().getTruststorePathProperty(); + pass = ProvRunner.getAafPropsUtils().getTruststorePassProperty(); + KeyStore trustStore = readStore(store, pass, AafPropsUtils.TRUESTSTORE_TYPE_PROPERTY); + + // We are connecting with the node name, but the certificate will have the CNAME + // So we need to accept a non-matching certificate name + SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore, ProvRunner.getAafPropsUtils().getKeystorePassProperty(), trustStore); - socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - sch = new Scheme("https", 443, socketFactory); + socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + sch = new Scheme("https", 443, socketFactory); + } else { + PlainSocketFactory socketFactory = new PlainSocketFactory(); + sch = new Scheme("http", 80, socketFactory); + } inited = true; } catch (Exception e) { intlogger.error("ProxyServlet.init: " + e.getMessage(), e); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java index 949019d1..db5470cc 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java @@ -27,14 +27,14 @@ package org.onap.dmaap.datarouter.provisioning; import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import jakarta.servlet.ServletConfig;
+import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@@ -159,8 +159,7 @@ public class PublishServlet extends BaseServlet { } else {
// Generate new URL
String nextnode = getRedirectNode(feedid, req);
- if (Boolean.parseBoolean(ProvRunner.getProvProperties()
- .getProperty("org.onap.dmaap.datarouter.provserver.tlsenabled", "true"))) {
+ if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) {
nextnode = nextnode + ":" + ProvRunner.getProvProperties().getProperty(
"org.onap.dmaap.datarouter.nodeserver.https.port", "8443");
} else {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java index 8506530b..e164ea8a 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java @@ -28,8 +28,8 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send import java.io.IOException;
import java.util.Set;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java index 1a07ffae..1c324e5a 100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java @@ -25,6 +25,7 @@ package org.onap.dmaap.datarouter.provisioning; import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.sendResponseError;
+import jakarta.servlet.ServletOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -39,9 +40,8 @@ import java.util.Date; import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord;
import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java index fa4a24ff..2ee58d6e 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java @@ -31,8 +31,8 @@ import com.att.eelf.configuration.EELFManager; import java.io.IOException; import java.io.InvalidObjectException; import java.util.Collection; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.json.JSONObject; import org.onap.dmaap.datarouter.authz.AuthorizationResponse; import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java index b3bb679b..1851d03a 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java @@ -34,8 +34,8 @@ import java.net.HttpURLConnection; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
@@ -53,18 +53,13 @@ import org.onap.dmaap.datarouter.provisioning.utils.SynchronizerTask; * @author Robert Eby
* @version $Id$
*/
-@SuppressWarnings("serial")
public class SubscriptionServlet extends ProxyServlet {
private static final String SUBCNTRL_CONTENT_TYPE = "application/vnd.dmaap-dr.subscription-control";
//Adding EELF Logger Rally:US664892
- private static EELFLogger eelfLogger = EELFManager.getInstance()
+ private static final EELFLogger eelfLogger = EELFManager.getInstance()
.getLogger(SubscriptionServlet.class);
-
-
-
-
/**
* DELETE on the <subscriptionUrl> -- delete a subscription. See the <i>Deleting a Subscription</i> section in
* the <b>Provisioning API</b> document for details on how this method should be invoked.
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EventLogRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EventLogRecord.java index cfdda917..d801a556 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EventLogRecord.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EventLogRecord.java @@ -24,10 +24,8 @@ package org.onap.dmaap.datarouter.provisioning.beans;
+import jakarta.servlet.http.HttpServletRequest;
import java.security.cert.X509Certificate;
-
-import javax.servlet.http.HttpServletRequest;
-
import org.onap.dmaap.datarouter.provisioning.BaseServlet;
/**
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java index d520a417..973f868d 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java @@ -36,7 +36,7 @@ import java.util.Collection; import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
-import javax.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONArray;
import org.json.JSONObject;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/AafPropsUtils.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/AafPropsUtils.java index 6b78d21d..57bc84bd 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/AafPropsUtils.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/AafPropsUtils.java @@ -29,7 +29,7 @@ import org.onap.aaf.cadi.PropAccess; public class AafPropsUtils { - private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(AafPropsUtils.class); + private static final EELFLogger eelfLogger = EELFManager.getInstance().getLogger(AafPropsUtils.class); public static final String KEYSTORE_TYPE_PROPERTY = "PKCS12"; public static final String TRUESTSTORE_TYPE_PROPERTY = "jks"; @@ -38,7 +38,7 @@ public class AafPropsUtils { private static final String TRUSTSTORE_PATH_PROPERTY = "cadi_truststore"; private static final String TRUSTSTORE_PASS_PROPERTY = "cadi_truststore_password"; - private PropAccess propAccess; + private final PropAccess propAccess; public AafPropsUtils(File propsFile) throws IOException { propAccess = new PropAccess(); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java deleted file mode 100644 index 526bfd54..00000000 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java +++ /dev/null @@ -1,266 +0,0 @@ -/** - * - - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * <p>* http://www.apache.org/licenses/LICENSE-2.0 - * - * <p>Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * <p>* SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.dmaap.datarouter.provisioning.utils; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import java.io.IOException; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.filter.CadiFilter; -import org.onap.dmaap.datarouter.provisioning.BaseServlet; -import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord; -import org.onap.dmaap.datarouter.provisioning.beans.Feed; -import org.onap.dmaap.datarouter.provisioning.beans.Subscription; - -public class DRProvCadiFilter extends CadiFilter { - protected static EELFLogger eventlogger = EELFManager.getInstance().getLogger("EventLog"); - protected static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); - private String aafInstance = ""; - - public DRProvCadiFilter(boolean init, PropAccess access) throws ServletException { - super(init, access); - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException { - HttpServletRequest httpRequest = (HttpServletRequest) request; - HttpServletResponse httpResponse = (HttpServletResponse) response; - - EventLogRecord elr = new EventLogRecord(httpRequest); - String excludeAAF = httpRequest.getHeader(BaseServlet.EXCLUDE_AAF_HEADER); - //send this param value as true, if want to add legacy feed/subscriber in AAF env - - String pathUrl = httpRequest.getServletPath(); - if (!(pathUrl.contains("internal") - || pathUrl.contains("sublog") - || pathUrl.contains("feedlog") - || pathUrl.contains("statistics") - || pathUrl.contains("publish") - || pathUrl.contains("group"))) { - - String method = httpRequest.getMethod().toUpperCase(); - if (!("POST".equals(method))) { - // if request method is PUT method (publish or Feed update) Needs to check for DELETE - if ("PUT".equals(method) || "DELETE".equals(method)) { - if ((pathUrl.contains("subs"))) { //edit subscriber - int subId = BaseServlet.getIdFromPath(httpRequest); - if (subId <= 0) { - String message = String.format("Invalid request URI - %s", httpRequest.getPathInfo()); - elr.setMessage(message); - elr.setResult(HttpServletResponse.SC_NOT_FOUND); - eventlogger.error(elr.toString()); - httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND, message); - return; - } - if (isAAFSubscriber(subId)) { //edit AAF Subscriber - String message = String.format("DRProvCadiFilter - " - + "Edit AAF Subscriber : %d : AAF Instance - %s", subId, aafInstance); - elr.setMessage(message); - eventlogger.info(elr.toString()); - //request.setAttribute("aafInstance", aafInstance);// - // no need to set it in request since it is taken care in respective servlets - super.doFilter(request, response, chain); - - } else { //Edit or publish legacy Subscriber - String message = "DRProvCadiFilter - Edit/Publish Legacy Subscriber :" + subId; - elr.setMessage(message); - eventlogger.info(elr.toString()); - chain.doFilter(request, response); - } - - } else { //edit or publish Feed - int feedId = BaseServlet.getIdFromPath(httpRequest); - if (feedId <= 0) { - String message = "Invalid request URI - " + httpRequest.getPathInfo(); - elr.setMessage(message); - elr.setResult(HttpServletResponse.SC_NOT_FOUND); - eventlogger.error(elr.toString()); - httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND, message); - return; - } - - if (isAAFFeed(feedId)) { //edit AAF Feed - String message = "DRProvCadiFilter - Edit AAF Feed:" - + feedId + ":" + "AAF Instance -" + aafInstance; - elr.setMessage(message); - eventlogger.info(elr.toString()); - super.doFilter(request, response, chain); - - } else { //Edit or publish legacy Feed - String message = "DRProvCadiFilter - Edit/Publish Legacy Feed:" + feedId; - elr.setMessage(message); - eventlogger.info(elr.toString()); - chain.doFilter(request, response); - } - } - } else { // in all other cases defaults to legacy behavior - String message = "DRProvCadiFilter - Default Legacy Feed/Subscriber URI -:" - + httpRequest.getPathInfo(); - elr.setMessage(message); - eventlogger.info(elr.toString()); - chain.doFilter(request, response); - } - } else { - //check to add legacy/AAF subscriber - if ((pathUrl.contains("subscribe"))) { //add subscriber - int feedId = BaseServlet.getIdFromPath(httpRequest); - if (feedId <= 0) { - String message = "Invalid request URI - " + httpRequest.getPathInfo(); - elr.setMessage(message); - elr.setResult(HttpServletResponse.SC_NOT_FOUND); - eventlogger.error(elr.toString()); - httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND, message); - return; - } - if (isAAFFeed(feedId)) { //check if AAF Feed or legacy to add new subscriber - if (excludeAAF == null) { - String message = "DRProvCadiFilter -Invalid request Header Parmeter " - + BaseServlet.EXCLUDE_AAF_HEADER - + " = " + httpRequest.getHeader(BaseServlet.EXCLUDE_AAF_HEADER); - elr.setMessage(message); - elr.setResult(HttpServletResponse.SC_BAD_REQUEST); - eventlogger.error(elr.toString()); - httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, message); - return; - } - if (excludeAAF.equalsIgnoreCase("true")) { //Check to add legacy subscriber to AAF Feed - String message = "DRProvCadiFilter - add legacy subscriber to AAF Feed, FeedID:" + feedId; - elr.setMessage(message); - eventlogger.info(elr.toString()); - chain.doFilter(request, response); - } else { - String message = "DRProvCadiFilter - Add AAF subscriber to AAF Feed, FeedID:" - + feedId + ":" + "AAF Instance -" + aafInstance; - elr.setMessage(message); - eventlogger.info(elr.toString()); - super.doFilter(request, response, chain); - } - } else { //Add legacy susbcriber to legacy Feed - String message = "DRProvCadiFilter - add legacy subscriber to legacy Feed:" + feedId; - elr.setMessage(message); - eventlogger.info(elr.toString()); - chain.doFilter(request, response); - } - } else { //add AAF feed - if (excludeAAF == null) { - String message = "DRProvCadiFilter -Invalid request Header Parmeter " - + BaseServlet.EXCLUDE_AAF_HEADER - + " = " + httpRequest.getHeader(BaseServlet.EXCLUDE_AAF_HEADER); - elr.setMessage(message); - elr.setResult(HttpServletResponse.SC_BAD_REQUEST); - eventlogger.error(elr.toString()); - httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, message); - return; - } - if (excludeAAF.equalsIgnoreCase("true")) { //add legacy feed - String message = "DRProvCadiFilter - Create new legacy Feed : EXCLUDE_AAF = " + excludeAAF; - elr.setMessage(message); - eventlogger.info(elr.toString()); - chain.doFilter(request, response); - } else { //add AAF Feed - String message = "DRProvCadiFilter - Create new AAF Feed : EXCLUDE_AAF = " + excludeAAF; - elr.setMessage(message); - eventlogger.info(elr.toString()); - super.doFilter(request, response, chain); - } - } - } - } else { - //All other requests default to (Non CADI) legacy - chain.doFilter(request, response); - } - } - - /** - * Check if it is AAF feed OR existing feed. - * - * @param feedId the Feed ID - * @return true if it is valid - */ - @SuppressWarnings("resource") - private boolean isAAFFeed(int feedId) { - try { - Feed feed = Feed.getFeedById(feedId); - if (feed != null) { - if (!(("legacy".equalsIgnoreCase(feed.getAafInstance())) || feed.getAafInstance() == null - || feed.getAafInstance().equals(""))) { //also apply null check and empty check too - aafInstance = feed.getAafInstance(); - String message = "DRProvCadiFilter.isAAFFeed: aafInstance-:" + aafInstance + "; feedId:- " + feedId; - intlogger.debug(message); - return true; - } else { - return false; - } - } else { - String message = "DRProvCadiFilter.isAAFFeed; Feed does not exist FeedID:-" + feedId; - intlogger.debug(message); - } - - } catch (Exception e) { - intlogger.error("PROV0073 DRProvCadiFilter.isAAFFeed: " + e.getMessage(), e); - return false; - } - return false; - } - - /** - * Check if it is AAF sub OR existing sub. - * - * @param subId the Sub ID - * @return true if it is valid - */ - @SuppressWarnings("resource") - private boolean isAAFSubscriber(int subId) { - try { - Subscription subscriber = Subscription.getSubscriptionById(subId); - if (subscriber != null) { - if (!(("legacy".equalsIgnoreCase(subscriber.getAafInstance())) - || subscriber.getAafInstance() == null - || "".equals(subscriber.getAafInstance()))) { //also apply null check and empty check too - aafInstance = subscriber.getAafInstance(); - String message = "DRProvCadiFilter.isAAFSubscriber: aafInstance-:" + aafInstance + "; subId:- " - + subId; - intlogger.debug(message); - return true; - } else { - return false; - } - } else { - String message = "DRProvCadiFilter.isAAFSubscriber; Subscriber does not exist subId:-" + subId; - intlogger.debug(message); - } - } catch (Exception e) { - intlogger.error("PROV0073 DRProvCadiFilter.isAAFSubscriber: " + e.getMessage(), e); - return false; - } - return false; - } - -} diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java index 2d92276e..c614c0ba 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java @@ -37,7 +37,7 @@ import java.security.KeyStore; import java.util.Arrays; import java.util.Properties; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java index ebd09127..40574ee9 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java @@ -24,8 +24,8 @@ package org.onap.dmaap.datarouter.provisioning.utils; import com.att.eelf.configuration.EELFLogger; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; public class HttpServletUtils { diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ProvDbUtils.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ProvDbUtils.java index b654bf3c..b1e7a558 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ProvDbUtils.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ProvDbUtils.java @@ -41,7 +41,7 @@ import org.onap.dmaap.datarouter.provisioning.ProvRunner; public class ProvDbUtils { - private static EELFLogger intLogger = EELFManager.getInstance().getLogger("InternalLog"); + private static final EELFLogger intLogger = EELFManager.getInstance().getLogger("InternalLog"); private static DataSource dataSource; private static ProvDbUtils provDbUtils; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/SynchronizerTask.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/SynchronizerTask.java index 5eeb45a2..ef282618 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/SynchronizerTask.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/SynchronizerTask.java @@ -29,7 +29,6 @@ import static org.onap.dmaap.datarouter.provisioning.BaseServlet.TEXT_CT; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.io.ByteArrayOutputStream; -import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.InetAddress; @@ -50,11 +49,12 @@ import java.util.Set; import java.util.Timer; import java.util.TimerTask; import java.util.TreeSet; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.ByteArrayEntity; @@ -137,43 +137,46 @@ public class SynchronizerTask extends TimerTask { nextsynctime = 0; logger.info("PROV5000: Sync task starting, server podState is UNKNOWN_POD"); - try { - // Set up keystore - String type = AafPropsUtils.KEYSTORE_TYPE_PROPERTY; - String store = ProvRunner.getAafPropsUtils().getKeystorePathProperty(); - String pass = ProvRunner.getAafPropsUtils().getKeystorePassProperty(); - KeyStore keyStore = KeyStore.getInstance(type); - try (FileInputStream instream = new FileInputStream(new File(store))) { - keyStore.load(instream, pass.toCharArray()); - - } - // Set up truststore - store = ProvRunner.getAafPropsUtils().getTruststorePathProperty(); - pass = ProvRunner.getAafPropsUtils().getTruststorePassProperty(); - KeyStore trustStore = null; - if (store != null && store.length() > 0) { - trustStore = KeyStore.getInstance(AafPropsUtils.TRUESTSTORE_TYPE_PROPERTY); - try (FileInputStream instream = new FileInputStream(new File(store))) { - trustStore.load(instream, pass.toCharArray()); + try (AbstractHttpClient hc = new DefaultHttpClient()) { + Scheme sch; + if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) { + // Set up keystore + String type = AafPropsUtils.KEYSTORE_TYPE_PROPERTY; + String store = ProvRunner.getAafPropsUtils().getKeystorePathProperty(); + String pass = ProvRunner.getAafPropsUtils().getKeystorePassProperty(); + KeyStore keyStore = KeyStore.getInstance(type); + try (FileInputStream instream = new FileInputStream(store)) { + keyStore.load(instream, pass.toCharArray()); } - } + // Set up truststore + store = ProvRunner.getAafPropsUtils().getTruststorePathProperty(); + pass = ProvRunner.getAafPropsUtils().getTruststorePassProperty(); + KeyStore trustStore = null; + if (store != null && store.length() > 0) { + trustStore = KeyStore.getInstance(AafPropsUtils.TRUESTSTORE_TYPE_PROPERTY); + try (FileInputStream instream = new FileInputStream(store)) { + trustStore.load(instream, pass.toCharArray()); - // We are connecting with the node name, but the certificate will have the CNAME - // So we need to accept a non-matching certificate name - String keystorepass = ProvRunner.getAafPropsUtils().getKeystorePassProperty(); - try (AbstractHttpClient hc = new DefaultHttpClient()) { + } + } + // We are connecting with the node name, but the certificate will have the CNAME + // So we need to accept a non-matching certificate name + String keystorepass = ProvRunner.getAafPropsUtils().getKeystorePassProperty(); SSLSocketFactory socketFactory = (trustStore == null) ? new SSLSocketFactory(keyStore, keystorepass) : new SSLSocketFactory(keyStore, keystorepass, trustStore); socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - Scheme sch = new Scheme("https", 443, socketFactory); - hc.getConnectionManager().getSchemeRegistry().register(sch); - httpclient = hc; + sch = new Scheme("https", 443, socketFactory); + } else { + PlainSocketFactory socketFactory = new PlainSocketFactory(); + sch = new Scheme("http", 80, socketFactory); } + hc.getConnectionManager().getSchemeRegistry().register(sch); + httpclient = hc; setSynchTimer(ProvRunner.getProvProperties().getProperty( - "org.onap.dmaap.datarouter.provserver.sync_interval", "5000")); + "org.onap.dmaap.datarouter.provserver.sync_interval", "5000")); } catch (Exception e) { logger.warn("PROV5005: Problem starting the synchronizer: " + e); } diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java index f0f10671..e117d368 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java @@ -102,9 +102,9 @@ public class ThrottleFilter extends TimerTask implements Filter { private static int samplingPeriod = 0; // sampling period
private static int action = ACTION_DROP; // action to take (throttle or drop)
- private static EELFLogger logger = EELFManager.getInstance().getLogger("InternalLog");
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger("InternalLog");
private static Map<String, Counter> map = new HashMap<>();
- private Map<String, List<Continuation>> suspendedRequests = new HashMap<>();
+ private final Map<String, List<Continuation>> suspendedRequests = new HashMap<>();
private static final Timer rolex = new Timer();
@Override
@@ -213,7 +213,7 @@ public class ThrottleFilter extends TimerTask implements Filter { String str = String.format("Throttling connection: %s %d bad connections in %d minutes",
getConnectionId(request), rate, samplingPeriod);
logger.info(str);
- Continuation continuation = ContinuationSupport.getContinuation(request);
+ Continuation continuation = ContinuationSupport.getContinuation((javax.servlet.ServletRequest) request);
continuation.suspend();
register(id, continuation);
continuation.undispatch();
@@ -232,11 +232,7 @@ public class ThrottleFilter extends TimerTask implements Filter { private void register(String id, Continuation continuation) {
synchronized (suspendedRequests) {
- List<Continuation> list = suspendedRequests.get(id);
- if (list == null) {
- list = new ArrayList<>();
- suspendedRequests.put(id, list);
- }
+ List<Continuation> list = suspendedRequests.computeIfAbsent(id, k -> new ArrayList<>());
list.add(continuation);
}
}
@@ -277,8 +273,8 @@ public class ThrottleFilter extends TimerTask implements Filter { }
}
- public class Counter {
- private List<Long> times = new ArrayList<>(); // a record of request times
+ public static class Counter {
+ private final List<Long> times = new ArrayList<>(); // a record of request times
/**
* Method to prune request rate.
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java index 988b576f..89403488 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java @@ -153,20 +153,17 @@ public class URLUtilities { }
public static String getUrlSecurityOption() {
- if (Boolean.parseBoolean(ProvRunner.getProvProperties()
- .getProperty("org.onap.dmaap.datarouter.provserver.tlsenabled", "true"))) {
+ if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) {
return "https://";
}
return "http://";
}
private static String getAppropriateUrlPort() {
- if (Boolean.parseBoolean(ProvRunner.getProvProperties()
- .getProperty("org.onap.dmaap.datarouter.provserver.tlsenabled", "true")))
- return "";
-
+ if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) {
+ return "";
+ }
return ":" + ProvRunner.getProvProperties()
.getProperty("org.onap.dmaap.datarouter.provserver.http.port", "8080");
-
}
}
diff --git a/datarouter-prov/src/main/resources/docker/Dockerfile b/datarouter-prov/src/main/resources/docker/Dockerfile index 7bc92c83..38ea3b9e 100644 --- a/datarouter-prov/src/main/resources/docker/Dockerfile +++ b/datarouter-prov/src/main/resources/docker/Dockerfile @@ -19,7 +19,7 @@ # limitations under the License. # ============LICENSE_END==================================================== # -FROM nexus3.onap.org:10001/onap/integration-java11:8.0.0 +FROM nexus3.onap.org:10001/onap/integration-java11:10.0.0 COPY /opt /opt diff --git a/datarouter-prov/src/main/resources/provserver.properties b/datarouter-prov/src/main/resources/provserver.properties index 642088ff..66d4e6c4 100755 --- a/datarouter-prov/src/main/resources/provserver.properties +++ b/datarouter-prov/src/main/resources/provserver.properties @@ -26,17 +26,20 @@ org.onap.dmaap.datarouter.provserver.http.port = 8080 org.onap.dmaap.datarouter.provserver.https.port = 8443 org.onap.dmaap.datarouter.provserver.https.relaxation = true -org.onap.dmaap.datarouter.provserver.aafprops.path = /opt/app/osaaf/local/org.onap.dmaap-dr.props - org.onap.dmaap.datarouter.provserver.accesslog.dir = /opt/app/datartr/logs org.onap.dmaap.datarouter.provserver.spooldir = /opt/app/datartr/spool org.onap.dmaap.datarouter.provserver.dbscripts = /opt/app/datartr/etc/misc org.onap.dmaap.datarouter.provserver.logretention = 30 -#DMAAP-597 (Tech Dept) REST request source IP auth -# relaxation to accommodate OOM kubernetes deploy +org.onap.dmaap.datarouter.provserver.aafprops.path = /opt/app/osaaf/local/org.onap.dmaap-dr.props org.onap.dmaap.datarouter.provserver.isaddressauthenabled = false +org.onap.dmaap.datarouter.provserver.cadi.enabled = false + +org.onap.dmaap.datarouter.provserver.tlsenabled = false +org.onap.dmaap.datarouter.nodeserver.https.port = 8443 +org.onap.dmaap.datarouter.nodeserver.http.port = 8080 + #Localhost address config org.onap.dmaap.datarouter.provserver.localhost = 127.0.0.1 @@ -46,18 +49,3 @@ org.onap.dmaap.datarouter.db.url = jdbc:mariadb://datarouter-mariadb:3306/d org.onap.dmaap.datarouter.db.login = datarouter org.onap.dmaap.datarouter.db.password = datarouter -# PROV - DEFAULT ENABLED TLS PROTOCOLS -org.onap.dmaap.datarouter.provserver.https.include.protocols = TLSv1.1|TLSv1.2 - -# AAF config -org.onap.dmaap.datarouter.provserver.cadi.enabled = false - -org.onap.dmaap.datarouter.provserver.aaf.feed.type = org.onap.dmaap-dr.feed -org.onap.dmaap.datarouter.provserver.aaf.sub.type = org.onap.dmaap-dr.sub -org.onap.dmaap.datarouter.provserver.aaf.instance = legacy -org.onap.dmaap.datarouter.provserver.aaf.action.publish = publish -org.onap.dmaap.datarouter.provserver.aaf.action.subscribe = subscribe - -org.onap.dmaap.datarouter.provserver.tlsenabled = true -org.onap.dmaap.datarouter.nodeserver.https.port = 8443 -org.onap.dmaap.datarouter.nodeserver.http.port = 8080
\ No newline at end of file diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsDelete.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsDelete.java index 47a3071f..7ebdf223 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsDelete.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsDelete.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsGet.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsGet.java index 70be1f22..2cc5feba 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsGet.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsGet.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsPost.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsPost.java index dfe7f787..9f604fe9 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsPost.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsPost.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.Header; import org.apache.http.HttpEntity; diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsPut.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsPut.java index 4220ef17..15e7c70a 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsPut.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestDrFeedsPut.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestFeedDelete.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestFeedDelete.java index f451f5a3..25e6e43a 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestFeedDelete.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestFeedDelete.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestFeedPut.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestFeedPut.java index 7a02931e..d77bc98d 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestFeedPut.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestFeedPut.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.Header; import org.apache.http.HttpEntity; diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestInternalMisc.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestInternalMisc.java index bc724079..9c30cd3f 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestInternalMisc.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestInternalMisc.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestLogGet.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestLogGet.java index ba28da11..0da0f41d 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestLogGet.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestLogGet.java @@ -28,7 +28,7 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.text.SimpleDateFormat; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestPublish.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestPublish.java index 833380a6..5c84a670 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestPublish.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestPublish.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.Header; import org.apache.http.HttpResponse; diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestSubscribePost.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestSubscribePost.java index 1f21c1f6..dfcdeff4 100644 --- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestSubscribePost.java +++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestSubscribePost.java @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; import java.io.IOException; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java index d335ffa1..9d0d3c80 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java @@ -25,7 +25,7 @@ import static org.mockito.Mockito.when; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java index 149943ea..84244dc3 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java @@ -38,7 +38,7 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; import javax.crypto.SecretKeyFactory; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.lang3.reflect.FieldUtils; import org.json.JSONObject; import org.junit.Assert; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java index af1d7145..9993334e 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java @@ -32,14 +32,14 @@ import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; +import jakarta.servlet.ServletOutputStream; import java.util.HashSet; import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java index 00bc2aa2..066b51fc 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java @@ -32,6 +32,8 @@ import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; import java.sql.Connection; import java.sql.SQLException; import java.util.HashSet; @@ -39,10 +41,8 @@ import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.jetbrains.annotations.NotNull; import org.json.JSONArray; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java index d84e66d4..5b9be757 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/GroupServletTest.java @@ -29,15 +29,15 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; import java.util.HashSet; import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.json.JSONObject; import org.junit.AfterClass; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java index 1601e63d..1016b06d 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java @@ -31,15 +31,15 @@ import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; import java.io.File; import java.net.InetAddress; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.AfterClass; import org.junit.Assert; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java index 1f6e3a59..931c00a2 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java @@ -25,6 +25,7 @@ package org.onap.dmaap.datarouter.provisioning; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; +import jakarta.servlet.ServletOutputStream; import org.junit.Before; import org.junit.BeforeClass; import org.junit.AfterClass; @@ -34,9 +35,8 @@ import org.mockito.Mock; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/ProvServerTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/ProvServerTest.java index 78d2eaa7..a915fa84 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/ProvServerTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/ProvServerTest.java @@ -46,7 +46,7 @@ public class ProvServerTest { public static void init() { System.setProperty( "org.onap.dmaap.datarouter.provserver.properties", - "src/test/resources/h2Database.properties"); + "src/test/resources/h2DatabaseTlsDisabled.properties"); } @Test diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/ProxyServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/ProxyServletTest.java index 8a676878..3c8d84e6 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/ProxyServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/ProxyServletTest.java @@ -24,6 +24,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.powermock.api.mockito.PowerMockito.when; +import jakarta.servlet.ServletConfig; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; @@ -33,9 +34,8 @@ import java.util.List; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.ServletConfig; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/PublishServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/PublishServletTest.java index 49e93bf1..f0d18b30 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/PublishServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/PublishServletTest.java @@ -37,8 +37,8 @@ import org.powermock.modules.junit4.PowerMockRunner; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.FileNotFoundException; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java index 0c5f63fc..dea98e0a 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/RouteServletTest.java @@ -29,12 +29,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import jakarta.servlet.ServletOutputStream; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java index b6686b0e..9512ff19 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/StatisticsServletTest.java @@ -28,12 +28,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import jakarta.servlet.ServletOutputStream; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java index 48a39925..bf2371f8 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java @@ -32,14 +32,14 @@ import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; +import jakarta.servlet.ServletOutputStream; import java.util.HashSet; import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.jetbrains.annotations.NotNull; import org.json.JSONObject; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java index 1f4fd535..d5badd34 100755 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java @@ -32,6 +32,8 @@ import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; import java.sql.Connection; import java.sql.SQLException; import java.util.HashSet; @@ -39,10 +41,8 @@ import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.jetbrains.annotations.NotNull; import org.json.JSONObject; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilterTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilterTest.java deleted file mode 100644 index 25df548e..00000000 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilterTest.java +++ /dev/null @@ -1,271 +0,0 @@ -/**-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.dmaap.datarouter.provisioning.utils;
-
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.servlet.FilterChain;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.filter.CadiFilter;
-import org.onap.dmaap.datarouter.provisioning.BaseServlet;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.api.support.membermodification.MemberMatcher;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({CadiFilter.class})
-@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "org.w3c.*"})
-public class DRProvCadiFilterTest {
-
- @Mock
- private PropAccess access;
-
- @Mock
- private HttpServletRequest request;
-
- @Mock
- private HttpServletResponse response;
-
- @Mock
- private FilterChain chain;
-
- private DRProvCadiFilter cadiFilter;
-
-
- private static EntityManagerFactory emf;
- private static EntityManager em;
-
-
- @BeforeClass
- public static void init() {
- emf = Persistence.createEntityManagerFactory("dr-unit-tests");
- em = emf.createEntityManager();
- System.setProperty(
- "org.onap.dmaap.datarouter.provserver.properties",
- "src/test/resources/h2Database.properties");
- }
-
- @Before
- public void setUp() throws Exception {
- cadiFilter = new DRProvCadiFilter(false, access);
- }
-
- @Test
- public void Given_doFilter_Called_And_Path_Contains_subs_And_SubId_Is_Incorrectly_Set_Then_Not_Found_Response_Returned() throws Exception{
- setRequestMocking("PUT", "subs");
-
- cadiFilter.doFilter(request, response, chain);
- verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
- }
-
- @Test
- public void Given_doFilter_called_And_Path_Contains_subs_And_Is_AAF_Subscriber_then_call_Super_doFilter() throws Exception{
- setRequestMocking("PUT", "subs");
- when(request.getPathInfo()).thenReturn("/2");
- PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(CadiFilter.class));
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(0)).doFilter(request, response);
- }
-
- @Test
- public void Given_doFilter_called_And_Path_Contains_subs_And_Is_Not_AAF_Subscriber_then_call_chain_doFilter() throws Exception{
- setRequestMocking("PUT", "subs");
- when(request.getPathInfo()).thenReturn("/5");
-
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(1)).doFilter(request, response);
- }
-
- @Test
- public void Given_doFilter_called_And_FeedId_Is_Incorrectly_Set_Then_Not_Found_Response_Returned () throws Exception{
- setRequestMocking("PUT", "feeds");
-
- cadiFilter.doFilter(request, response, chain);
- verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
- }
-
- @Test
- public void Given_doFilter_called_And_FeedId_Is_Correctly_Set_And_Is_AAF_Feed_Then_Call_Super_doFilter() throws Exception{
- setRequestMocking("PUT", "feeds");
- when(request.getPathInfo()).thenReturn("/2");
- PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(CadiFilter.class));
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(0)).doFilter(request, response);
- }
-
- @Test
- public void Given_doFilter_called_And_FeedId_Is_Correctly_Set_And_Is_Not_AAF_Feed_then_call_chain_doFilter() throws Exception{
- setRequestMocking("PUT", "feeds");
- when(request.getPathInfo()).thenReturn("/1");
-
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(1)).doFilter(request, response);
- }
-
- @Test
- public void Given_doFilter_called_With_Get_Then_call_chain_doFilter() throws Exception{
- setRequestMocking("GET", "feeds");
- when(request.getPathInfo()).thenReturn("/5");
-
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(1)).doFilter(request, response);
- }
-
-
- @Test
- public void Given_doFilter_called_With_POST_Then_call_chain_doFilter() throws Exception{
- setRequestMocking("POST", "subscribe");
-
- cadiFilter.doFilter(request, response, chain);
- verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
-
- }
-
- @Test
- public void Given_doFilter_called_With_POST_And_FeedId_Is_Incorrectly_Set_Then_Not_Found_Response_Returned() throws Exception{
- setRequestMocking("POST", "subscribe");
-
- cadiFilter.doFilter(request, response, chain);
- verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
-
- }
-
- @Test
- public void Given_doFilter_called_With_POST_And_Exclude_AAF_Is_NULL_Then_Bad_Request_Response_Returned() throws Exception{
- setRequestMocking("POST", "subscribe");
- when(request.getPathInfo()).thenReturn("/2");
-
- cadiFilter.doFilter(request, response, chain);
- verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), anyString());
-
- }
-
- @Test
- public void Given_doFilter_called_With_POST_And_Exclude_AAF_Equals_True_Then_Call_Chain_doFilter() throws Exception{
- setRequestMocking("POST", "subscribe");
- when(request.getPathInfo()).thenReturn("/2");
- when(request.getHeader("X-EXCLUDE-AAF")).thenReturn("true");
-
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(1)).doFilter(request, response);
-
- }
-
- @Test
- public void Given_doFilter_called_With_POST_And_Exclude_AAF_Equals_False_Then_Call_Super_doFilter() throws Exception{
- setRequestMocking("POST", "subscribe");
- when(request.getPathInfo()).thenReturn("/2");
- when(request.getHeader("X-EXCLUDE-AAF")).thenReturn("false");
- PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(CadiFilter.class));
-
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(0)).doFilter(request, response);
-
- }
-
- @Test
- public void Given_doFilter_called_With_POST_And_Is_Not_AAF_Exclude_AAF_Equals_Then_Call_Chain_doFilter() throws Exception{
- setRequestMocking("POST", "subscribe");
- when(request.getPathInfo()).thenReturn("/5");
- when(request.getHeader("X-EXCLUDE-AAF")).thenReturn("false");
-
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(1)).doFilter(request, response);
-
- }
-
- @Test
- public void Given_doFilter_called_With_POST_And_Path_Not_Includes_subscribe_And_Exclude_AAF_Is_NULL_Then_Bad_Request_Response_Returned() throws Exception{
- setRequestMocking("POST", "other");
- when(request.getPathInfo()).thenReturn("/5");
-
- cadiFilter.doFilter(request, response, chain);
- verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), anyString());
-
- }
-
- @Test
- public void Given_doFilter_called_With_POST_And_Path_Not_Includes_subscribe_And_Exclude_AAF_Equals_True_Then_Call_Chain_doFilter() throws Exception{
- setRequestMocking("POST", "other");
- when(request.getPathInfo()).thenReturn("/5");
- when(request.getHeader("X-EXCLUDE-AAF")).thenReturn("true");
-
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(1)).doFilter(request, response);
-
- }
-
- @Test
- public void Given_doFilter_called_With_POST_And_Path_Not_Includes_subscribe_And_Exclude_AAF_Equals_False_Then_Call_Super_doFilter() throws Exception{
- setRequestMocking("POST", "other");
- when(request.getPathInfo()).thenReturn("/5");
- when(request.getHeader("X-EXCLUDE-AAF")).thenReturn("false");
- PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(CadiFilter.class));
-
- cadiFilter.doFilter(request, response, chain);
- verify(chain, times(0)).doFilter(request, response);
-
- }
-
- @Test
- public void Given_doFilter_Called_And_Path_Contains_subs_And_getSubId_Throws_NumberFormatException_then_Not_Found_response_returned() throws Exception{
- setRequestMocking("PUT", "subs");
- when(request.getPathInfo()).thenReturn("5/");
- cadiFilter.doFilter(request, response, chain);
- verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
-
- }
-
- @Test
- public void Given_doFilter_called_And_FeedId_Throws_Set_Then_Not_Found_Response_Returned () throws Exception{
- setRequestMocking("PUT", "feeds");
- when(request.getPathInfo()).thenReturn("//5");
- cadiFilter.doFilter(request, response, chain);
- verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
- }
-
- private void setRequestMocking(String method, String servletPath)
- {
- when(request.getRemoteAddr()).thenReturn(null);
- when(request.getHeader(BEHALF_HEADER)).thenReturn(null);
- when(request.getAttribute(BaseServlet.CERT_ATTRIBUTE)).thenReturn(null);
- when(request.getMethod()).thenReturn(method);
- when(request.getServletPath()).thenReturn(servletPath);
- }
-
- }
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilterTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilterTest.java index 94ef3b72..bb0077ab 100644 --- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilterTest.java +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilterTest.java @@ -23,6 +23,25 @@ package org.onap.dmaap.datarouter.provisioning.utils; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.reflect.FieldUtils; import org.eclipse.jetty.continuation.Continuation; import org.eclipse.jetty.continuation.ContinuationSupport; @@ -31,33 +50,20 @@ import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpConnection; import org.eclipse.jetty.server.Request; import org.junit.Test; - import org.junit.runner.RunWith; -import static org.junit.Assert.*; -import static org.hamcrest.core.Is.is; import org.mockito.Mock; - -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; - import org.onap.dmaap.datarouter.provisioning.beans.Parameters; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.*; - @RunWith(PowerMockRunner.class) @SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Parameters", "org.eclipse.jetty.server.Request", "org.eclipse.jetty.continuation.ContinuationSupport", "org.eclipse.jetty.server.HttpConnection"}) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) public class ThrottleFilterTest { @Mock @@ -132,7 +138,7 @@ public class ThrottleFilterTest { public void Given_Do_Filter_Run_and_enabled_and_action_is_true_and_rate_is_greater_than_0_and_getFeedId_returns_id_then_continuation_will_call_suspend_and_dispatch_once() throws Exception { mockParametersWithValues("0,5,thing"); PowerMockito.mockStatic(ContinuationSupport.class); - PowerMockito.when(continuationsupport.getContinuation(any())).thenReturn(continuation); + PowerMockito.when(ContinuationSupport.getContinuation(any())).thenReturn(continuation); ThrottleFilter.configure(); mockServletInputStream(); FieldUtils.writeDeclaredStaticField(ThrottleFilter.class, "action", 1, true); @@ -175,7 +181,7 @@ public class ThrottleFilterTest { FilterConfig filterconfig = mock(FilterConfig.class); mockParametersWithValues("0,5,thing"); PowerMockito.mockStatic(ContinuationSupport.class); - PowerMockito.when(continuationsupport.getContinuation(any())).thenReturn(continuation); + PowerMockito.when(ContinuationSupport.getContinuation(any())).thenReturn(continuation); throttleFilter.init(filterconfig); throttleFilter.destroy(); @@ -199,17 +205,17 @@ public class ThrottleFilterTest { private void mockContinuationSupport() { PowerMockito.mockStatic(ContinuationSupport.class); - PowerMockito.when(continuationsupport.getContinuation(any())).thenReturn(continuation); + PowerMockito.when(ContinuationSupport.getContinuation(any())).thenReturn(continuation); } private void mockHttpConnectionHttpChannelAndRequest(ServletInputStream serverinputstream) throws IOException { PowerMockito.mockStatic(ContinuationSupport.class); - PowerMockito.when(continuationsupport.getContinuation(any())).thenReturn(continuation); + PowerMockito.when(ContinuationSupport.getContinuation(any())).thenReturn(continuation); when(serverinputstream.read(any())).thenReturn(2).thenReturn(1).thenReturn(0); when(request.getInputStream()).thenReturn(serverinputstream); PowerMockito.mockStatic(HttpConnection.class); EndPoint endpoint = mock(EndPoint.class); - PowerMockito.when(httpconnection.getCurrentConnection()).thenReturn(httpconnection); + PowerMockito.when(HttpConnection.getCurrentConnection()).thenReturn(httpconnection); PowerMockito.when(httpconnection.getHttpChannel()).thenReturn(httpchannel); when(httpchannel.getRequest()).thenReturn(req); when(req.getHttpChannel()).thenReturn(httpchannel); diff --git a/datarouter-prov/src/test/resources/h2DatabaseTlsDisabled.properties b/datarouter-prov/src/test/resources/h2DatabaseTlsDisabled.properties index 05ab3a47..b7f5aa9d 100644 --- a/datarouter-prov/src/test/resources/h2DatabaseTlsDisabled.properties +++ b/datarouter-prov/src/test/resources/h2DatabaseTlsDisabled.properties @@ -25,8 +25,8 @@ org.onap.dmaap.datarouter.db.driver = org.h2.Driver org.onap.dmaap.datarouter.db.url = jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 org.onap.dmaap.datarouter.provserver.isaddressauthenabled = true -org.onap.dmaap.datarouter.provserver.cadi.enabled = true -org.onap.dmaap.datarouter.provserver.https.relaxation = false +org.onap.dmaap.datarouter.provserver.cadi.enabled = false +org.onap.dmaap.datarouter.provserver.https.relaxation = true org.onap.dmaap.datarouter.provserver.accesslog.dir = unit-test-logs org.onap.dmaap.datarouter.provserver.spooldir = src/test/resources org.onap.dmaap.datarouter.provserver.dbscripts = src/test/resources diff --git a/datarouter-prov/src/test/resources/prov_data.json b/datarouter-prov/src/test/resources/prov_data.json index cf455c71..80ff6fab 100644 --- a/datarouter-prov/src/test/resources/prov_data.json +++ b/datarouter-prov/src/test/resources/prov_data.json @@ -25,10 +25,10 @@ "aaf_instance": "legacy", "publisher": "dradmin", "links": { - "subscribe": "https://dmaap-dr-prov/subscribe/1", - "log": "https://dmaap-dr-prov/feedlog/1", - "publish": "https://dmaap-dr-prov/publish/1", - "self": "https://dmaap-dr-prov/feed/1" + "subscribe": "http://dmaap-dr-prov/subscribe/1", + "log": "http://dmaap-dr-prov/feedlog/1", + "publish": "http://dmaap-dr-prov/publish/1", + "self": "http://dmaap-dr-prov/feed/1" }, "created_date": 1560871903000 } @@ -49,7 +49,7 @@ "use100": true, "password": "PASSWORD", "user": "LOGIN", - "url": "https://dcae-pm-mapper:8443/delivery" + "url": "http://dcae-pm-mapper:8080/delivery" }, "subscriber": "dradmin", "groupid": 0, @@ -62,9 +62,9 @@ "decompress": true, "aaf_instance": "legacy", "links": { - "feed": "https://dmaap-dr-prov/feed/1", - "log": "https://dmaap-dr-prov/sublog/1", - "self": "https://dmaap-dr-prov/subs/1" + "feed": "http://dmaap-dr-prov/feed/1", + "log": "http://dmaap-dr-prov/sublog/1", + "self": "http://dmaap-dr-prov/subs/1" }, "created_date": 1560872889000 } |