Class TlsOptions.Builder

java.lang.Object
com.jsgalactic.axiom.lifecycle.TlsOptions.Builder
Enclosing class:
TlsOptions

public static final class TlsOptions.Builder extends Object
Collects settings before build(). Not thread-safe; the built options are immutable.
  • Method Details

    • certificateChain

      public TlsOptions.Builder certificateChain(Path file)
      Sets the PEM file holding the server certificate followed by its intermediate issuers.
      Parameters:
      file - the certificate chain file
      Returns:
      this builder
    • privateKey

      public TlsOptions.Builder privateKey(Path file)
      Sets the PEM file holding the private key of the server certificate. The key must be unencrypted PKCS#8 (BEGIN PRIVATE KEY) with an RSA, EC or Ed25519 key.
      Parameters:
      file - the private key file
      Returns:
      this builder
    • sslContext

      public TlsOptions.Builder sslContext(Supplier<SSLContext> supplier)
      Takes the key material from an SSLContext, an alternative to the PEM files. The supplier is called at startup and on each reload, and may return a new context each time. The listener applies its own protocol, cipher suite, ALPN and client authentication settings to every connection; the context supplies the keys and, with requireClientCertificates(), the trust anchors.
      Parameters:
      supplier - produces the context; must not return null
      Returns:
      this builder
    • minimumProtocol

      public TlsOptions.Builder minimumProtocol(TlsOptions.Protocol protocol)
      Sets the oldest TLS version a client may negotiate. The default is TLS 1.2, which is also the oldest version this API allows.
      Parameters:
      protocol - the minimum version
      Returns:
      this builder
    • cipherSuites

      public TlsOptions.Builder cipherSuites(List<String> suites)
      Replaces the enabled cipher suites, in preference order. Names are JSSE standard names. Suites the JVM does not support are skipped, and at least one must remain.
      Parameters:
      suites - one or more suite names
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if empty or a name is blank
    • requireClientCertificates

      public TlsOptions.Builder requireClientCertificates(Path trustedCertificates)
      Turns on mutual TLS for PEM key material: clients must present a certificate that chains to one of the certificates in the file, or the handshake fails.
      Parameters:
      trustedCertificates - PEM file of the trusted client certificates or issuing authorities
      Returns:
      this builder
    • requireClientCertificates

      public TlsOptions.Builder requireClientCertificates()
      Turns on mutual TLS for an SSL context whose trust managers decide which client certificates are accepted.
      Returns:
      this builder
    • reloadInterval

      public TlsOptions.Builder reloadInterval(Duration interval)
      Checks the key files for changes at this interval and reloads them when one changed, as Server.reloadTls() does. A reload that fails is logged and counted, keeps the previous material, and is tried again at the next check. Off by default. It applies to PEM files only.
      Parameters:
      interval - 1 second to one day
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if out of range
    • clock

      public TlsOptions.Builder clock(Clock clock)
      Sets the clock that decides whether certificates are expired or not yet valid. Tests inject a fixed clock; the default is the system UTC clock.
      Parameters:
      clock - the clock
      Returns:
      this builder
    • build

      public TlsOptions build()
      Builds immutable options.
      Returns:
      the options
      Throws:
      IllegalStateException - if the key material is not exactly one of PEM files (both a chain and a key) or an SSL context supplier, if a client trust file is combined with an SSL context, or if polling is combined with an SSL context