All Superinterfaces:
Principal

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

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 void
    Executes a runnable task with this user set as the current thread-local user.

    Methods inherited from interface java.security.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 Flux Capacitor 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
    • 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