boolean isInIpAddressRange(String cidr, String ipAddress) {
    Matcher matcher = IP_ADDRESS_RANGE_PATTERN.matcher(cidr);

    if (matcher.matches() && matcher.groupCount() == 2) {
      try {
        String hostSpecIPAddress = matcher.group(1);
        String hostSpecBits = matcher.group(2);
        int hostSpecIPAddressInt = ipAddressToInt(hostSpecIPAddress);
        int remoteAddressInt = ipAddressToInt(ipAddress);

        int mask = -1 << (32 - Integer.valueOf(hostSpecBits));
        return ((hostSpecIPAddressInt & mask) == (remoteAddressInt & mask));
      } catch (Throwable t) {
        LOG.warn("Invalid CIDR in host specification, skipping: " + cidr, t);
      }
    }

    return false;
  }
Determines if an IP address is in the subnet specified by the CIDR value.
<p>
The logic for ths method comes from an example found at
https://stackoverflow.com/questions/4209760/validate-an-ip-address-with-mask.
<p>
A CIDR is an IP address with a mask, denoting a subnet.  For example, <code>192.168.1.0/24</code> contains all
IP addresses in the range of <code>192.168.1.0</code> through <code>192.168.1.255</code>. See https://www.ipaddressguide.com/cidr
for an on-line calculator.

@param cidr      a CIDR
@param ipAddress the IP address to test
@return <code>true</code> if the IP Address is withing the range specified by the CIDR; <code>false</code> otherwise.
ambari-server/src/main/java/org/apache/ambari/server/security/authentication/kerberos/AmbariProxiedUserDetailsService.java