diff options
Diffstat (limited to 'datarouter-prov/src/main/java')
6 files changed, 185 insertions, 90 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java index aefe8cdf..3269c843 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java @@ -24,10 +24,12 @@ package org.onap.dmaap.datarouter.provisioning; +import static java.lang.System.exit; + import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.security.Security; import java.util.EnumSet; import java.util.Properties; @@ -51,8 +53,7 @@ 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.onap.aaf.cadi.PropAccess; - +import org.onap.dmaap.datarouter.provisioning.utils.AafPropsUtils; import org.onap.dmaap.datarouter.provisioning.utils.DB; import org.onap.dmaap.datarouter.provisioning.utils.DRProvCadiFilter; import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader; @@ -90,15 +91,6 @@ import org.onap.dmaap.datarouter.provisioning.utils.ThrottleFilter; */ public class Main { - /** - * The truststore to use if none is specified. - */ - static final String DEFAULT_TRUSTSTORE = "/opt/java/jdk/jdk180/jre/lib/security/cacerts"; - static final String KEYSTORE_TYPE_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.type"; - static final String KEYSTORE_PATH_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.path"; - static final String KEYSTORE_PASS_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.password"; - static final String TRUSTSTORE_PATH_PROPERTY = "org.onap.dmaap.datarouter.provserver.truststore.path"; - static final String TRUSTSTORE_PASS_PROPERTY = "org.onap.dmaap.datarouter.provserver.truststore.password"; public static final EELFLogger intlogger = EELFManager.getInstance() .getLogger("org.onap.dmaap.datarouter.provisioning.internal"); @@ -106,18 +98,7 @@ public class Main { * The one and only {@link Server} instance in this JVM. */ private static Server server; - - class Inner { - InputStream getCadiProps() { - InputStream in = null; - try { - in = getClass().getClassLoader().getResourceAsStream("drProvCadi.properties"); - } catch (Exception e) { - intlogger.error("Exception in Main.getCadiProps(): " + e.getMessage(), e); - } - return in; - } - } + static AafPropsUtils aafPropsUtils; /** * Starts the Data Router Provisioning server. @@ -129,10 +110,11 @@ public class Main { Security.setProperty("networkaddress.cache.ttl", "4"); // Check DB is accessible and contains the expected tables if (!checkDatabase()) { - System.exit(1); + intlogger.error("Data Router Provisioning database init failure. Exiting."); + exit(1); } - intlogger.info("PROV0000 **** AT&T Data Router Provisioning Server starting...."); + intlogger.info("PROV0000 **** Data Router Provisioning Server starting...."); Security.setProperty("networkaddress.cache.ttl", "4"); Properties provProperties = (new DB()).getProperties(); @@ -180,6 +162,16 @@ public class Main { httpConfiguration.setSendServerVersion(true); httpConfiguration.setSendDateHeader(false); + try { + AafPropsUtils.init(new File(provProperties.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); + } + aafPropsUtils = AafPropsUtils.getInstance(); + //HTTP Connector HandlerCollection handlerCollection; try (ServerConnector httpServerConnector = @@ -190,19 +182,19 @@ public class Main { // SSL Context SslContextFactory sslContextFactory = new SslContextFactory(); - sslContextFactory.setKeyStoreType(provProperties.getProperty(KEYSTORE_TYPE_PROPERTY, "jks")); - sslContextFactory.setKeyStorePath(provProperties.getProperty(KEYSTORE_PATH_PROPERTY)); - sslContextFactory.setKeyStorePassword(provProperties.getProperty(KEYSTORE_PASS_PROPERTY)); - sslContextFactory.setKeyManagerPassword(provProperties - .getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password")); - - String ts = provProperties.getProperty(TRUSTSTORE_PATH_PROPERTY); - if (ts != null && ts.length() > 0) { - intlogger.info("@@ TS -> " + ts); - sslContextFactory.setTrustStorePath(ts); - sslContextFactory.setTrustStorePassword(provProperties.getProperty(TRUSTSTORE_PASS_PROPERTY)); + sslContextFactory.setKeyStoreType(AafPropsUtils.KEYSTORE_TYPE_PROPERTY); + sslContextFactory.setKeyStorePath(aafPropsUtils.getKeystorePathProperty()); + sslContextFactory.setKeyStorePassword(aafPropsUtils.getKeystorePassProperty()); + sslContextFactory.setKeyManagerPassword(aafPropsUtils.getKeystorePassProperty()); + + String truststorePathProperty = aafPropsUtils.getTruststorePathProperty(); + if (truststorePathProperty != null && truststorePathProperty.length() > 0) { + intlogger.info("@@ TS -> " + truststorePathProperty); + sslContextFactory.setTrustStoreType(AafPropsUtils.TRUESTSTORE_TYPE_PROPERTY); + sslContextFactory.setTrustStorePath(truststorePathProperty); + sslContextFactory.setTrustStorePassword(aafPropsUtils.getTruststorePassProperty()); } else { - sslContextFactory.setTrustStorePath(DEFAULT_TRUSTSTORE); + sslContextFactory.setTrustStorePath(AafPropsUtils.DEFAULT_TRUSTSTORE); sslContextFactory.setTrustStorePassword("changeit"); } @@ -263,23 +255,9 @@ public class Main { //CADI Filter activation check if (Boolean.parseBoolean(provProperties.getProperty( "org.onap.dmaap.datarouter.provserver.cadi.enabled", "false"))) { - //Get cadi properties - Properties cadiProperties = null; - try { - intlogger.info("PROV0001 Prov - Loading CADI properties"); - cadiProperties = new Properties(); - Inner obj = new Main().new Inner(); - InputStream in = obj.getCadiProps(); - cadiProperties.load(in); - } catch (IOException ioe) { - intlogger.error("PROV0001 Exception loading CADI properties: " + ioe.getMessage(), ioe); - } - cadiProperties.setProperty("aaf_locate_url", provProperties.getProperty("org.onap.dmaap.datarouter.provserver.cadi.aaf.url", "https://aaf-onap-test.osaaf.org:8095")); - intlogger.info("PROV0001 aaf_url set to - " + cadiProperties.getProperty("aaf_url")); - - PropAccess access = new PropAccess(cadiProperties); - servletContextHandler.addFilter(new FilterHolder(new DRProvCadiFilter(true, access)), + servletContextHandler.addFilter(new FilterHolder(new DRProvCadiFilter(true, aafPropsUtils.getPropAccess())), "/*", EnumSet.of(DispatcherType.REQUEST)); + intlogger.info("PROV0001 AAF CADI Auth enabled for "); } ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection(); @@ -306,7 +284,8 @@ public class Main { server.start(); intlogger.info("Prov Server started-" + server.getState()); } catch (Exception e) { - intlogger.info("Jetty failed to start. Reporting will we unavailable: " + e.getMessage(), e); + intlogger.error("Jetty failed to start. Exiting: " + e.getMessage(), e); + exit(1); } server.join(); intlogger.info("PROV0001 **** AT&T Data Router Provisioning Server halted."); @@ -325,7 +304,7 @@ public class Main { try { server.stop(); Thread.sleep(5000L); - System.exit(0); + exit(0); } catch (Exception e) { intlogger.error("Exception in Main.shutdown(): " + e.getMessage(), e); } 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 c9075b0c..72d55a4c 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 @@ -53,6 +53,7 @@ import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.entity.BasicHttpEntity; import org.apache.http.impl.client.AbstractHttpClient; import org.apache.http.impl.client.DefaultHttpClient; +import org.onap.dmaap.datarouter.provisioning.utils.AafPropsUtils; import org.onap.dmaap.datarouter.provisioning.utils.DB; import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities; @@ -80,21 +81,23 @@ public class ProxyServlet extends BaseServlet { super.init(config); try { // Set up keystore - Properties props = (new DB()).getProperties(); - String store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY); - String pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY); + String type = AafPropsUtils.KEYSTORE_TYPE_PROPERTY; + String store = Main.aafPropsUtils.getKeystorePathProperty(); + String pass = Main.aafPropsUtils.getKeystorePassProperty(); + KeyStore keyStore = readStore(store, pass, type); + // Set up truststore + store = Main.aafPropsUtils.getTruststorePathProperty(); + pass = Main.aafPropsUtils.getTruststorePassProperty(); if (store == null || store.length() == 0) { - store = Main.DEFAULT_TRUSTSTORE; + store = AafPropsUtils.DEFAULT_TRUSTSTORE; pass = "changeit"; } - KeyStore trustStore = readStore(store, pass, KeyStore.getDefaultType()); + 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 - String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks"); - KeyStore keyStore = readStore(store, pass, type); SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore, - props.getProperty(Main.KEYSTORE_PASS_PROPERTY), trustStore); + Main.aafPropsUtils.getKeystorePassProperty(), trustStore); socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); sch = new Scheme("https", 443, socketFactory); inited = true; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java index 5d0592c3..2a907fb7 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java @@ -77,6 +77,7 @@ import org.onap.dmaap.datarouter.provisioning.beans.NetworkRoute; import org.onap.dmaap.datarouter.provisioning.beans.Parameters; import org.onap.dmaap.datarouter.provisioning.beans.Subscription; import org.onap.dmaap.datarouter.provisioning.beans.Syncable; +import org.onap.dmaap.datarouter.provisioning.utils.AafPropsUtils; import org.onap.dmaap.datarouter.provisioning.utils.DB; import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader; import org.onap.dmaap.datarouter.provisioning.utils.RLEBitSet; @@ -144,20 +145,21 @@ public class SynchronizerTask extends TimerTask { logger.info("PROV5000: Sync task starting, server podState is UNKNOWN_POD"); try { - Properties props = (new DB()).getProperties(); - String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks"); - String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY); - String pass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY); + // Set up keystore + String type = AafPropsUtils.KEYSTORE_TYPE_PROPERTY; + String store = Main.aafPropsUtils.getKeystorePathProperty(); + String pass = Main.aafPropsUtils.getKeystorePassProperty(); KeyStore keyStore = KeyStore.getInstance(type); try (FileInputStream instream = new FileInputStream(new File(store))) { keyStore.load(instream, pass.toCharArray()); } - store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY); - pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY); + // Set up truststore + store = Main.aafPropsUtils.getTruststorePathProperty(); + pass = Main.aafPropsUtils.getTruststorePassProperty(); KeyStore trustStore = null; if (store != null && store.length() > 0) { - trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); + trustStore = KeyStore.getInstance(AafPropsUtils.TRUESTSTORE_TYPE_PROPERTY); try (FileInputStream instream = new FileInputStream(new File(store))) { trustStore.load(instream, pass.toCharArray()); @@ -166,7 +168,7 @@ public class SynchronizerTask extends TimerTask { // 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 = props.getProperty(Main.KEYSTORE_PASS_PROPERTY); + String keystorepass = Main.aafPropsUtils.getKeystorePassProperty(); try (AbstractHttpClient hc = new DefaultHttpClient()) { SSLSocketFactory socketFactory = (trustStore == null) @@ -177,18 +179,18 @@ public class SynchronizerTask extends TimerTask { hc.getConnectionManager().getSchemeRegistry().register(sch); httpclient = hc; } - setSynchTimer(props); + setSynchTimer(new DB().getProperties().getProperty( + "org.onap.dmaap.datarouter.provserver.sync_interval", "5000")); } catch (Exception e) { logger.warn("PROV5005: Problem starting the synchronizer: " + e); } } - private void setSynchTimer(Properties props) { + private void setSynchTimer(String strInterval) { // Run once every 5 seconds to check DNS, etc. long interval; try { - String str = props.getProperty("org.onap.dmaap.datarouter.provserver.sync_interval", "5000"); - interval = Long.parseLong(str); + interval = Long.parseLong(strInterval); } catch (NumberFormatException e) { interval = 5000L; } 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 new file mode 100644 index 00000000..68981599 --- /dev/null +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/AafPropsUtils.java @@ -0,0 +1,102 @@ +/* + * ============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 com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import org.onap.aaf.cadi.PropAccess; + +public class AafPropsUtils { + + private static AafPropsUtils aafPropsUtilsInstance = null; + private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(AafPropsUtils.class); + + public static final String DEFAULT_TRUSTSTORE = "/opt/app/osaaf/local/org.onap.dmaap-dr.trust.jks"; + public static final String KEYSTORE_TYPE_PROPERTY = "PKCS12"; + public static final String TRUESTSTORE_TYPE_PROPERTY = "jks"; + private static final String KEYSTORE_PATH_PROPERTY = "cadi_keystore"; + private static final String KEYSTORE_PASS_PROPERTY = "cadi_keystore_password_p12"; + private static final String TRUSTSTORE_PATH_PROPERTY = "cadi_truststore"; + private static final String TRUSTSTORE_PASS_PROPERTY = "cadi_truststore_password"; + + private PropAccess propAccess; + + private AafPropsUtils(File propsFile) throws IOException { + propAccess = new PropAccess(); + try { + propAccess.load(new FileInputStream(propsFile)); + } catch (IOException e) { + eelfLogger.error("Failed to load props file: " + propsFile + "\n" + e.getMessage(), e); + throw e; + } + } + + public static synchronized void init(File propsFile) throws IOException { + if (aafPropsUtilsInstance != null) { + throw new IllegalStateException("Already initialized"); + } + aafPropsUtilsInstance = new AafPropsUtils(propsFile); + } + + public static AafPropsUtils getInstance() { + if (aafPropsUtilsInstance == null) { + throw new IllegalStateException("Call AafPropsUtils.init(File propsFile) first"); + } + return aafPropsUtilsInstance; + } + + private String decryptedPass(String password) { + String decryptedPass = null; + try { + decryptedPass = propAccess.decrypt(password, false); + } catch (IOException e) { + eelfLogger.error("Failed to decrypt " + password + " : " + e.getMessage(), e); + } + return decryptedPass; + } + + public PropAccess getPropAccess() { + if (propAccess == null) { + throw new IllegalStateException("Call AafPropsUtils.init(File propsFile) first"); + } + return propAccess; + } + + public String getKeystorePathProperty() { + return propAccess.getProperty(KEYSTORE_PATH_PROPERTY); + } + + public String getKeystorePassProperty() { + return decryptedPass(propAccess.getProperty(KEYSTORE_PASS_PROPERTY)); + } + + public String getTruststorePathProperty() { + return propAccess.getProperty(TRUSTSTORE_PATH_PROPERTY); + } + + public String getTruststorePassProperty() { + return decryptedPass(propAccess.getProperty(TRUSTSTORE_PASS_PROPERTY)); + } + +} diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java index 340b4213..a83f81a5 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java @@ -114,8 +114,7 @@ public class DB { synchronized (queue) {
try {
connection = queue.remove();
- } catch (NoSuchElementException nseEx) {
- intlogger.error("PROV9006 No connection on queue: " + nseEx.getMessage(), nseEx);
+ } catch (NoSuchElementException ignore) {
int num = 0;
do {
// Try up to 3 times to get a connection
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 867d1163..f078d80e 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 @@ -23,6 +23,8 @@ package org.onap.dmaap.datarouter.provisioning.utils;
+import static java.lang.System.exit;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.io.File;
@@ -96,9 +98,9 @@ public class DRRouteCLI { }
}
- public static final String ENV_VAR = "PROVSRVR";
- public static final String PROMPT = "dr-route> ";
- public static final String DEFAULT_TRUSTSTORE_PATH = /* $JAVA_HOME + */ "/jre/lib/security/cacerts";
+ private static final String ENV_VAR = "PROVSRVR";
+ private static final String PROMPT = "dr-route> ";
+ private static final String DEFAULT_TRUSTSTORE_PATH = /* $JAVA_HOME + */ "/jre/lib/security/cacerts";
private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
private final String server;
@@ -113,12 +115,20 @@ public class DRRouteCLI { */
public DRRouteCLI(String server) throws Exception {
this.server = server;
- this.width = 120;
this.httpclient = new DefaultHttpClient();
- Properties prop = (new DB()).getProperties();
- String truststoreFile = prop.getProperty("org.onap.dmaap.datarouter.provserver.truststore.path");
- String truststorePw = prop.getProperty("org.onap.dmaap.datarouter.provserver.truststore.password");
+ Properties provProperties = (new DB()).getProperties();
+ try {
+ AafPropsUtils.init(new File(provProperties.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);
+ }
+
+ String truststoreFile = AafPropsUtils.getInstance().getTruststorePathProperty();
+ String truststorePw = AafPropsUtils.getInstance().getTruststorePassProperty();
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
if (truststoreFile == null || truststoreFile.equals("")) {
@@ -139,8 +149,8 @@ public class DRRouteCLI { } finally {
try {
instream.close();
- } catch (Exception ignore) {
- intlogger.error("Ignore error closing input stream: " + ignore.getMessage(), ignore);
+ } catch (Exception e) {
+ intlogger.error("Ignore error closing input stream: " + e.getMessage(), e);
}
}
}
@@ -178,7 +188,7 @@ public class DRRouteCLI { * @param args The command line arguments.
* @return true if the command was valid and succeeded
*/
- public boolean runCommand(String[] args) {
+ boolean runCommand(String[] args) {
String cmd = args[0].trim().toLowerCase();
if (cmd.equals("add")) {
if (args.length > 2) {
@@ -471,12 +481,12 @@ public class DRRouteCLI { return rv;
}
- private void printErrorText(HttpEntity entity) throws IllegalStateException, IOException {
+ private void printErrorText(HttpEntity entity) throws IOException {
// Look for and print only the part of the output between <pre>...</pre>
InputStream is = entity.getContent();
StringBuilder sb = new StringBuilder();
byte[] bite = new byte[512];
- int num = 0;
+ int num;
while ((num = is.read(bite)) > 0) {
sb.append(new String(bite, 0, num));
}
|