Class AbstractUserProvider
- All Implemented Interfaces:
UserProvider
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 or resolving a user ID 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 isDEFAULT_USER_KEY, which resolves to "$user". With compatibility
defaults, this key stores a serialized user object. With defaults version 2026.08.04 or newer, or when
USE_USER_ID_METADATA_PROPERTY is enabled, it stores User.id() for regular users and
SYSTEM_USER_ID for the system user. Regular IDs resolve through UserProvider.getUserById(Object) and the system
ID resolves through UserProvider.getSystemUser().
Custom keys can also be provided via the constructor for flexibility across different application contexts.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault key used inMetadatato store user information.static final StringReserved user ID that resolves to the system user.static final StringProperty that explicitly selects whether user metadata contains user IDs instead of serialized user objects.Fields inherited from interface UserProvider
defaultUserProvider -
Constructor Summary
ConstructorsConstructorDescriptionAbstractUserProvider(Class<? extends User> userClass) Constructs anAbstractUserProviderusing the default metadata keyDEFAULT_USER_KEY.AbstractUserProvider(String metadataKey, Class<? extends User> userClass) Constructs anAbstractUserProviderusing a custom metadata 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.protected booleanisSystemUser(User user) Determines whether a user should be represented bySYSTEM_USER_IDin metadata.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, requiresMessageBasedLocalResolution
-
Field Details
-
DEFAULT_USER_KEY
-
USE_USER_ID_METADATA_PROPERTY
Property that explicitly selects whether user metadata contains user IDs instead of serialized user objects.- See Also:
-
SYSTEM_USER_ID
Reserved user ID that resolves to the system user.- See Also:
-
-
Constructor Details
-
AbstractUserProvider
-
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. Compatibility defaults only accept a serialized user object. New defaults also accept user IDs while continuing to deserialize user objects written before migration. IDs are resolved throughUserProvider.getUserById(Object), except forSYSTEM_USER_ID, which resolves throughUserProvider.getSystemUser().- 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. Compatibility defaults serialize the complete user; new defaults storeUser.id()so the receiving provider can resolve a regular user by ID, orSYSTEM_USER_IDwhenisSystemUser(User)identifies the user as the system user.- 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
- Throws:
IllegalArgumentException- if a regular user has the reserved IDSYSTEM_USER_ID
-
isSystemUser
Determines whether a user should be represented bySYSTEM_USER_IDin metadata.The default implementation checks whether the supplied user is the same instance as
UserProvider.getSystemUser(). Providers whose system user is not a stable instance may override this method with their own identity check.- Parameters:
user- the non-null user being added to metadata- Returns:
trueif the user represents the system identity
-