Class ControlPlaneAuthenticationHandlerFactory

java.lang.Object
org.mockserver.authentication.ControlPlaneAuthenticationHandlerFactory

public class ControlPlaneAuthenticationHandlerFactory extends Object
Builds the control-plane AuthenticationHandler chain from a Configuration.

This exists so the handler chain has exactly ONE construction site that is a pure function of the live configuration. Previously the chain was built once during server bootstrap and pushed into HttpState; enabling control-plane authentication afterwards (via a system property, a Configuration mutation, or PUT /mockserver/configuration) returned success but left the handler null, and a null handler means "authenticated" — so the control plane reported itself locked while remaining fully open. Deriving the handler from the configuration on demand, keyed by signature(Configuration), makes every configuration route take effect.

Fail closed. build(org.mockserver.configuration.Configuration, org.mockserver.logging.MockServerLogger) returns null only when no control-plane authentication is required. If authentication IS required but the handler cannot be constructed (bad JWKS source, unreadable CA chain, ...) it returns a handler that rejects every request rather than null, so a misconfiguration can never degrade into an open control plane.

  • Method Details

    • authenticationRequired

      public static boolean authenticationRequired(Configuration configuration)
      Returns:
      true if any control-plane authentication mechanism is enabled
    • signature

      public static String signature(Configuration configuration)
      A stable string capturing every configuration value that feeds handler construction. When this changes the cached handler must be discarded and rebuilt, which is how a runtime reconfiguration (system property, Configuration setter, DTO, or PUT /mockserver/configuration) reaches the enforcement point. Sorted collections keep the value order-independent so a semantically identical configuration does not force a pointless rebuild.
    • build

      public static AuthenticationHandler build(Configuration configuration, MockServerLogger mockServerLogger)
      Build the control-plane authentication handler for the supplied configuration.
      Returns:
      null when no control-plane authentication is required; otherwise a handler that enforces every enabled mechanism (chained when more than one is enabled), or a deny-all handler if construction failed