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.node;
27 import org.apache.log4j.Logger;
33 * Determine if an IP address is from a machine
36 private long nextcheck;
39 private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.IsFrom");
42 * Configure the JVM DNS cache to have a 10 second TTL. This needs to be called very very early or it won't have any effect.
44 public static void setDNSCache() {
45 java.security.Security.setProperty("networkaddress.cache.ttl", "10");
49 * Create an IsFrom for the specified fully qualified domain name.
51 public IsFrom(String fqdn) {
56 * Check if an IP address matches. If it has been more than
57 * 10 seconds since DNS was last checked for changes to the
58 * IP address(es) of this FQDN, check again. Then check
59 * if the specified IP address belongs to the FQDN.
61 public synchronized boolean isFrom(String ip) {
62 long now = System.currentTimeMillis();
63 if (now > nextcheck) {
64 nextcheck = now + 10000;
65 Vector<String> v = new Vector<>();
67 InetAddress[] addrs = InetAddress.getAllByName(fqdn);
68 for (InetAddress a : addrs) {
69 v.add(a.getHostAddress());
71 } catch (UnknownHostException e) {
72 logger.debug("IsFrom: UnknownHostEx: " + e.toString(), e);
74 ips = v.toArray(new String[v.size()]);
75 logger.info("IsFrom: DNS ENTRIES FOR FQDN " + fqdn + " : " + Arrays.toString(ips));
77 for (String s : ips) {
78 if (s.equals(ip) || s.equals(System.getenv("DMAAP_DR_PROV_SERVICE_HOST"))) {
86 * Return the fully qualified domain name
88 public String toString() {