1 /*******************************************************************************
2 * ============LICENSE_START==================================================
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
11 * * http://www.apache.org/licenses/LICENSE-2.0
13 * * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
25 package org.onap.dmaap.datarouter.provisioning;
27 import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
29 import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
30 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.net.InetAddress;
35 import java.net.UnknownHostException;
36 import java.security.cert.X509Certificate;
37 import java.sql.Connection;
38 import java.sql.SQLException;
39 import java.util.HashMap;
40 import java.util.HashSet;
43 import java.util.List;
44 import java.util.ArrayList;
46 import javax.servlet.ServletConfig;
47 import javax.servlet.ServletException;
48 import javax.servlet.http.HttpServlet;
49 import javax.servlet.http.HttpServletRequest;
51 import org.apache.log4j.Logger;
52 import org.json.JSONObject;
53 import org.json.JSONTokener;
54 import org.onap.dmaap.datarouter.authz.Authorizer;
55 import org.onap.dmaap.datarouter.authz.impl.ProvAuthorizer;
56 import org.onap.dmaap.datarouter.authz.impl.ProvDataProvider;
57 import org.onap.dmaap.datarouter.provisioning.beans.Deleteable;
58 import org.onap.dmaap.datarouter.provisioning.beans.Feed;
59 import org.onap.dmaap.datarouter.provisioning.beans.Group;
60 import org.onap.dmaap.datarouter.provisioning.beans.Insertable;
61 import org.onap.dmaap.datarouter.provisioning.beans.NodeClass;
62 import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
63 import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
64 import org.onap.dmaap.datarouter.provisioning.beans.Updateable;
65 import org.onap.dmaap.datarouter.provisioning.utils.DB;
66 import org.onap.dmaap.datarouter.provisioning.utils.ThrottleFilter;
67 import org.json.JSONException;
70 import java.util.Properties;
71 import java.util.regex.Pattern;
72 import javax.mail.Message;
73 import javax.mail.MessagingException;
74 import javax.mail.Multipart;
75 import javax.mail.Session;
76 import javax.mail.Transport;
77 import javax.mail.internet.AddressException;
78 import javax.mail.internet.InternetAddress;
79 import javax.mail.internet.MimeBodyPart;
80 import javax.mail.internet.MimeMessage;
81 import javax.mail.internet.MimeMultipart;
84 * This is the base class for all Servlets in the provisioning code. It provides standard constants and some common
88 * @version $Id: BaseServlet.java,v 1.16 2014/03/12 19:45:40 eby Exp $
90 @SuppressWarnings("serial")
91 public class BaseServlet extends HttpServlet implements ProvDataProvider {
93 public static final String BEHALF_HEADER = "X-ATT-DR-ON-BEHALF-OF";
94 static final String FEED_BASECONTENT_TYPE = "application/vnd.att-dr.feed";
95 public static final String FEED_CONTENT_TYPE = "application/vnd.att-dr.feed; version=2.0";
96 public static final String FEEDFULL_CONTENT_TYPE = "application/vnd.att-dr.feed-full; version=2.0";
97 public static final String FEEDLIST_CONTENT_TYPE = "application/vnd.att-dr.feed-list; version=1.0";
98 static final String SUB_BASECONTENT_TYPE = "application/vnd.att-dr.subscription";
99 public static final String SUB_CONTENT_TYPE = "application/vnd.att-dr.subscription; version=2.0";
100 public static final String SUBFULL_CONTENT_TYPE = "application/vnd.att-dr.subscription-full; version=2.0";
101 static final String SUBLIST_CONTENT_TYPE = "application/vnd.att-dr.subscription-list; version=1.0";
104 //Adding groups functionality, ...1610
105 static final String GROUP_BASECONTENT_TYPE = "application/vnd.att-dr.group";
106 public static final String GROUP_CONTENT_TYPE = "application/vnd.att-dr.group; version=2.0";
107 static final String GROUPFULL_CONTENT_TYPE = "application/vnd.att-dr.group-full; version=2.0";
108 public static final String GROUPLIST_CONTENT_TYPE = "application/vnd.att-dr.fegrouped-list; version=1.0";
111 public static final String LOGLIST_CONTENT_TYPE = "application/vnd.att-dr.log-list; version=1.0";
112 public static final String PROVFULL_CONTENT_TYPE1 = "application/vnd.att-dr.provfeed-full; version=1.0";
113 public static final String PROVFULL_CONTENT_TYPE2 = "application/vnd.att-dr.provfeed-full; version=2.0";
114 public static final String CERT_ATTRIBUTE = "javax.servlet.request.X509Certificate";
116 static final String DB_PROBLEM_MSG = "There has been a problem with the DB. It is suggested you try the operation again.";
118 private static final int DEFAULT_MAX_FEEDS = 10000;
119 private static final int DEFAULT_MAX_SUBS = 100000;
120 private static final int DEFAULT_POKETIMER1 = 5;
121 private static final int DEFAULT_POKETIMER2 = 30;
122 private static final String DEFAULT_DOMAIN = "onap";
123 private static final String DEFAULT_PROVSRVR_NAME = "dmaap-dr-prov";
124 private static final String RESEARCH_SUBNET = "10.42.0.0/16";
125 private static final String STATIC_ROUTING_NODES = ""; //Adding new param for static Routing - Rally:US664862-1610
128 * A boolean to trigger one time "provisioning changed" event on startup
130 private static boolean startmsgFlag = true;
132 * This POD should require SSL connections from clients; pulled from the DB (PROV_REQUIRE_SECURE)
134 private static boolean requireSecure = true;
136 * This POD should require signed, recognized certificates from clients; pulled from the DB (PROV_REQUIRE_CERT)
138 private static boolean requireCert = true;
140 * The set of authorized addresses and networks; pulled from the DB (PROV_AUTH_ADDRESSES)
142 private static Set<String> authorizedAddressesAndNetworks = new HashSet<String>();
144 * The set of authorized names; pulled from the DB (PROV_AUTH_SUBJECTS)
146 private static Set<String> authorizedNames = new HashSet<String>();
148 * The FQDN of the initially "active" provisioning server in this Data Router ecosystem
150 private static String initialActivePod;
152 * The FQDN of the initially "standby" provisioning server in this Data Router ecosystem
154 private static String initialStandbyPod;
156 * The FQDN of this provisioning server in this Data Router ecosystem
158 private static String thisPod;
160 * "Timer 1" - used to determine when to notify nodes of provisioning changes
162 private static long pokeTimer1;
164 * "Timer 2" - used to determine when to notify nodes of provisioning changes
166 private static long pokeTimer2;
168 * Array of nodes names and/or FQDNs
170 private static String[] nodes = new String[0];
172 * Array of node IP addresses
174 private static InetAddress[] nodeAddresses = new InetAddress[0];
176 * Array of POD IP addresses
178 private static InetAddress[] podAddresses = new InetAddress[0];
180 * The maximum number of feeds allowed; pulled from the DB (PROV_MAXFEED_COUNT)
182 static int maxFeeds = 0;
184 * The maximum number of subscriptions allowed; pulled from the DB (PROV_MAXSUB_COUNT)
186 static int maxSubs = 0;
188 * The current number of feeds in the system
190 static int activeFeeds = 0;
192 * The current number of subscriptions in the system
194 static int activeSubs = 0;
196 * The domain used to generate a FQDN from the "bare" node names
198 private static String provDomain = "web.att.com";
200 * The standard FQDN of the provisioning server in this Data Router ecosystem
202 public static String provName = "feeds-drtr.web.att.com";
204 * The standard FQDN of the ACTIVE provisioning server in this Data Router ecosystem
206 public static String activeProvName = "feeds-drtr.web.att.com";
208 * Special subnet that is allowed access to /internal
210 private static String researchSubnet = RESEARCH_SUBNET;
212 * Special subnet that is allowed access to /internal to Lab Machine
214 private static String researchSubnet1 = RESEARCH_SUBNET;
215 private static String staticRoutingNodes = STATIC_ROUTING_NODES; //Adding new param for static Routing - Rally:US664862-1610
218 * This logger is used to log provisioning events
220 protected static Logger eventlogger;
222 * This logger is used to log internal events (errors, etc.)
224 protected static Logger intlogger;
226 * Authorizer - interface to the Policy Engine
228 protected static Authorizer authz;
230 * The Synchronizer used to sync active DB to standby one
232 private static SynchronizerTask synctask = null;
234 //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
235 private InetAddress thishost;
236 private InetAddress loopback;
237 private static Boolean mailSendFlag = false;
239 private static final String MAILCONFIG_FILE = "mail.properties";
240 private static Properties mailprops;
242 //DMAAP-597 (Tech Dept) REST request source IP auth relaxation to accommodate OOM kubernetes deploy
243 private static String isAddressAuthEnabled = (new DB()).getProperties()
244 .getProperty("org.onap.dmaap.datarouter.provserver.isaddressauthenabled", "false");
247 * Initialize data common to all the provisioning server servlets.
249 protected BaseServlet() {
250 if (eventlogger == null) {
251 eventlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.events");
253 if (intlogger == null) {
254 intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
257 authz = new ProvAuthorizer(this);
260 startmsgFlag = false;
261 provisioningParametersChanged();
263 if (synctask == null) {
264 synctask = SynchronizerTask.getSynchronizer();
266 String name = this.getClass().getName();
267 intlogger.info("PROV0002 Servlet " + name + " started.");
271 public void init(ServletConfig config) throws ServletException {
274 thishost = InetAddress.getLocalHost();
275 loopback = InetAddress.getLoopbackAddress();
276 //checkHttpsRelaxation(); //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
277 } catch (UnknownHostException e) {
282 int getIdFromPath(HttpServletRequest req) {
283 String path = req.getPathInfo();
284 if (path == null || path.length() < 2) {
288 return Integer.parseInt(path.substring(1));
289 } catch (NumberFormatException e) {
295 * Read the request's input stream and return a JSONObject from it
297 * @param req the HTTP request
298 * @return the JSONObject, or null if the stream cannot be parsed
300 JSONObject getJSONfromInput(HttpServletRequest req) {
301 JSONObject jo = null;
303 jo = new JSONObject(new JSONTokener(req.getInputStream()));
304 if (intlogger.isDebugEnabled()) {
305 intlogger.debug("JSON: " + jo.toString());
307 } catch (Exception e) {
308 intlogger.info("Error reading JSON: " + e);
314 * Check if the remote host is authorized to perform provisioning. Is the request secure? Is it coming from an
315 * authorized IP address or network (configured via PROV_AUTH_ADDRESSES)? Does it have a valid client certificate
316 * (configured via PROV_AUTH_SUBJECTS)?
318 * @param request the request
319 * @return an error string, or null if all is OK
321 String isAuthorizedForProvisioning(HttpServletRequest request) {
322 if (!Boolean.parseBoolean(isAddressAuthEnabled)) {
325 // Is the request https?
326 if (requireSecure && !request.isSecure()) {
327 return "Request must be made over an HTTPS connection.";
330 // Is remote IP authorized?
331 String remote = request.getRemoteAddr();
333 boolean found = false;
334 InetAddress ip = InetAddress.getByName(remote);
335 for (String addrnet : authorizedAddressesAndNetworks) {
336 found |= addressMatchesNetwork(ip, addrnet);
339 return "Unauthorized address: " + remote;
341 } catch (UnknownHostException e) {
342 return "Unauthorized address: " + remote;
345 // Does remote have a valid certificate?
347 X509Certificate certs[] = (X509Certificate[]) request.getAttribute(CERT_ATTRIBUTE);
348 if (certs == null || certs.length == 0) {
349 return "Client certificate is missing.";
351 // cert[0] is the client cert
352 // see http://www.proto.research.att.com/java/java7/api/javax/net/ssl/SSLSession.html#getPeerCertificates()
353 String name = certs[0].getSubjectX500Principal().getName();
354 if (!authorizedNames.contains(name)) {
355 return "No authorized certificate found.";
364 * Check if the remote IP address is authorized to see the /internal URL tree.
366 * @param request the HTTP request
367 * @return true iff authorized
369 boolean isAuthorizedForInternal(HttpServletRequest request) {
372 if (!Boolean.parseBoolean(isAddressAuthEnabled)) {
375 InetAddress ip = InetAddress.getByName(request.getRemoteAddr());
376 for (InetAddress node : getNodeAddresses()) {
377 if (node != null && ip.equals(node)) {
381 for (InetAddress pod : getPodAddresses()) {
382 if (pod != null && ip.equals(pod)) {
386 if (thishost != null && ip.equals(thishost)) {
389 if (loopback != null && ip.equals(loopback)) {
392 // Also allow the "special subnet" access
393 if (addressMatchesNetwork(ip, researchSubnet1)) {
396 if (addressMatchesNetwork(ip, researchSubnet)) {
399 } catch (UnknownHostException e) {
406 * Check if an IP address matches a network address.
408 * @param ip the IP address
409 * @param s the network address; a bare IP address may be matched also
410 * @return true if they intersect
412 private static boolean addressMatchesNetwork(InetAddress ip, String s) {
414 int n = s.indexOf("/");
416 mlen = Integer.parseInt(s.substring(n + 1));
417 s = s.substring(0, n);
420 InetAddress i2 = InetAddress.getByName(s);
421 byte[] b1 = ip.getAddress();
422 byte[] b2 = i2.getAddress();
423 if (b1.length != b2.length) {
428 (byte) 0x00, (byte) 0x80, (byte) 0xC0, (byte) 0xE0,
429 (byte) 0xF0, (byte) 0xF8, (byte) 0xFC, (byte) 0xFE
431 byte mask = masks[mlen % 8];
432 for (n = mlen / 8; n < b1.length; n++) {
438 for (n = 0; n < b1.length; n++) {
439 if (b1[n] != b2[n]) {
443 } catch (UnknownHostException e) {
450 * Something has changed in the provisioning data. Start the timers that will cause the pre-packaged JSON string to
451 * be regenerated, and cause nodes and the other provisioning server to be notified.
453 public static void provisioningDataChanged() {
454 long now = System.currentTimeMillis();
455 Poker p = Poker.getPoker();
456 p.setTimers(now + (pokeTimer1 * 1000L), now + (pokeTimer2 * 1000L));
460 * Something in the parameters has changed, reload all parameters from the DB.
462 public static void provisioningParametersChanged() {
463 Map<String, String> map = Parameters.getParameters();
464 requireSecure = getBoolean(map, Parameters.PROV_REQUIRE_SECURE);
465 requireCert = getBoolean(map, Parameters.PROV_REQUIRE_CERT);
466 authorizedAddressesAndNetworks = getSet(map, Parameters.PROV_AUTH_ADDRESSES);
467 authorizedNames = getSet(map, Parameters.PROV_AUTH_SUBJECTS);
468 nodes = getSet(map, Parameters.NODES).toArray(new String[0]);
469 maxFeeds = getInt(map, Parameters.PROV_MAXFEED_COUNT, DEFAULT_MAX_FEEDS);
470 maxSubs = getInt(map, Parameters.PROV_MAXSUB_COUNT, DEFAULT_MAX_SUBS);
471 pokeTimer1 = getInt(map, Parameters.PROV_POKETIMER1, DEFAULT_POKETIMER1);
472 pokeTimer2 = getInt(map, Parameters.PROV_POKETIMER2, DEFAULT_POKETIMER2);
473 provDomain = getString(map, Parameters.PROV_DOMAIN, DEFAULT_DOMAIN);
474 provName = getString(map, Parameters.PROV_NAME, DEFAULT_PROVSRVR_NAME);
475 activeProvName = getString(map, Parameters.PROV_ACTIVE_NAME, provName);
476 researchSubnet = getString(map, Parameters.PROV_SPECIAL_SUBNET, RESEARCH_SUBNET);
477 staticRoutingNodes = getString(map, Parameters.STATIC_ROUTING_NODES,
478 ""); //Adding new param for static Routing - Rally:US664862-1610
479 initialActivePod = getString(map, Parameters.ACTIVE_POD, "");
480 initialStandbyPod = getString(map, Parameters.STANDBY_POD, "");
481 staticRoutingNodes = getString(map, Parameters.STATIC_ROUTING_NODES,
482 ""); //Adding new param for static Routing - Rally:US664862-1610
483 activeFeeds = Feed.countActiveFeeds();
484 activeSubs = Subscription.countActiveSubscriptions();
486 thisPod = InetAddress.getLocalHost().getHostName();
487 } catch (UnknownHostException e) {
489 intlogger.warn("PROV0014 Cannot determine the name of this provisioning server.");
492 // Normalize the nodes, and fill in nodeAddresses
493 InetAddress[] na = new InetAddress[nodes.length];
494 for (int i = 0; i < nodes.length; i++) {
496 na[i] = InetAddress.getByName(nodes[i]);
497 intlogger.debug("PROV0003 DNS lookup: " + nodes[i] + " => " + na[i].toString());
498 } catch (UnknownHostException e) {
500 intlogger.warn("PROV0004 Cannot lookup " + nodes[i] + ": " + e);
504 //Reset Nodes arr after - removing static routing Nodes, Rally Userstory - US664862 .
505 List<String> filterNodes = new ArrayList<>();
506 for (String node : nodes) {
507 if (!staticRoutingNodes.contains(node)) {
508 filterNodes.add(node);
511 nodes = filterNodes.toArray(new String[filterNodes.size()]);
514 NodeClass.setNodes(nodes); // update NODES table
516 // Normalize the PODs, and fill in podAddresses
517 String[] pods = getPods();
518 na = new InetAddress[pods.length];
519 for (int i = 0; i < pods.length; i++) {
521 na[i] = InetAddress.getByName(pods[i]);
522 intlogger.debug("PROV0003 DNS lookup: " + pods[i] + " => " + na[i].toString());
523 } catch (UnknownHostException e) {
525 intlogger.warn("PROV0004 Cannot lookup " + pods[i] + ": " + e);
530 // Update ThrottleFilter
531 ThrottleFilter.configure();
533 // Check if we are active or standby POD
534 if (!isInitialActivePOD() && !isInitialStandbyPOD()) {
535 intlogger.warn("PROV0015 This machine is neither the active nor the standby POD.");
541 * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. Load mail properties.
545 private void loadMailProperties() {
546 if (mailprops == null) {
547 mailprops = new Properties();
548 InputStream inStream = getClass().getClassLoader().getResourceAsStream(MAILCONFIG_FILE);
550 mailprops.load(inStream);
551 } catch (IOException e) {
552 intlogger.fatal("PROV9003 Opening properties: " + e.getMessage());
558 } catch (IOException e) {
565 * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. Check if HTTPS Relexaction is enabled
569 private void checkHttpsRelaxation() {
571 Properties p = (new DB()).getProperties();
572 intlogger.info("HTTPS relaxation: " + p.get("org.onap.dmaap.datarouter.provserver.https.relaxation"));
574 if (p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").equals("true")) {
576 notifyPSTeam(p.get("org.onap.dmaap.datarouter.provserver.https.relax.notify").toString());
577 } catch (Exception e) {
586 * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
588 * @param email - list of email ids to notify if HTTP relexcation is enabled.
591 private void notifyPSTeam(String email) throws Exception {
592 loadMailProperties(); //Load HTTPS Relex mail properties.
593 String[] emails = email.split(Pattern.quote("|"));
595 Properties mailproperties = new Properties();
596 mailproperties.put("mail.smtp.host", mailprops.get("com.att.dmaap.datarouter.mail.server"));
597 mailproperties.put("mail.transport.protocol", mailprops.get("com.att.dmaap.datarouter.mail.protocol"));
599 Session session = Session.getDefaultInstance(mailproperties, null);
600 Multipart mp = new MimeMultipart();
601 MimeBodyPart htmlPart = new MimeBodyPart();
605 Message msg = new MimeMessage(session);
606 msg.setFrom(new InternetAddress(mailprops.get("com.att.dmaap.datarouter.mail.from").toString()));
608 InternetAddress[] addressTo = new InternetAddress[emails.length];
609 for (int x = 0; x < emails.length; x++) {
610 addressTo[x] = new InternetAddress(emails[x]);
613 msg.addRecipients(Message.RecipientType.TO, addressTo);
614 msg.setSubject(mailprops.get("com.att.dmaap.datarouter.mail.subject").toString());
615 htmlPart.setContent(mailprops.get("com.att.dmaap.datarouter.mail.body").toString()
616 .replace("[SERVER]", InetAddress.getLocalHost().getHostName()), "text/html");
617 mp.addBodyPart(htmlPart);
620 System.out.println(mailprops.get("com.att.dmaap.datarouter.mail.body").toString()
621 .replace("[SERVER]", InetAddress.getLocalHost().getHostName()));
624 intlogger.info("HTTPS relaxation mail is sent to - : " + email);
626 } catch (AddressException e) {
627 intlogger.error("Invalid email address, unable to send https relaxation mail to - : " + email);
628 } catch (MessagingException e) {
629 intlogger.error("Invalid email address, unable to send https relaxation mail to - : " + email);
635 * Get an array of all node names in the DR network.
637 * @return an array of Strings
639 public static String[] getNodes() {
644 * Get an array of all node InetAddresses in the DR network.
646 * @return an array of InetAddresses
648 public static InetAddress[] getNodeAddresses() {
649 return nodeAddresses;
653 * Get an array of all POD names in the DR network.
655 * @return an array of Strings
657 public static String[] getPods() {
658 return new String[]{initialActivePod, initialStandbyPod};
662 * Get an array of all POD InetAddresses in the DR network.
664 * @return an array of InetAddresses
666 private static InetAddress[] getPodAddresses() {
671 * Gets the FQDN of the initially ACTIVE provisioning server (POD). Note: this used to be called isActivePOD(),
672 * however, that is a misnomer, as the active status could shift to the standby POD without these parameters
673 * changing. Hence, the function names have been changed to more accurately reflect their purpose.
677 public static boolean isInitialActivePOD() {
678 return thisPod.equals(initialActivePod);
682 * Gets the FQDN of the initially STANDBY provisioning server (POD). Note: this used to be called isStandbyPOD(),
683 * however, that is a misnomer, as the standby status could shift to the active POD without these parameters
684 * changing. Hence, the function names have been changed to more accurately reflect their purpose.
688 public static boolean isInitialStandbyPOD() {
689 return thisPod.equals(initialStandbyPod);
693 * INSERT an {@link Insertable} bean into the database.
695 * @param bean the bean representing a row to insert
696 * @return true if the INSERT was successful
698 protected boolean doInsert(Insertable bean) {
701 Connection conn = null;
703 conn = db.getConnection();
704 rv = bean.doInsert(conn);
705 } catch (SQLException e) {
707 intlogger.warn("PROV0005 doInsert: " + e.getMessage());
718 * UPDATE an {@link Updateable} bean in the database.
720 * @param bean the bean representing a row to update
721 * @return true if the UPDATE was successful
723 protected boolean doUpdate(Updateable bean) {
726 Connection conn = null;
728 conn = db.getConnection();
729 rv = bean.doUpdate(conn);
730 } catch (SQLException e) {
732 intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
743 * DELETE an {@link Deleteable} bean from the database.
745 * @param bean the bean representing a row to delete
746 * @return true if the DELETE was successful
748 protected boolean doDelete(Deleteable bean) {
751 Connection conn = null;
753 conn = db.getConnection();
754 rv = bean.doDelete(conn);
755 } catch (SQLException e) {
757 intlogger.warn("PROV0007 doDelete: " + e.getMessage());
767 private static boolean getBoolean(Map<String, String> map, String name) {
768 String s = map.get(name);
769 return (s != null) && s.equalsIgnoreCase("true");
772 private static String getString(Map<String, String> map, String name, String dflt) {
773 String s = map.get(name);
774 return (s != null) ? s : dflt;
777 private static int getInt(Map<String, String> map, String name, int dflt) {
779 String s = map.get(name);
780 return Integer.parseInt(s);
781 } catch (NumberFormatException e) {
786 private static Set<String> getSet(Map<String, String> map, String name) {
787 Set<String> set = new HashSet<String>();
788 String s = map.get(name);
790 String[] pp = s.split("\\|");
792 for (String t : pp) {
793 String t2 = t.trim();
794 if (t2.length() > 0) {
804 * A class used to encapsulate a Content-type header, separating out the "version" attribute (which defaults to
807 public class ContentHeader {
809 private String type = "";
810 private Map<String, String> map = new HashMap<String, String>();
816 ContentHeader(String t, String v) {
818 map.put("version", v);
821 public String getType() {
825 public String getAttribute(String key) {
826 String s = map.get(key);
835 * Get the ContentHeader from an HTTP request.
837 * @param req the request
838 * @return the header, encapsulated in a ContentHeader object
840 ContentHeader getContentHeader(HttpServletRequest req) {
841 ContentHeader ch = new ContentHeader();
842 String s = req.getHeader("Content-Type");
844 String[] pp = s.split(";");
845 ch.type = pp[0].trim();
846 for (int i = 1; i < pp.length; i++) {
847 int ix = pp[i].indexOf('=');
849 String k = pp[i].substring(0, ix).trim();
850 String v = pp[i].substring(ix + 1).trim();
853 ch.map.put(pp[i].trim(), "");
860 // Methods for the Policy Engine classes - ProvDataProvider interface
862 public String getFeedOwner(String feedId) {
864 int n = Integer.parseInt(feedId);
865 Feed f = Feed.getFeedById(n);
867 return f.getPublisher();
869 } catch (NumberFormatException e) {
876 public String getFeedClassification(String feedId) {
878 int n = Integer.parseInt(feedId);
879 Feed f = Feed.getFeedById(n);
881 return f.getAuthorization().getClassification();
883 } catch (NumberFormatException e) {
890 public String getSubscriptionOwner(String subId) {
892 int n = Integer.parseInt(subId);
893 Subscription s = Subscription.getSubscriptionById(n);
895 return s.getSubscriber();
897 } catch (NumberFormatException e) {
904 * @Method - isUserMemberOfGroup - Rally:US708115
905 * @Params - group object and user to check if exists in given group
906 * @return - boolean value /true/false
908 private boolean isUserMemberOfGroup(Group group, String user) {
910 String groupDetails = group.getMembers().replace("]", "").replace("[", "");
911 String[] s = groupDetails.split("},");
913 for (String value : s) {
916 jsonObj = new JSONObject(value + "}");
917 if (jsonObj.get("id").equals(user)) {
920 } catch (JSONException e) {
929 * @Method - getGroupByFeedGroupId- Rally:US708115
930 * @Params - User to check in group and feedid which is assigned the group.
931 * @return - string value grupid/null
934 public String getGroupByFeedGroupId(String owner, String feedId) {
936 int n = Integer.parseInt(feedId);
937 Feed f = Feed.getFeedById(n);
939 int groupid = f.getGroupid();
941 Group group = Group.getGroupById(groupid);
942 assert group != null;
943 if (isUserMemberOfGroup(group, owner)) {
944 return group.getAuthid();
948 } catch (NumberFormatException e) {
955 * @Method - getGroupBySubGroupId - Rally:US708115
956 * @Params - User to check in group and subid which is assigned the group.
957 * @return - string value grupid/null
960 public String getGroupBySubGroupId(String owner, String subId) {
962 int n = Integer.parseInt(subId);
963 Subscription s = Subscription.getSubscriptionById(n);
965 int groupid = s.getGroupid();
967 Group group = Group.getGroupById(groupid);
968 assert group != null;
969 if (isUserMemberOfGroup(group, owner)) {
970 return group.getAuthid();
974 } catch (NumberFormatException e) {
981 * @Method - setIpAndFqdnForEelf - Rally:US664892
982 * @Params - method, prints method name in EELF log.
984 void setIpAndFqdnForEelf(String method) {
986 MDC.put(MDC_SERVICE_NAME, method);
988 MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
989 MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
990 } catch (Exception e) {