Class AuthenticatingInterceptor

java.lang.Object
io.fluxzero.sdk.tracking.handling.authentication.AuthenticatingInterceptor
All Implemented Interfaces:
DispatchInterceptor, HandlerDecorator, HandlerInterceptor

public class AuthenticatingInterceptor extends Object implements DispatchInterceptor, HandlerInterceptor
  • Constructor Details

    • AuthenticatingInterceptor

      public AuthenticatingInterceptor()
  • Method Details

    • interceptDispatch

      public Message interceptDispatch(Message m, io.fluxzero.common.MessageType messageType, String topic)
      Description copied from interface: DispatchInterceptor
      Intercepts the dispatch of a message before it is serialized and published or locally handled.

      You may modify the message or return null to block dispatching. Throwing an exception also prevents dispatching.

      Specified by:
      interceptDispatch in interface DispatchInterceptor
      Parameters:
      m - the message to be dispatched
      messageType - the type of the message (e.g., COMMAND, EVENT, etc.)
      topic - the target topic or null if not applicable
      Returns:
      the modified message, the same message, or null to prevent dispatch
    • prepareLocalDispatch

      public PreparedLocalDispatch prepareLocalDispatch(LocalDispatchDescriptor descriptor)
      Description copied from interface: DispatchInterceptor
      Prepares this interceptor for repeated local dispatches with the same static message characteristics.

      This optional method lets local handling apply an interceptor without creating a complete Message first. Implementations must preserve the observable behavior of DispatchInterceptor.interceptDispatch(Message, MessageType, String). Return null when that is not possible; Fluxzero will then use the regular dispatch path for this payload type.

      The returned policy may be cached and used concurrently. State belonging to a single dispatch must be stored in the supplied LocalExecution, not in the policy itself.

      Specified by:
      prepareLocalDispatch in interface DispatchInterceptor
      Parameters:
      descriptor - payload class, message type, and topic shared by the local dispatches
      Returns:
      a thread-safe prepared policy, or null to use regular message-based dispatch
    • interceptHandling

      public Function<DeserializingMessage, Object> interceptHandling(Function<DeserializingMessage, Object> function, io.fluxzero.common.handling.HandlerInvoker invoker)
      Description copied from interface: HandlerInterceptor
      Intercepts the message handling logic.

      The function parameter represents the next step in the handling chain— typically the actual message handler. The invoker provides metadata and invocation logic for the underlying handler method.

      Within this method, an interceptor may:

      • Modify the DeserializingMessage before passing it to the handler
      • Bypass the handler entirely and return a value directly
      • Wrap the result after the handler is invoked

      Note: Interceptors may return a different DeserializingMessage, but it must be compatible with a handler method in the same target class. If no suitable handler is found, an exception will be thrown.

      Specified by:
      interceptHandling in interface HandlerInterceptor
      Parameters:
      function - the next step in the handler chain (typically the handler itself)
      invoker - the metadata and execution strategy for the actual handler method
      Returns:
      a decorated function that wraps handling behavior
    • prepare

      public HandlerInterceptor.PreparedHandlerInterceptor prepare(io.fluxzero.common.handling.HandlerDescriptor handler)
      Description copied from interface: HandlerInterceptor
      Prepares this interceptor for a specific handler method.

      The returned interceptor is cached and reused concurrently for invocations with the same stable handler metadata. Implementations may use this hook to resolve annotation- or signature-based policy once while keeping message-dependent decisions inside HandlerInterceptor.PreparedHandlerInterceptor.interceptHandling(DeserializingMessage, HandlerDescriptor, BiFunction, HandlerInterceptor.PreparedHandlerFunction).

      The default adapter preserves the existing HandlerInterceptor.interceptHandling(Function, HandlerInvoker) contract and deliberately disables the reusable HandlerMethod path. Custom interceptors therefore retain their current behavior unless they explicitly opt into preparation.

      Specified by:
      prepare in interface HandlerInterceptor
      Parameters:
      handler - stable metadata for the handler method
      Returns:
      a thread-safe prepared interceptor
    • prepareInput

      public HandlerInterceptor.PreparedHandlerInputInterceptor prepareInput(io.fluxzero.common.handling.HandlerDescriptor handler)
      Description copied from interface: HandlerInterceptor
      Prepares this interceptor to run without first creating a complete message.

      Return null when the interceptor requires the regular message-based handling path. The default only supports an interceptor whose prepared behavior is the shared no-op policy, so existing interceptors retain their exact behavior unless they opt in explicitly.

      The returned policy may be cached and invoked concurrently.

      Specified by:
      prepareInput in interface HandlerInterceptor
      Parameters:
      handler - stable information about the selected handler method
      Returns:
      a thread-safe payload-first policy, or null to use regular message-based handling
    • prepareInput

      public HandlerInterceptor.PreparedHandlerInputInterceptor prepareInput(io.fluxzero.common.handling.HandlerDescriptor handler, io.fluxzero.common.handling.HandlerInput<DeserializingMessage> preparedInput)
      Description copied from interface: HandlerInterceptor
      Prepares this interceptor using both the selected handler method and a representative input.

      Override this overload when the interceptor's ability to use payload-first handling depends on input characteristics. The default delegates to HandlerInterceptor.prepareInput(HandlerDescriptor).

      Specified by:
      prepareInput in interface HandlerInterceptor
      Parameters:
      handler - stable information about the selected handler method
      preparedInput - a representative input for the prepared handler plan
      Returns:
      a thread-safe payload-first policy, or null to use regular message-based handling
    • supportsPreparation

      public boolean supportsPreparation()
      Description copied from interface: HandlerInterceptor
      Indicates whether this interceptor opts into the prepared, mergeable handler wrapper.

      The default is false, preserving the exact wrapper behavior of existing custom interceptors. An interceptor should return true only when HandlerInterceptor.prepare(HandlerDescriptor) returns a thread-safe plan that fully represents its handling behavior. If a subclass overrides only the legacy HandlerInterceptor.interceptHandling(Function, HandlerInvoker) method, the legacy wrapper is retained automatically.

      Specified by:
      supportsPreparation in interface HandlerInterceptor
      Returns:
      true when this interceptor may be merged into a prepared wrapper
    • getCurrentUser

      protected User getCurrentUser(DeserializingMessage m)
    • getDispatchUser

      protected User getDispatchUser(Message m, io.fluxzero.common.MessageType messageType)
    • isEstablishedWebsocketFrame

      protected boolean isEstablishedWebsocketFrame(Message m, io.fluxzero.common.MessageType messageType)
    • getAuthorizingUser

      protected User getAuthorizingUser(DeserializingMessage m)
    • refreshUser

      protected User refreshUser(RefreshableUser refreshableUser, DeserializingMessage m)
    • wrap

      public io.fluxzero.common.handling.Handler<DeserializingMessage> wrap(io.fluxzero.common.handling.Handler<DeserializingMessage> handler)
      Description copied from interface: HandlerInterceptor
      Wraps a Handler with this interceptor, producing an intercepted handler.
      Specified by:
      wrap in interface HandlerDecorator
      Specified by:
      wrap in interface HandlerInterceptor
      Parameters:
      handler - the original handler to wrap
      Returns:
      an intercepted handler that applies this interceptor to all handled messages