Record Class BindPolicy

java.lang.Object
java.lang.Record
com.tnsai.server.security.BindPolicy

public record BindPolicy(String host, boolean allowPublic) extends Record
Bind policy for the HTTP/WS listener (TNS-302).

Defaults to 127.0.0.1 (loopback). Non-loopback binds — including 0.0.0.0, IPv4 LAN addresses, and any non-localhost hostname — require the explicit allowPublic=true opt-in. Without that flag, validate() throws IllegalStateException so the JVM exits before opening a public listener.

The policy is the first defence layer of the server-hardening surface: even if every other check (auth, capability tokens, workspace allowlist) is misconfigured, a strict loopback bind keeps the blast radius to the local machine.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    BindPolicy(String host, boolean allowPublic)
    Creates an instance of a BindPolicy record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns the value of the allowPublic record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the host record component.
    boolean
    Whether this host string addresses only the local machine.
    static BindPolicy
    Default policy: loopback bind, public access disabled.
    final String
    Returns a string representation of this record class.
    void
    Throws if the policy would open a non-loopback listener without explicit opt-in.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • BindPolicy

      public BindPolicy(String host, boolean allowPublic)
      Creates an instance of a BindPolicy record class.
      Parameters:
      host - the value for the host record component
      allowPublic - the value for the allowPublic record component
  • Method Details

    • loopback

      public static BindPolicy loopback()
      Default policy: loopback bind, public access disabled.
    • isLoopback

      public boolean isLoopback()
      Whether this host string addresses only the local machine.
    • validate

      public void validate()
      Throws if the policy would open a non-loopback listener without explicit opt-in. Call once during startup, before Javalin.start(host, port).
    • 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.
    • host

      public String host()
      Returns the value of the host record component.
      Returns:
      the value of the host record component
    • allowPublic

      public boolean allowPublic()
      Returns the value of the allowPublic record component.
      Returns:
      the value of the allowPublic record component