Module io.fluxzero.sdk
Class AbstractUserProvider
java.lang.Object
io.fluxzero.sdk.tracking.handling.authentication.AbstractUserProvider
- All Implemented Interfaces:
UserProvider
Abstract base class for implementing
UserProviders that resolve user identities via a metadata key.
This implementation provides a reusable foundation for extracting, injecting, and managing User instances
within Metadata, commonly used in message handling scenarios. Most concrete UserProvider
implementations can extend this class to inherit standard behavior for:
- Retrieving a user from message metadata via a configured key
- Checking whether a user is present in metadata
- Inserting or removing user entries in metadata
Metadata key
The default metadata key used for storing user objects isDEFAULT_USER_KEY, which resolves to "$user".
Custom keys can also be provided via the constructor for flexibility across different application contexts.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StringDefault key used inMetadatato storeUserobjects.Fields inherited from interface io.fluxzero.sdk.tracking.handling.authentication.UserProvider
defaultUserProvider -
Constructor Summary
ConstructorsConstructorDescriptionAbstractUserProvider(Class<? extends User> userClass) Constructs anAbstractUserProviderusing the default metadata keyDEFAULT_USER_KEY. -
Method Summary
Modifier and TypeMethodDescriptionio.fluxzero.common.api.MetadataaddToMetadata(io.fluxzero.common.api.Metadata metadata, User user, boolean ifAbsent) Adds aUserto the metadata using the configured key.booleancontainsUser(io.fluxzero.common.api.Metadata metadata) Returnstrueif the metadata contains a user entry under the configured key.fromMessage(HasMessage message) Extracts aUserfrom the metadata of a message.io.fluxzero.common.api.MetadataremoveFromMetadata(io.fluxzero.common.api.Metadata metadata) Removes the user entry from the metadata.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.fluxzero.sdk.tracking.handling.authentication.UserProvider
addToMetadata, andThen, getActiveUser, getSystemUser, getUserById
-
Field Details
-
DEFAULT_USER_KEY
Default key used inMetadatato storeUserobjects.
-
-
Constructor Details
-
AbstractUserProvider
Constructs anAbstractUserProviderusing the default metadata keyDEFAULT_USER_KEY.- Parameters:
userClass- the concrete user class this provider resolves
-
-
Method Details
-
fromMessage
Extracts aUserfrom the metadata of a message.Uses the configured
metadataKeyto locate the user in the metadata of the given message.- Specified by:
fromMessagein interfaceUserProvider- Parameters:
message- the message containing metadata- Returns:
- the resolved
User, ornullif not found
-
containsUser
public boolean containsUser(io.fluxzero.common.api.Metadata metadata) Returnstrueif the metadata contains a user entry under the configured key.- Specified by:
containsUserin interfaceUserProvider- Parameters:
metadata- the metadata to inspect- Returns:
trueif a user is present, otherwisefalse
-
removeFromMetadata
public io.fluxzero.common.api.Metadata removeFromMetadata(io.fluxzero.common.api.Metadata metadata) Removes the user entry from the metadata.- Specified by:
removeFromMetadatain interfaceUserProvider- Parameters:
metadata- the original metadata- Returns:
- a new
Metadatainstance without the user entry
-
addToMetadata
public io.fluxzero.common.api.Metadata addToMetadata(io.fluxzero.common.api.Metadata metadata, User user, boolean ifAbsent) Adds aUserto the metadata using the configured key.- Specified by:
addToMetadatain interfaceUserProvider- Parameters:
metadata- the original metadatauser- the user to addifAbsent- whether to only add the user if it is not already present- Returns:
- updated metadata including the user
-