Class RemoteAddressValidator

java.lang.Object
org.apache.activemq.util.RemoteAddressValidator

public class RemoteAddressValidator extends Object
Validates a socket's remote IP address against configurable allow and deny lists expressed in CIDR notation (e.g. "192.168.1.0/24", "10.0.0.0/8").

Evaluation order:

  1. If the address matches any deny entry → DENIED.
  2. If the allow list is non-empty and the address matches any allow entry → ALLOWED.
  3. If the allow list is empty (no restrictions) → ALLOWED.
  4. Otherwise → DENIED (not in allow list).

Both IPv4 and IPv6 addresses are supported. IPv4-mapped IPv6 addresses (e.g. ::ffff:192.168.1.1) are automatically normalized to their IPv4 equivalent before matching, so a single IPv4 CIDR rule covers both plain IPv4 connections and dual-stack sockets that represent the same peer.

Build the lists with CidrListLoader, which accepts a comma separated string or a file: URI and reports entries it had to skip.

  • Constructor Details

    • RemoteAddressValidator

      public RemoteAddressValidator(List<Cidr> allowCidrs, List<Cidr> denyCidrs)
      Parameters:
      allowCidrs - CIDR strings that are explicitly permitted. Pass an empty list to permit all addresses.
      denyCidrs - CIDR strings that are explicitly forbidden. Deny rules are evaluated before allow rules.
  • Method Details

    • isAllowed

      public boolean isAllowed(Socket socket)
      Returns true if the remote address of the given socket is allowed.
      Throws:
      IllegalArgumentException - if the socket is not connected or has no remote address.
    • isAllowed

      public boolean isAllowed(InetAddress address)
      Returns true if the given InetAddress passes the allow/deny policy.
    • isAllowed

      public boolean isAllowed(String addressOrCidr)
      Runs a single IP address or a whole CIDR block through the allow/deny decision. A single address gets exactly the decision an accepted socket would: deny entries first, then the allow list, an empty allow list permitting, an IPv4-mapped IPv6 address normalised first. A block is judged as a whole: it is allowed when an allow entry covers it (or the allow list is empty) and no deny entry covers the entire block, so a few denied hosts carved out of an allowed network do not change its answer. Host names are rejected, never resolved.
      Throws:
      IllegalArgumentException - if the value is neither an IP literal nor a CIDR block