Record Class ClientOrigin

java.lang.Object
java.lang.Record
com.jsgalactic.axiom.security.ClientOrigin
Record Components:
address - the client address: the transport peer, or the forwarded address when the peer is a trusted proxy
scheme - http or https
forwarded - true when the values come from headers set by trusted proxies rather than from the connection itself
host - the host the client addressed, as validated by TrustedProxies: a DNS name in lower case, an IPv4 literal, or an IPv6 literal in brackets; empty when no trusted proxy reported a usable one
port - the port the client addressed, 1 to 65535; empty when no trusted proxy reported a usable one (no default is inferred from the scheme)

public record ClientOrigin(InetAddress address, String scheme, boolean forwarded, Optional<String> host, OptionalInt port) extends Record
Where a request came from, as decided by TrustedProxies: the client's IP address, the scheme it used and, when a trusted proxy reported them, the host and port it addressed. Immutable.
  • Constructor Details

    • ClientOrigin

      public ClientOrigin(InetAddress address, String scheme, boolean forwarded, Optional<String> host, OptionalInt port)
      Validates the origin.
      Parameters:
      address - client address
      scheme - http or https
      forwarded - whether proxy headers supplied the values
      host - reported host, if any
      port - reported port, if any
      Throws:
      IllegalArgumentException - for another scheme
    • ClientOrigin

      public ClientOrigin(InetAddress address, String scheme, boolean forwarded)
      Creates an origin without a reported host or port.
      Parameters:
      address - client address
      scheme - http or https
      forwarded - whether proxy headers supplied the values
      Throws:
      IllegalArgumentException - for another scheme
  • Method Details

    • secure

      public boolean secure()
      Reports whether the client used HTTPS.
      Returns:
      true for https
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • address

      public InetAddress address()
      Returns the value of the address record component.
      Returns:
      the value of the address record component
    • scheme

      public String scheme()
      Returns the value of the scheme record component.
      Returns:
      the value of the scheme record component
    • forwarded

      public boolean forwarded()
      Returns the value of the forwarded record component.
      Returns:
      the value of the forwarded record component
    • host

      public Optional<String> host()
      Returns the value of the host record component.
      Returns:
      the value of the host record component
    • port

      public OptionalInt port()
      Returns the value of the port record component.
      Returns:
      the value of the port record component