protected boolean isValidAuthority(String authority) {
if (authority == null) {
return false;
}
InetAddressValidator inetAddressValidator =
InetAddressValidator.getInstance();
Matcher authorityMatcher = AUTHORITY_PATTERN.matcher(authority);
if (!authorityMatcher.matches()) {
return false;
}
boolean hostname = false;
// check if authority is IP address or hostname
String hostIP = authorityMatcher.group(PARSE_AUTHORITY_HOST_IP);
boolean ipV4Address = inetAddressValidator.isValid(hostIP);
if (!ipV4Address) {
// Domain is hostname name
hostname = DOMAIN_PATTERN.matcher(hostIP).matches();
}