Interface UserProvider
- All Known Implementing Classes:
AbstractUserProvider
,DelegatingUserProvider
,NoOpUserProvider
public interface UserProvider
Service interface for managing
User
identities in Flux Capacitor.
A UserProvider
is responsible for extracting, resolving, and injecting user identity information into
messages. It enables user-aware processing by:
- Resolving the current authenticated
User
- Looking up users by ID or from message metadata
- Storing user metadata into messages for downstream correlation
Implementations of this interface can be registered via Java’s ServiceLoader
. When multiple implementations
are found, they are combined using andThen(UserProvider)
.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UserProvider
DefaultUserProvider
discovered viaServiceLoader
. -
Method Summary
Modifier and TypeMethodDescriptiondefault Metadata
addToMetadata
(Metadata metadata, User user) Adds user-related metadata to a message, overwriting existing values if present.addToMetadata
(Metadata metadata, User user, boolean ifAbsent) Adds user-related metadata to a message.default UserProvider
andThen
(UserProvider other) Combines this provider with another.boolean
containsUser
(Metadata metadata) Checks if the given metadata contains user information that can be resolved by this provider.fromMessage
(HasMessage message) Extracts theUser
from a givenHasMessage
instance.default User
Returns the currently active user, typically injected by the current context.Returns theUser
representing the system (non-human) identity.getUserById
(Object userId) Retrieves aUser
by their unique ID.removeFromMetadata
(Metadata metadata) Removes any user-related metadata entries from the givenMetadata
.
-
Field Details
-
defaultUserProvider
DefaultUserProvider
discovered viaServiceLoader
. If multiple providers are found, they are chained usingandThen(UserProvider)
. May benull
if no provider is registered.
-
-
Method Details
-
getActiveUser
Returns the currently active user, typically injected by the current context.- Returns:
- the active
User
, orUser.getCurrent()
if not explicitly provided
-
getUserById
Retrieves aUser
by their unique ID.- Parameters:
userId
- an identifier for the user, usually a string or numeric value- Returns:
- the corresponding
User
, ornull
if no match is found
-
getSystemUser
User getSystemUser()Returns theUser
representing the system (non-human) identity. Typically used for scheduled messages, internal services, etc. -
fromMessage
Extracts theUser
from a givenHasMessage
instance. Implementations may inspect message metadata or payload to resolve the user identity.- Parameters:
message
- the message containing potential user-related metadata- Returns:
- the resolved
User
, ornull
if no user info was found
-
containsUser
Checks if the given metadata contains user information that can be resolved by this provider.- Parameters:
metadata
- the metadata to inspect- Returns:
true
if the metadata contains recognizable user information
-
removeFromMetadata
Removes any user-related metadata entries from the givenMetadata
.- Parameters:
metadata
- the metadata to clean- Returns:
- a new
Metadata
instance without any user-specific keys
-
addToMetadata
Adds user-related metadata to a message, overwriting existing values if present.- Parameters:
metadata
- the original metadatauser
- the user whose info should be added- Returns:
- new metadata including the user identity
-
addToMetadata
Adds user-related metadata to a message.- Parameters:
metadata
- the original metadatauser
- the user to includeifAbsent
- iftrue
, metadata is only added if not already present- Returns:
- updated
Metadata
with user info conditionally added
-
andThen
Combines this provider with another.The returned provider will try this provider first, falling back to
other
if a user cannot be resolved. This is useful for composing multiple resolution strategies.- Parameters:
other
- another user provider to chain after this one- Returns:
- a new
UserProvider
that delegates to both providers
-