25
25
* This matcher supports both wildcard hostname patterns (e.g., *.example.com) and CIDR notation (e.g., 192.168.1.0/24).
26
26
*/
27
27
public class HostAndCidrMatcher {
28
- private static final String IP_HOSTNAME = "ip-hostname" ;
29
- private static final String IP_HOSTNAME_LOOKUP = "ip-hostname-lookup" ;
30
-
31
28
protected final Logger log = LogManager .getLogger (HostAndCidrMatcher .class );
32
29
private final WildcardMatcher hostMatcher ;
33
30
private final List <IPAddressString > cidrMatchers ;
@@ -66,7 +63,7 @@ public boolean matchesCidr(InetAddress address) {
66
63
return cidrMatchers .stream ().anyMatch (cidrAddress -> cidrAddress .contains (addressString ));
67
64
} catch (Exception e ) {
68
65
log .warn ("Failed to process IP address {}: {}" , address , e .getMessage ());
69
- return false ;
66
+ throw new RuntimeException ( "Invalid Address format used" ) ;
70
67
}
71
68
}
72
69
@@ -75,8 +72,7 @@ public boolean matchesCidr(InetAddress address) {
75
72
* This method can perform DNS lookups depending on the hostResolverMode.
76
73
*
77
74
* @param address The IP address to check
78
- * @param hostResolverMode The resolution mode. Must be either "ip-hostname" or
79
- * "ip-hostname-lookup" to enable hostname matching
75
+ * @param hostResolverMode The resolution mode. Must be one of {@link HostResolverMode} to enable hostname matching
80
76
* @return true if the address matches any configured hostname pattern, false otherwise,
81
77
* if the address is null, or if the resolver mode is invalid
82
78
* @implNote This method may perform DNS lookups which could impact performance
@@ -88,7 +84,8 @@ public boolean matchesHostname(InetAddress address, String hostResolverMode) {
88
84
89
85
List <String > valuesToCheck = new ArrayList <>(List .of (address .getHostAddress ()));
90
86
if (hostResolverMode != null
91
- && (hostResolverMode .equalsIgnoreCase (IP_HOSTNAME ) || hostResolverMode .equalsIgnoreCase (IP_HOSTNAME_LOOKUP ))) {
87
+ && (hostResolverMode .equalsIgnoreCase (HostResolverMode .IP_HOSTNAME .getValue ())
88
+ || hostResolverMode .equalsIgnoreCase (HostResolverMode .IP_HOSTNAME_LOOKUP .getValue ()))) {
92
89
try {
93
90
final String hostName = address .getHostName (); // potential blocking call
94
91
valuesToCheck .add (hostName );
0 commit comments