Package com.tnsai.server.security
Record Class BindPolicy
java.lang.Object
java.lang.Record
com.tnsai.server.security.BindPolicy
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 -
Constructor Summary
ConstructorsConstructorDescriptionBindPolicy(String host, boolean allowPublic) Creates an instance of aBindPolicyrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the value of theallowPublicrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.host()Returns the value of thehostrecord component.booleanWhether this host string addresses only the local machine.static BindPolicyloopback()Default policy: loopback bind, public access disabled.final StringtoString()Returns a string representation of this record class.voidvalidate()Throws if the policy would open a non-loopback listener without explicit opt-in.
-
Field Details
-
DEFAULT_HOST
- See Also:
-
-
Constructor Details
-
BindPolicy
Creates an instance of aBindPolicyrecord class.- Parameters:
host- the value for thehostrecord componentallowPublic- the value for theallowPublicrecord component
-
-
Method Details
-
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, beforeJavalin.start(host, port). -
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
host
Returns the value of thehostrecord component.- Returns:
- the value of the
hostrecord component
-
allowPublic
public boolean allowPublic()Returns the value of theallowPublicrecord component.- Returns:
- the value of the
allowPublicrecord component
-