Interface UserProvider
- All Known Subinterfaces:
RefreshingUserProvider<U>
- All Known Implementing Classes:
AbstractUserProvider, DelegatingUserProvider, NoOpUserProvider, OidcUserProvider
User identities in Fluxzero.
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 UserProviderDefaultUserProviderdiscovered viaServiceLoader. -
Method Summary
Modifier and TypeMethodDescriptiondefault MetadataaddToMetadata(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 UserProviderandThen(UserProvider other) Combines this provider with another.booleancontainsUser(Metadata metadata) Checks if the given metadata contains user information that can be resolved by this provider.fromMessage(HasMessage message) Extracts theUserfrom a givenHasMessageinstance.default UserReturns the currently active user, typically injected by the current context.Returns theUserrepresenting the system (non-human) identity.getUserById(Object userId) Retrieves aUserby their unique identifier.removeFromMetadata(Metadata metadata) Removes any user-related metadata entries from the givenMetadata.default booleanReturns whether locally handled messages must be passed tofromMessage(HasMessage)to determine the handling user.
-
Field Details
-
defaultUserProvider
DefaultUserProviderdiscovered viaServiceLoader. If multiple providers are found, they are chained usingandThen(UserProvider). May benullif no provider is registered.
-
-
Method Details
-
requiresMessageBasedLocalResolution
default boolean requiresMessageBasedLocalResolution()Returns whether locally handled messages must be passed tofromMessage(HasMessage)to determine the handling user.Fluxzero normally reuses the user that was selected when the message was dispatched. This avoids constructing a complete message solely to store that user in metadata and read it back again. This is correct for regular providers, including implementations of
AbstractUserProvider, wherefromMessage(message)returns the same user thataddToMetadata(Metadata, User)added.Override this method to return
trueonly iffromMessage(HasMessage)can intentionally produce a different user, or if user resolution depends on other parts of the completed message. Local handling will then use the regular message-based path so that the provider retains exactly that behavior.- Returns:
trueto resolve the handling user from the completed local message;falseto reuse the user selected during dispatch
-
getActiveUser
Returns the currently active user, typically injected by the current context.- Returns:
- the active
User, orUser.getCurrent()if not explicitly provided
-
getUserById
Retrieves aUserby their unique identifier.This method is primarily used in
TestFixture-based access control tests, such as when usingwhenCommandByUser(...), to simulate requests by a specific user.Implementations may return
nullif the user cannot be found, or alternatively return a new, unprivilegedUserinstance. The latter approach allows tests to verify authorization behavior for unknown or default users without requiring explicit user creation. -
getSystemUser
-
fromMessage
Extracts theUserfrom a givenHasMessageinstance. 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, ornullif 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:
trueif the metadata contains recognizable user information
-
removeFromMetadata
-
addToMetadata
-
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
Metadatawith user info conditionally added
-
andThen
Combines this provider with another.The returned provider will try this provider first, falling back to
otherif 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
UserProviderthat delegates to both providers
-