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.
    default String
    Returns this user's principal name, using the explicit identity when no separate name is supplied.
    boolean
    Indicates whether this user has the specified role.
    id()
    Returns the stable identifier of this user.
    default void
    run(io.fluxzero.common.ThrowingRunnable f)
    Executes a runnable task with this user set as the current thread-local user.

    Methods inherited from interface Principal

    equals, 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

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

      Every implementation must supply this identity explicitly. There is no fallback to getName(); a principal or display name is not an identity contract. Fluxzero uses this value for ID-based user metadata, provider lookups, and diagnostics that identify the acting user. Implementations should return a non-null, stable identifier that their UserProvider can resolve.

      Returns:
      the stable user identifier
    • getName

      default String getName()
      Returns this user's principal name, using the explicit identity when no separate name is supplied. Override this method for a distinct principal or display name; identity-dependent behavior still uses id(). This one-way default does not infer an identity from a name.
      Specified by:
      getName in interface Principal
      Returns:
      the principal name
    • 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(io.fluxzero.common.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