Record Class AuthConfig

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

public record AuthConfig(String bearerToken) extends Record
Authentication configuration for TnsServer (TNS-302).

When bearerToken() is non-blank, every HTTP request and every WS upgrade must present Authorization: Bearer <token>; missing or mismatched tokens are rejected with 401. The token also signs per-session capability tokens (see

invalid reference
CapabilityToken
).

When bearerToken() is null (or blank), HTTP/WS auth is disabled. This is permitted only when the server is bound to loopback (BindPolicy.isLoopback()); the constructor of TnsServer rejects non-loopback binds without a token. The combination is the back-compat path for local development.

The default token source for TnsServerMain is the TNSAI_TOKEN environment variable.

  • Field Summary

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

    Constructors
    Constructor
    Description
    AuthConfig(String bearerToken)
    Creates an instance of a AuthConfig record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the bearerToken record component.
    static AuthConfig
    Auth disabled — only valid combined with a loopback bind policy.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
     
    final String
    Returns a string representation of this record class.
    static AuthConfig
    Auth required with the given Bearer token.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • AuthConfig

      public AuthConfig(String bearerToken)
      Creates an instance of a AuthConfig record class.
      Parameters:
      bearerToken - the value for the bearerToken record component
  • Method Details

    • disabled

      public static AuthConfig disabled()
      Auth disabled — only valid combined with a loopback bind policy.
    • withToken

      public static AuthConfig withToken(String token)
      Auth required with the given Bearer token.
    • isEnabled

      public boolean isEnabled()
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • bearerToken

      public String bearerToken()
      Returns the value of the bearerToken record component.
      Returns:
      the value of the bearerToken record component