Interface User

All Superinterfaces:
Principal

public interface User extends Principal
Represents an authenticated or system-level user identity within the Fluxzero Runtime.

A User provides role-based access information. User instances are propagated through message metadata and can be made available to business logic via getCurrent() or injection into handler methods.

To execute logic with a specific user bound to the current thread context, use apply(Callable) or run(ThrowingRunnable).

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ThreadLocal<User>
    Thread-local reference to the current user.
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> T
    Executes a callable task with this user set as the current thread-local user.
    static <U extends User>
    U
    Returns the user currently associated with the executing thread.
    boolean
    Indicates whether this user has the specified role.
    default String
    id()
    Returns the stable identifier of this user.
    default void
    Executes a runnable task with this user set as the current thread-local user.

    Methods inherited from interface Principal

    equals, getName, hashCode, implies, toString
  • Field Details

    • current

      static final ThreadLocal<User> current
      Thread-local reference to the current user. Typically managed by the Fluxzero Runtime and automatically injected for message handling.
  • Method Details

    • getCurrent

      static <U extends User> U getCurrent()
      Returns the user currently associated with the executing thread.
      Type Parameters:
      U - the expected user subtype
      Returns:
      the current User, or null if none is set
    • id

      default String id()
      Returns the stable identifier of this user.

      The default delegates to Principal.getName() so existing User implementations remain source-, binary-, and behavior-compatible. Implementations should override this method when the principal name is not a stable application user identifier. Fluxzero uses this value for user metadata, provider lookups, and diagnostics that identify the acting user.

      Returns:
      the stable user identifier
    • apply

      default <T> T apply(Callable<T> f)
      Executes a callable task with this user set as the current thread-local user. Restores the previous user (if any) after execution.
      Type Parameters:
      T - the type of result returned by the callable
      Parameters:
      f - the callable task to run
      Returns:
      the result of the callable
    • run

      default void run(ThrowingRunnable f)
      Executes a runnable task with this user set as the current thread-local user. Restores the previous user (if any) after execution.
      Parameters:
      f - the task to run
    • hasRole

      boolean hasRole(String role)
      Indicates whether this user has the specified role.
      Parameters:
      role - a role string such as "admin" or "viewer"
      Returns:
      true if the user has the role, false otherwise