Class DelegatingUserProvider

java.lang.Object
io.fluxzero.sdk.tracking.handling.authentication.DelegatingUserProvider
All Implemented Interfaces:
RefreshingUserProvider<User>, UserProvider

public class DelegatingUserProvider extends Object implements RefreshingUserProvider<User>
An extendable UserProvider that delegates to another UserProvider.
  • Field Details

  • Constructor Details

    • DelegatingUserProvider

      public DelegatingUserProvider()
  • Method Details

    • requiresMessageBasedLocalResolution

      public boolean requiresMessageBasedLocalResolution()
      Description copied from interface: UserProvider
      Returns whether locally handled messages must be passed to UserProvider.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, where fromMessage(message) returns the same user that UserProvider.addToMetadata(Metadata, User) added.

      Override this method to return true only if UserProvider.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:
      requiresMessageBasedLocalResolution in interface UserProvider
      Returns:
      true to resolve the handling user from the completed local message; false to reuse the user selected during dispatch
    • getActiveUser

      public User getActiveUser()
      Description copied from interface: UserProvider
      Returns the currently active user, typically injected by the current context.
      Specified by:
      getActiveUser in interface UserProvider
      Returns:
      the active User, or User.getCurrent() if not explicitly provided
    • getUserById

      public User getUserById(Object userId)
      Description copied from interface: UserProvider
      Retrieves a User by their unique identifier.

      This method is primarily used in TestFixture-based access control tests, such as when using whenCommandByUser(...), to simulate requests by a specific user.

      Implementations may return null if the user cannot be found, or alternatively return a new, unprivileged User instance. The latter approach allows tests to verify authorization behavior for unknown or default users without requiring explicit user creation.

      Specified by:
      getUserById in interface UserProvider
      Parameters:
      userId - the unique identifier of the user (typically a String or number)
      Returns:
      the matching User, a default unprivileged User, or null if not found
    • getSystemUser

      public User getSystemUser()
      Description copied from interface: UserProvider
      Returns the User representing the system (non-human) identity. Typically used for scheduled messages, internal services, etc.
      Specified by:
      getSystemUser in interface UserProvider
    • fromMessage

      public User fromMessage(HasMessage message)
      Description copied from interface: UserProvider
      Extracts the User from a given HasMessage instance. Implementations may inspect message metadata or payload to resolve the user identity.
      Specified by:
      fromMessage in interface UserProvider
      Parameters:
      message - the message containing potential user-related metadata
      Returns:
      the resolved User, or null if no user info was found
    • refreshUser

      public User refreshUser(User user, HasMessage message)
      Refreshes the supplied user when the delegate supports RefreshingUserProvider; otherwise returns the original user unchanged.
      Specified by:
      refreshUser in interface RefreshingUserProvider<User>
      Parameters:
      user - the previously resolved user identity
      message - 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

      public boolean containsUser(Metadata metadata)
      Description copied from interface: UserProvider
      Checks if the given metadata contains user information that can be resolved by this provider.
      Specified by:
      containsUser in interface UserProvider
      Parameters:
      metadata - the metadata to inspect
      Returns:
      true if the metadata contains recognizable user information
    • removeFromMetadata

      public Metadata removeFromMetadata(Metadata metadata)
      Description copied from interface: UserProvider
      Removes any user-related metadata entries from the given Metadata.
      Specified by:
      removeFromMetadata in interface UserProvider
      Parameters:
      metadata - the metadata to clean
      Returns:
      a new Metadata instance without any user-specific keys
    • addToMetadata

      public Metadata addToMetadata(Metadata metadata, User user, boolean ifAbsent)
      Description copied from interface: UserProvider
      Adds user-related metadata to a message.
      Specified by:
      addToMetadata in interface UserProvider
      Parameters:
      metadata - the original metadata
      user - the user to include
      ifAbsent - if true, metadata is only added if not already present
      Returns:
      updated Metadata with user info conditionally added
    • andThen

      public UserProvider andThen(UserProvider other)
      Description copied from interface: UserProvider
      Combines this provider with another.

      The returned provider will try this provider first, falling back to other if a user cannot be resolved. This is useful for composing multiple resolution strategies.

      Specified by:
      andThen in interface UserProvider
      Parameters:
      other - another user provider to chain after this one
      Returns:
      a new UserProvider that delegates to both providers