Interface InetAddressFilter

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface InetAddressFilter
Strategy interface used for InetAddress-based filtering.

Allow HTTP clients to offer Server-Side Request Forgery (SSRF) mitigation features, for example by only allowing local addresses to be called.

Filters are typically built using the static factory methods on this interface, optionally combined with one or more of the logic methods. For example:

InetAddressFilter.of("192.168.0.0/24")
        .andNot("192.168.0.1");
Since:
4.1.0
See Also:
  • Method Details

    • matches

      default boolean matches(InetSocketAddress address)
      Determine whether the given socket address matches.
      Parameters:
      address - the socket address string to check
      Returns:
      if the address matches
    • matches

      boolean matches(InetAddress address)
      Whether the given address matches.
      Parameters:
      address - the address to check
      Returns:
      if the address matches
    • and

      default InetAddressFilter and(String... addresses)
      Return a composed filter that represents a short-circuiting logical AND of this filter and other IP addresses.
      Parameters:
      addresses - the addresses that will be logically-ANDed with this filter in any form supported by of(String...)
      Returns:
      a new composed filter instance
    • and

      default InetAddressFilter and(InetAddressFilter... filters)
      Return a composed filter that represents a short-circuiting logical AND of this filter and other filters.
      Parameters:
      filters - the filters that will be logically-ANDed with this filter
      Returns:
      a new composed filter instance
    • and

      default InetAddressFilter and(Collection<? extends InetAddressFilter> filters)
      Return a composed filter that represents a short-circuiting logical AND of this filter and other filters.
      Parameters:
      filters - the filters that will be logically-ANDed with this filter
      Returns:
      a new composed filter instance
    • andNot

      default InetAddressFilter andNot(String... addresses)
      Return a composed filter that represents a short-circuiting logical AND of this filter and other negated IP addresses.
      Parameters:
      addresses - the addresses that will be negated and logically-ANDed with this filter in any form supported by of(String...)
      Returns:
      a new composed filter instance
    • andNot

      default InetAddressFilter andNot(InetAddressFilter... filters)
      Return a composed filter that represents a short-circuiting logical AND of this filter and other negated filters.
      Parameters:
      filters - the filters that will be negated and logically-ANDed with this filter
      Returns:
      a new composed filter instance
    • andNot

      default InetAddressFilter andNot(Collection<? extends InetAddressFilter> filters)
      Return a composed filter that represents a short-circuiting logical AND of this filter and other negated filters.
      Parameters:
      filters - the filters that will be negated and logically-ANDed with this filter
      Returns:
      a new composed filter instance
    • or

      default InetAddressFilter or(String... addresses)
      Return a composed filter that represents a short-circuiting logical OR of this filter and other IP addresses.
      Parameters:
      addresses - the addresses that will be logically-ORed with this filter in any form supported by of(String...)
      Returns:
      a new composed filter instance
    • or

      default InetAddressFilter or(InetAddressFilter... filters)
      Return a composed filter that represents a short-circuiting logical OR of this filter and other filters.
      Parameters:
      filters - the matchers that will be logically-ORed with this filter
      Returns:
      a new composed filter instance
    • or

      default InetAddressFilter or(Collection<? extends InetAddressFilter> filters)
      Return a composed filter that represents a short-circuiting logical OR of this filter and other filters.
      Parameters:
      filters - the filters that will be logically-ORed with this filter
      Returns:
      a new composed filter instance
    • negate

      default InetAddressFilter negate()
      Return a new filter that represents the logical negation of this filter.
      Returns:
      the negated filter
    • externalAddresses

      static InetAddressFilter externalAddresses()
      Return a filter that will match external (non-private) IP addresses. External addresses are all routable addresses that are not:
      Returns:
      a filter for external IP addresses
      See Also:
    • internalAddresses

      static InetAddressFilter internalAddresses()
      Return a filter that will match internal (private) IP addresses.

      Internal addresses include loopback addresses (127.0.0.0/8 for IPv4, ::1 for IPv6), private IPv4 address ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), and IPv6 Unique Local Addresses (fc00::/7).

      Returns:
      a filter for external IP addresses
      See Also:
    • routable

      static InetAddressFilter routable()
      Returns a filter that will match all routable addresses (not all zeros).
      Returns:
      a filter for routable IP addresses
    • multicast

      static InetAddressFilter multicast()
      Returns a filter that will match all multicast addresses.
      Returns:
      a filter for multicast IP addresses
    • specialPurpose

      static InetAddressFilter specialPurpose()
      Returns a filter that will match special purpose IP addresses as defined by RFC 6890.
      Returns:
      a filter for this network
    • not

      static InetAddressFilter not(String... addresses)
      Return a filter that is the negation of all the given addresses.
      Parameters:
      addresses - the addresses to negate in any form supported by of(String...)
      Returns:
      a negated filter
      See Also:
    • not

      static InetAddressFilter not(InetAddressFilter... filters)
      Return a filter that is the negation of all the given matchers.
      Parameters:
      filters - the filters to negate
      Returns:
      a negated filter
      See Also:
    • not

      static InetAddressFilter not(Collection<? extends InetAddressFilter> filters)
      Return a filter that is the negation of all the given filters.
      Parameters:
      filters - the filters to negate
      Returns:
      a negated filter
      See Also:
    • of

      static InetAddressFilter of(String... addresses)
      Return a filter that matches any of the given IP addresses. Address may be either a full IP address (e.g. 192.168.1.1) or an IP address block spcified using CIDR notations (for example 192.168.1.0/24). Both IPv4 and IPv6 addresses are supported.
      Parameters:
      addresses - the IP addresses to match
      Returns:
      a filter that matches any of the given addresses
    • of

      static InetAddressFilter of(InetAddressFilter... filters)
      Return a filter that matches any of the given filters.
      Parameters:
      filters - the filters to include
      Returns:
      a filter that matches any of the filters
    • of

      static InetAddressFilter of(Collection<? extends InetAddressFilter> filters)
      Return a filter that matches any of the given filters.
      Parameters:
      filters - the filters to include
      Returns:
      a filter that matches any of the filters
    • adapt

      static InetAddressFilter adapt(Predicate<@Nullable InetAddress> predicate)
      Adapt the given Predicate into an InetAddressFilter.
      Parameters:
      predicate - the predicate to adapt
      Returns:
      a filter that matches using the predicate
    • all

      static InetAddressFilter all()
      Return a filter that matches all addresses.
      Returns:
      a filter that matches all
    • none

      static InetAddressFilter none()
      Return a filter that matches no addresses.
      Returns:
      a filter that matches none