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
FieldsFields inherited from interface UserProvider
defaultUserProvider -
Constructor Summary
ConstructorsConstructorDescriptionAbstractUserProvider(Class<? extends User> userClass) Constructs anAbstractUserProviderusing the default metadata keyDEFAULT_USER_KEY. -
Method Summary
Modifier and TypeMethodDescriptionaddToMetadata(Metadata metadata, User user, boolean ifAbsent) Adds aUserto the metadata using the configured key.booleancontainsUser(Metadata metadata) Returnstrueif the metadata contains a user entry under the configured key.fromMessage(HasMessage message) Extracts aUserfrom the metadata of a message.removeFromMetadata(Metadata metadata) Removes the user entry from the metadata.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface UserProvider
addToMetadata, andThen, getActiveUser, getSystemUser, getUserById
-
Field Details
-
DEFAULT_USER_KEY
-
-
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
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
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
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
-