Class InfinispanStateBackend

java.lang.Object
org.mockserver.state.infinispan.InfinispanStateBackend
All Implemented Interfaces:
Closeable, AutoCloseable, StateBackend

public class InfinispanStateBackend extends Object implements StateBackend
Infinispan-backed StateBackend supporting both LOCAL (non-clustered) and CLUSTERED (JGroups transport, REPL_SYNC) modes.

LOCAL mode (default, clusterEnabled=false): single-node, no JGroups network transport, identical behaviour to Phase 2b. The Java serialization allow-list remains permissive (".*") because caches are heap-only with no network marshalling exposure.

CLUSTERED mode (clusterEnabled=true): starts a JGroups transport for multi-node state replication. Caches use REPL_SYNC so all writes are synchronously replicated to all cluster members. The Java serialization allow-list is tightened to an explicit set of packages covering exactly the types that cross the wire:

  • org.mockserver.state.infinispan.* (VersionedWrapper)
  • org.mockserver.state.* (ExpectationEntry)
  • org.mockserver.mock.* (Expectation, domain model)
  • org.mockserver.model.* (HttpRequest, HttpResponse, etc.)
  • org.mockserver.matchers.* (TimeToLive, Times)
  • com.fasterxml.jackson.* (ObjectNode for CRUD entities)
  • java.lang.*, java.util.*, java.time.* (primitives/wrappers, collections, time types)
This explicit allow-list resolves the P0 security gate from Phase 2b — deserialization gadget chains from untrusted packages are blocked.

Cluster invalidation: in CLUSTERED mode, Infinispan @Listener annotated listeners are attached to each cache. When a remote write arrives (replication from another node), the listener fires InvalidationListener.onChanged(String) or InvalidationListener.onCleared(), which triggers the node-local view rebuild in RequestMatchers.reconcileFromBackend().

  • Constructor Details

    • InfinispanStateBackend

      public InfinispanStateBackend(Configuration configuration)
      Creates an Infinispan state backend in the appropriate mode based on configuration. When configuration.clusterEnabled() is true, a JGroups-transported clustered cache manager is created; otherwise a LOCAL (non-clustered) manager is used.
      Parameters:
      configuration - the MockServer configuration
    • InfinispanStateBackend

      public InfinispanStateBackend(int maxExpectations)
      Backward-compatible constructor for tests and single-node usage. Creates a LOCAL (non-clustered) backend.
      Parameters:
      maxExpectations - the maximum number of expectations
  • Method Details

    • expectations

      public KeyValueStore<ExpectationEntry> expectations()
      Description copied from interface: StateBackend
      Returns the expectation key-value store. The in-memory implementation internally wraps a CircularPriorityQueue for identical ordering and eviction behaviour.
      Specified by:
      expectations in interface StateBackend
    • scenarioStates

      public KeyValueStore<String> scenarioStates()
      Description copied from interface: StateBackend
      Returns the scenario-state key-value store. Keys are composite scenario-name + isolation strings; values are state strings.
      Specified by:
      scenarioStates in interface StateBackend
    • crudEntities

      public KeyValueStore<com.fasterxml.jackson.databind.node.ObjectNode> crudEntities(String namespace)
      Description copied from interface: StateBackend
      Returns a CRUD entity key-value store for the given namespace. Each namespace corresponds to a distinct CRUD resource path.
      Specified by:
      crudEntities in interface StateBackend
    • blobs

      public BlobStore blobs()
      Description copied from interface: StateBackend
      Returns the blob store for persisted expectations, recorded cassettes, fixtures, and snapshots.
      Specified by:
      blobs in interface StateBackend
    • addInvalidationListener

      public void addInvalidationListener(InvalidationListener listener)
      Description copied from interface: StateBackend
      Adds an invalidation listener that receives change notifications from ALL stores managed by this backend.
      Specified by:
      addInvalidationListener in interface StateBackend
    • nodeId

      public String nodeId()
      Description copied from interface: StateBackend
      Returns a unique identifier for this node/instance. Used to distinguish local vs. remote writes in a clustered backend.
      Specified by:
      nodeId in interface StateBackend
    • isClustered

      public boolean isClustered()
      Returns whether this backend is in clustered mode. Overrides the StateBackend default (false) to return the actual clustering state from the configuration. When true, RequestMatchers will use backend CAS for Times consumption.
      Specified by:
      isClustered in interface StateBackend
    • close

      public void close()
      Description copied from interface: StateBackend
      Closes the backend and releases any resources. No-op for the in-memory backend.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface StateBackend