Class AbstractUserProvider
java.lang.Object
io.fluxcapacitor.javaclient.tracking.handling.authentication.AbstractUserProvider
- All Implemented Interfaces:
UserProvider
Abstract base class for implementing
UserProvider
s 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 io.fluxcapacitor.javaclient.tracking.handling.authentication.UserProvider
defaultUserProvider
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractUserProvider
(Class<? extends User> userClass) Constructs anAbstractUserProvider
using the default metadata keyDEFAULT_USER_KEY
. -
Method Summary
Modifier and TypeMethodDescriptionaddToMetadata
(Metadata metadata, User user, boolean ifAbsent) Adds aUser
to the metadata using the configured key.boolean
containsUser
(Metadata metadata) Returnstrue
if the metadata contains a user entry under the configured key.fromMessage
(HasMessage message) Extracts aUser
from the metadata of a message.removeFromMetadata
(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, wait
Methods inherited from interface io.fluxcapacitor.javaclient.tracking.handling.authentication.UserProvider
addToMetadata, andThen, getActiveUser, getSystemUser, getUserById
-
Field Details
-
DEFAULT_USER_KEY
-
-
Constructor Details
-
AbstractUserProvider
Constructs anAbstractUserProvider
using the default metadata keyDEFAULT_USER_KEY
.- Parameters:
userClass
- the concrete user class this provider resolves
-
-
Method Details
-
fromMessage
Extracts aUser
from the metadata of a message.Uses the configured
metadataKey
to locate the user in the metadata of the given message.- Specified by:
fromMessage
in interfaceUserProvider
- Parameters:
message
- the message containing metadata- Returns:
- the resolved
User
, ornull
if not found
-
containsUser
Returnstrue
if the metadata contains a user entry under the configured key.- Specified by:
containsUser
in interfaceUserProvider
- Parameters:
metadata
- the metadata to inspect- Returns:
true
if a user is present, otherwisefalse
-
removeFromMetadata
Removes the user entry from the metadata.- Specified by:
removeFromMetadata
in interfaceUserProvider
- Parameters:
metadata
- the original metadata- Returns:
- a new
Metadata
instance without the user entry
-
addToMetadata
Adds aUser
to the metadata using the configured key.- Specified by:
addToMetadata
in 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
-