X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2FBaseServlet.java;h=d916a21c0622c2680ef5e10378b309b0157a5d6b;hb=14b8d9552808063686e0c22760cec6e35b960b59;hp=6ed5d8b623dee489a4716be3ab1b8cecf0bb4df9;hpb=a9ebff578a1ce292c4d410446da7e9292250578d;p=dmaap%2Fdatarouter.git 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 old mode 100644 new mode 100755 index 6ed5d8b6..d916a21c --- 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 @@ -28,6 +28,9 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN; 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; @@ -36,18 +39,13 @@ import java.net.UnknownHostException; 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; @@ -66,8 +64,17 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB; 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; @@ -103,9 +110,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { //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"; @@ -121,7 +126,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { 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 /** @@ -139,11 +143,11 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { /** * The set of authorized addresses and networks; pulled from the DB (PROV_AUTH_ADDRESSES) */ - private static Set authorizedAddressesAndNetworks = new HashSet(); + private static Set authorizedAddressesAndNetworks = new HashSet<>(); /** * The set of authorized names; pulled from the DB (PROV_AUTH_SUBJECTS) */ - private static Set authorizedNames = new HashSet(); + private static Set authorizedNames = new HashSet<>(); /** * The FQDN of the initially "active" provisioning server in this Data Router ecosystem */ @@ -199,19 +203,13 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { /** * 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 /** @@ -273,7 +271,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { try { thishost = InetAddress.getLocalHost(); loopback = InetAddress.getLoopbackAddress(); - checkHttpsRelaxation(); //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. + //checkHttpsRelaxation(); //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. } catch (UnknownHostException e) { // ignore } @@ -319,7 +317,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { * @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? @@ -369,7 +367,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { boolean isAuthorizedForInternal(HttpServletRequest request) { try { - if (Boolean.parseBoolean(isAddressAuthEnabled)) { + if (!Boolean.parseBoolean(isAddressAuthEnabled)) { return true; } InetAddress ip = InetAddress.getByName(request.getRemoteAddr()); @@ -389,13 +387,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { 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 } @@ -473,7 +464,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { 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, ""); @@ -492,9 +482,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { // 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()); @@ -520,9 +507,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { 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()); @@ -556,7 +540,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { mailprops.load(inStream); } catch (IOException e) { intlogger.fatal("PROV9003 Opening properties: " + e.getMessage()); - e.printStackTrace(); System.exit(1); } finally { try { @@ -575,13 +558,13 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { private void checkHttpsRelaxation() { if (!mailSendFlag) { Properties p = (new DB()).getProperties(); - intlogger.info("HTTPS relaxatio: " + p.get("org.onap.dmaap.datarouter.provserver.https.relaxation")); + intlogger.info("HTTPS relaxation: " + p.get("org.onap.dmaap.datarouter.provserver.https.relaxation")); if (p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").equals("true")) { 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; @@ -636,6 +619,13 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { } } + public static String getProvName() { + return provName; + } + + public static String getActiveProvName() { + return activeProvName; + } /** * Get an array of all node names in the DR network. @@ -711,7 +701,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { } catch (SQLException e) { rv = false; intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - e.printStackTrace(); } finally { if (conn != null) { db.release(conn); @@ -736,7 +725,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { } catch (SQLException e) { rv = false; intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - e.printStackTrace(); } finally { if (conn != null) { db.release(conn); @@ -761,7 +749,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { } catch (SQLException e) { rv = false; intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - e.printStackTrace(); } finally { if (conn != null) { db.release(conn); @@ -790,7 +777,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { } private static Set getSet(Map map, String name) { - Set set = new HashSet(); + Set set = new HashSet<>(); String s = map.get(name); if (s != null) { String[] pp = s.split("\\|"); @@ -813,7 +800,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { public class ContentHeader { private String type = ""; - private Map map = new HashMap(); + private Map map = new HashMap<>(); ContentHeader() { this("", "1.0"); @@ -924,7 +911,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { return true; } } catch (JSONException e) { - e.printStackTrace(); + intlogger.error("JSONException: " + e.getMessage()); } } return false; @@ -984,17 +971,36 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { } /* - * @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()); } }