Class DelegatingUserProvider
- All Implemented Interfaces:
RefreshingUserProvider<User>, UserProvider
UserProvider that delegates to another UserProvider.-
Field Summary
FieldsFields inherited from interface UserProvider
defaultUserProvider -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddToMetadata(Metadata metadata, User user, boolean ifAbsent) Adds user-related metadata to a message.andThen(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.Returns 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.protected UserrefreshUser(RefreshingUserProvider refreshingUserProvider, User user, HasMessage message) refreshUser(User user, HasMessage message) Refreshes the supplied user when the delegate supportsRefreshingUserProvider; otherwise returns the original user unchanged.removeFromMetadata(Metadata metadata) Removes any user-related metadata entries from the givenMetadata.booleanReturns whether locally handled messages must be passed toUserProvider.fromMessage(HasMessage)to determine the handling user.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface UserProvider
addToMetadata
-
Field Details
-
delegate
-
-
Constructor Details
-
DelegatingUserProvider
public DelegatingUserProvider()
-
-
Method Details
-
requiresMessageBasedLocalResolution
public boolean requiresMessageBasedLocalResolution()Description copied from interface:UserProviderReturns whether locally handled messages must be passed toUserProvider.fromMessage(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 thatUserProvider.addToMetadata(Metadata, User)added.Override this method to return
trueonly ifUserProvider.fromMessage(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.- Specified by:
requiresMessageBasedLocalResolutionin interfaceUserProvider- Returns:
trueto resolve the handling user from the completed local message;falseto reuse the user selected during dispatch
-
getActiveUser
Description copied from interface:UserProviderReturns the currently active user, typically injected by the current context.- Specified by:
getActiveUserin interfaceUserProvider- Returns:
- the active
User, orUser.getCurrent()if not explicitly provided
-
getUserById
Description copied from interface:UserProviderRetrieves 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.- Specified by:
getUserByIdin interfaceUserProvider- Parameters:
userId- the unique identifier of the user (typically a String or number)- Returns:
- the matching
User, a default unprivilegedUser, ornullif not found
-
getSystemUser
Description copied from interface:UserProviderReturns theUserrepresenting the system (non-human) identity. Typically used for scheduled messages, internal services, etc.- Specified by:
getSystemUserin interfaceUserProvider
-
fromMessage
Description copied from interface:UserProviderExtracts theUserfrom a givenHasMessageinstance. Implementations may inspect message metadata or payload to resolve the user identity.- Specified by:
fromMessagein interfaceUserProvider- Parameters:
message- the message containing potential user-related metadata- Returns:
- the resolved
User, ornullif no user info was found
-
refreshUser
Refreshes the supplied user when the delegate supportsRefreshingUserProvider; otherwise returns the original user unchanged.- Specified by:
refreshUserin interfaceRefreshingUserProvider<User>- Parameters:
user- the previously resolved user identitymessage- the message being authorized or handled- Returns:
- the refreshed user, or the original user if the delegate does not support refresh
-
refreshUser
protected User refreshUser(RefreshingUserProvider refreshingUserProvider, User user, HasMessage message) -
containsUser
Description copied from interface:UserProviderChecks if the given metadata contains user information that can be resolved by this provider.- Specified by:
containsUserin interfaceUserProvider- Parameters:
metadata- the metadata to inspect- Returns:
trueif the metadata contains recognizable user information
-
removeFromMetadata
Description copied from interface:UserProviderRemoves any user-related metadata entries from the givenMetadata.- Specified by:
removeFromMetadatain interfaceUserProvider- Parameters:
metadata- the metadata to clean- Returns:
- a new
Metadatainstance without any user-specific keys
-
addToMetadata
Description copied from interface:UserProviderAdds user-related metadata to a message.- Specified by:
addToMetadatain interfaceUserProvider- 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
Description copied from interface:UserProviderCombines 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.- Specified by:
andThenin interfaceUserProvider- Parameters:
other- another user provider to chain after this one- Returns:
- a new
UserProviderthat delegates to both providers
-