Class DataProtectionInterceptor
- All Implemented Interfaces:
DispatchInterceptor, HandlerDecorator, HandlerInterceptor
DispatchInterceptor and HandlerInterceptor that supports secure transmission of sensitive data
fields by removing them from the payload before dispatch and restoring them during handling.
This interceptor works in two phases:
- Dispatch phase:
- Scans the payload for fields annotated with
ProtectData. - Each such field is serialized and stored securely in a designated store, indexed by a generated key.
- The payload is cloned and sensitive fields are removed (set to
null). - The generated key references and their dispatch namespace are stored in the message metadata under
METADATA_KEYandNAMESPACE_METADATA_KEY.
- Scans the payload for fields annotated with
- Handling phase:
- Looks for protected data references in the message metadata.
- If present, retrieves the original values from the store using the stored keys.
- Injects the retrieved values back into the message payload before invocation.
- If the target method is annotated with
DropProtectedData, the stored entries are deleted after injection.
This strategy is useful for preventing sensitive or private data from being persisted to the message log, while still allowing handlers to receive full context during execution.
Example
public class MyHandler {
@HandleCommand
public void handle(@ProtectData String ssn, ...) {
...
}
@HandleCommand
@DropProtectedData
public void auditSensitive(@ProtectData String secretField, ...) {
...
// After invocation, the secret is permanently removed
}
}
Note: The payload is cloned via (de)serialization to ensure the original object remains unmodified.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface HandlerDecorator
HandlerDecorator.MergedDecoratorNested classes/interfaces inherited from interface HandlerInterceptor
HandlerInterceptor.InterceptedHandler, HandlerInterceptor.PreparedHandlerFunction, HandlerInterceptor.PreparedHandlerInputFunction, HandlerInterceptor.PreparedHandlerInputInterceptor, HandlerInterceptor.PreparedHandlerInterceptor, HandlerInterceptor.PreparedInterceptedHandler -
Field Summary
FieldsFields inherited from interface DispatchInterceptor
defaultInterceptors, noOpFields inherited from interface HandlerDecorator
noOpFields inherited from interface HandlerInterceptor
defaultInterceptors -
Constructor Summary
ConstructorsConstructorDescriptionDataProtectionInterceptor(KeyValueStore keyValueStore, Serializer serializer) Creates an interceptor that silently invokes handlers when protected values are unavailable.DataProtectionInterceptor(KeyValueStore keyValueStore, Serializer serializer, MissingProtectedDataPolicy onMissingProtectedData) Creates an interceptor with an application-wide missing protected data policy.DataProtectionInterceptor(KeyValueStore keyValueStore, Serializer serializer, MissingProtectedDataPolicy onMissingProtectedData, boolean trackingMetricsEnabled) Creates an interceptor with an application-wide missing protected data policy. -
Method Summary
Modifier and TypeMethodDescriptioninterceptDispatch(Message m, MessageType messageType, String topic) Intercepts the dispatch of a message before it is serialized and published or locally handled.interceptDispatch(Message m, MessageType messageType, String topic, String namespace) Intercepts a dispatch to a specific namespace.interceptHandling(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Intercepts the message handling logic.prepareLocalDispatch(LocalDispatchDescriptor descriptor) Prepares this interceptor for repeated local dispatches with the same static message characteristics.wrap(Handler<DeserializingMessage> handler) Wraps aHandlerwith this interceptor, producing an intercepted handler.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DispatchInterceptor
andThen, modifySerializedMessage, monitorDispatch, withNamespaceMethods inherited from interface HandlerDecorator
andThenMethods inherited from interface HandlerInterceptor
prepare, prepareInput, prepareInput, supportsPreparation
-
Field Details
-
METADATA_KEY
-
NAMESPACE_METADATA_KEY
- See Also:
-
-
Constructor Details
-
DataProtectionInterceptor
Creates an interceptor that silently invokes handlers when protected values are unavailable.- Parameters:
keyValueStore- store containing protected valuesserializer- serializer used to sanitize and restore payloads
-
DataProtectionInterceptor
public DataProtectionInterceptor(KeyValueStore keyValueStore, Serializer serializer, MissingProtectedDataPolicy onMissingProtectedData) Creates an interceptor with an application-wide missing protected data policy.- Parameters:
keyValueStore- store containing protected valuesserializer- serializer used to sanitize and restore payloadsonMissingProtectedData- application-wide fallback policy
-
DataProtectionInterceptor
public DataProtectionInterceptor(KeyValueStore keyValueStore, Serializer serializer, MissingProtectedDataPolicy onMissingProtectedData, boolean trackingMetricsEnabled) Creates an interceptor with an application-wide missing protected data policy.- Parameters:
keyValueStore- store containing protected valuesserializer- serializer used to sanitize and restore payloadsonMissingProtectedData- application-wide fallback policytrackingMetricsEnabled- whether skipped handlers should publish ignore-message metrics
-
-
Method Details
-
interceptDispatch
Description copied from interface:DispatchInterceptorIntercepts the dispatch of a message before it is serialized and published or locally handled.You may modify the message or return
nullto block dispatching. Throwing an exception also prevents dispatching.- Specified by:
interceptDispatchin interfaceDispatchInterceptor- Parameters:
m- the message to be dispatchedmessageType- 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
nullto prevent dispatch
-
interceptDispatch
public Message interceptDispatch(Message m, MessageType messageType, String topic, String namespace) Description copied from interface:DispatchInterceptorIntercepts a dispatch to a specific namespace.The default implementation delegates to the namespace-agnostic method so existing interceptors retain their behavior. Interceptors that access namespace-sensitive resources can override this method.
- Specified by:
interceptDispatchin interfaceDispatchInterceptor- Parameters:
m- the message to be dispatchedmessageType- the type of the messagetopic- the target topic ornullnamespace- the target namespace ornullfor the application namespace- Returns:
- the modified message, the same message, or
nullto prevent dispatch
-
prepareLocalDispatch
Description copied from interface:DispatchInterceptorPrepares 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
Messagefirst. Implementations must preserve the observable behavior ofDispatchInterceptor.interceptDispatch(Message, MessageType, String). Returnnullwhen 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:
prepareLocalDispatchin interfaceDispatchInterceptor- Parameters:
descriptor- payload class, message type, and topic shared by the local dispatches- Returns:
- a thread-safe prepared policy, or
nullto use regular message-based dispatch
-
wrap
Description copied from interface:HandlerInterceptorWraps aHandlerwith this interceptor, producing an intercepted handler.- Specified by:
wrapin interfaceHandlerDecorator- Specified by:
wrapin interfaceHandlerInterceptor- Parameters:
handler- the original handler to wrap- Returns:
- an intercepted handler that applies this interceptor to all handled messages
-
interceptHandling
public Function<DeserializingMessage, Object> interceptHandling(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Description copied from interface:HandlerInterceptorIntercepts the message handling logic.The
functionparameter represents the next step in the handling chain— typically the actual message handler. Theinvokerprovides metadata and invocation logic for the underlying handler method.Within this method, an interceptor may:
- Modify the
DeserializingMessagebefore 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:
interceptHandlingin interfaceHandlerInterceptor- 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
- Modify the
-