java.lang.Object
io.fluxcapacitor.javaclient.tracking.handling.authentication.AbstractUserProvider
All Implemented Interfaces:
UserProvider

public abstract class AbstractUserProvider extends Object implements 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 is DEFAULT_USER_KEY, which resolves to "$user". Custom keys can also be provided via the constructor for flexibility across different application contexts.
See Also:
  • Field Details

    • DEFAULT_USER_KEY

      public static String DEFAULT_USER_KEY
      Default key used in Metadata to store User objects.
  • Constructor Details

    • AbstractUserProvider

      public AbstractUserProvider(Class<? extends User> userClass)
      Constructs an AbstractUserProvider using the default metadata key DEFAULT_USER_KEY.
      Parameters:
      userClass - the concrete user class this provider resolves
  • Method Details

    • fromMessage

      public User fromMessage(HasMessage message)
      Extracts a User 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 interface UserProvider
      Parameters:
      message - the message containing metadata
      Returns:
      the resolved User, or null if not found
    • containsUser

      public boolean containsUser(Metadata metadata)
      Returns true if the metadata contains a user entry under the configured key.
      Specified by:
      containsUser in interface UserProvider
      Parameters:
      metadata - the metadata to inspect
      Returns:
      true if a user is present, otherwise false
    • removeFromMetadata

      public Metadata removeFromMetadata(Metadata metadata)
      Removes the user entry from the metadata.
      Specified by:
      removeFromMetadata in interface UserProvider
      Parameters:
      metadata - the original metadata
      Returns:
      a new Metadata instance without the user entry
    • addToMetadata

      public Metadata addToMetadata(Metadata metadata, User user, boolean ifAbsent)
      Adds a User to the metadata using the configured key.
      Specified by:
      addToMetadata in interface UserProvider
      Parameters:
      metadata - the original metadata
      user - the user to add
      ifAbsent - whether to only add the user if it is not already present
      Returns:
      updated metadata including the user