import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+
+
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.X509Certificate;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.onap.dmaap.datarouter.provisioning.utils.ThrottleFilter;
import org.json.JSONException;
import org.slf4j.MDC;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.UUID;
import java.util.regex.Pattern;
import javax.mail.Message;
import javax.mail.MessagingException;
//Adding groups functionality, ...1610
static final String GROUP_BASECONTENT_TYPE = "application/vnd.att-dr.group";
- public static final String GROUP_CONTENT_TYPE = "application/vnd.att-dr.group; version=2.0";
static final String GROUPFULL_CONTENT_TYPE = "application/vnd.att-dr.group-full; version=2.0";
- public static final String GROUPLIST_CONTENT_TYPE = "application/vnd.att-dr.fegrouped-list; version=1.0";
public static final String LOGLIST_CONTENT_TYPE = "application/vnd.att-dr.log-list; version=1.0";
private static final int DEFAULT_POKETIMER2 = 30;
private static final String DEFAULT_DOMAIN = "onap";
private static final String DEFAULT_PROVSRVR_NAME = "dmaap-dr-prov";
- private static final String RESEARCH_SUBNET = "10.42.0.0/16";
private static final String STATIC_ROUTING_NODES = ""; //Adding new param for static Routing - Rally:US664862-1610
/**
/**
* The set of authorized addresses and networks; pulled from the DB (PROV_AUTH_ADDRESSES)
*/
- private static Set<String> authorizedAddressesAndNetworks = new HashSet<String>();
+ private static Set<String> authorizedAddressesAndNetworks = new HashSet<>();
/**
* The set of authorized names; pulled from the DB (PROV_AUTH_SUBJECTS)
*/
- private static Set<String> authorizedNames = new HashSet<String>();
+ private static Set<String> authorizedNames = new HashSet<>();
/**
* The FQDN of the initially "active" provisioning server in this Data Router ecosystem
*/
/**
* The standard FQDN of the provisioning server in this Data Router ecosystem
*/
- public static String provName = "feeds-drtr.web.att.com";
+ private static String provName = "feeds-drtr.web.att.com";
+
/**
* The standard FQDN of the ACTIVE provisioning server in this Data Router ecosystem
*/
- public static String activeProvName = "feeds-drtr.web.att.com";
- /**
- * Special subnet that is allowed access to /internal
- */
- private static String researchSubnet = RESEARCH_SUBNET;
- /**
- * Special subnet that is allowed access to /internal to Lab Machine
- */
- private static String researchSubnet1 = RESEARCH_SUBNET;
+ private static String activeProvName = "feeds-drtr.web.att.com";
+
private static String staticRoutingNodes = STATIC_ROUTING_NODES; //Adding new param for static Routing - Rally:US664862-1610
/**
* @return an error string, or null if all is OK
*/
String isAuthorizedForProvisioning(HttpServletRequest request) {
- if (Boolean.parseBoolean(isAddressAuthEnabled)) {
+ if (!Boolean.parseBoolean(isAddressAuthEnabled)) {
return null;
}
// Is the request https?
boolean isAuthorizedForInternal(HttpServletRequest request) {
try {
- if (Boolean.parseBoolean(isAddressAuthEnabled)) {
+ if (!Boolean.parseBoolean(isAddressAuthEnabled)) {
return true;
}
InetAddress ip = InetAddress.getByName(request.getRemoteAddr());
if (loopback != null && ip.equals(loopback)) {
return true;
}
- // Also allow the "special subnet" access
- if (addressMatchesNetwork(ip, researchSubnet1)) {
- return true;
- }
- if (addressMatchesNetwork(ip, researchSubnet)) {
- return true;
- }
} catch (UnknownHostException e) {
// ignore
}
provDomain = getString(map, Parameters.PROV_DOMAIN, DEFAULT_DOMAIN);
provName = getString(map, Parameters.PROV_NAME, DEFAULT_PROVSRVR_NAME);
activeProvName = getString(map, Parameters.PROV_ACTIVE_NAME, provName);
- researchSubnet = getString(map, Parameters.PROV_SPECIAL_SUBNET, RESEARCH_SUBNET);
staticRoutingNodes = getString(map, Parameters.STATIC_ROUTING_NODES,
""); //Adding new param for static Routing - Rally:US664862-1610
initialActivePod = getString(map, Parameters.ACTIVE_POD, "");
// Normalize the nodes, and fill in nodeAddresses
InetAddress[] na = new InetAddress[nodes.length];
for (int i = 0; i < nodes.length; i++) {
- if (nodes[i].indexOf('.') < 0) {
- nodes[i] += "." + provDomain;
- }
try {
na[i] = InetAddress.getByName(nodes[i]);
intlogger.debug("PROV0003 DNS lookup: " + nodes[i] + " => " + na[i].toString());
String[] pods = getPods();
na = new InetAddress[pods.length];
for (int i = 0; i < pods.length; i++) {
- if (pods[i].indexOf('.') < 0) {
- pods[i] += "." + provDomain;
- }
try {
na[i] = InetAddress.getByName(pods[i]);
intlogger.debug("PROV0003 DNS lookup: " + pods[i] + " => " + na[i].toString());
mailprops.load(inStream);
} catch (IOException e) {
intlogger.fatal("PROV9003 Opening properties: " + e.getMessage());
- e.printStackTrace();
System.exit(1);
} finally {
try {
try {
notifyPSTeam(p.get("org.onap.dmaap.datarouter.provserver.https.relax.notify").toString());
} catch (Exception e) {
- e.printStackTrace();
+ intlogger.warn("Exception: " + e.getMessage());
}
}
mailSendFlag = true;
}
}
+ public static String getProvName() {
+ return provName;
+ }
+
+ public static String getActiveProvName() {
+ return activeProvName;
+ }
/**
* Get an array of all node names in the DR network.
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0005 doInsert: " + e.getMessage());
- e.printStackTrace();
} finally {
if (conn != null) {
db.release(conn);
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
- e.printStackTrace();
} finally {
if (conn != null) {
db.release(conn);
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0007 doDelete: " + e.getMessage());
- e.printStackTrace();
} finally {
if (conn != null) {
db.release(conn);
}
private static Set<String> getSet(Map<String, String> map, String name) {
- Set<String> set = new HashSet<String>();
+ Set<String> set = new HashSet<>();
String s = map.get(name);
if (s != null) {
String[] pp = s.split("\\|");
public class ContentHeader {
private String type = "";
- private Map<String, String> map = new HashMap<String, String>();
+ private Map<String, String> map = new HashMap<>();
ContentHeader() {
this("", "1.0");
return true;
}
} catch (JSONException e) {
- e.printStackTrace();
+ intlogger.error("JSONException: " + e.getMessage());
}
}
return false;
}
/*
- * @Method - setIpAndFqdnForEelf - Rally:US664892
+ * @Method - setIpFqdnRequestIDandInvocationIDForEelf
+ * @Params - method, prints method name in EELF log.
+ * @Params- Req, Request used to get RequestId and InvocationId
+ */
+ void setIpFqdnRequestIDandInvocationIDForEelf(String method, HttpServletRequest req) {
+ setIpFqdnForEelf(method);
+ setMDC(req, "X-ONAP-RequestID", MDC_KEY_REQUEST_ID);
+ setMDC(req, "X-InvocationID", "InvocationId");
+ }
+
+ void setMDC(HttpServletRequest req, String headerName, String keyName) {
+ String mdcId = req.getHeader(headerName);
+ if (StringUtils.isBlank(mdcId)) {
+ mdcId = UUID.randomUUID().toString();
+ }
+ MDC.put(keyName, mdcId);
+ }
+
+ /*
+ * @Method - setIpFqdnRequestIdForEelf - Rally:US664892
* @Params - method, prints method name in EELF log.
*/
- void setIpAndFqdnForEelf(String method) {
+ void setIpFqdnForEelf(String method) {
MDC.clear();
MDC.put(MDC_SERVICE_NAME, method);
try {
MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
} catch (Exception e) {
- e.printStackTrace();
+ intlogger.error("Exception: " + e.getMessage());
}
}