Interface User
- All Superinterfaces:
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
FieldsModifier and TypeFieldDescriptionstatic final ThreadLocal
<User> Thread-local reference to the current user. -
Method Summary
Modifier and TypeMethodDescriptiondefault <T> T
Executes a callable task with this user set as the current thread-local user.static <U extends User>
UReturns 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.
-
Field Details
-
current
Thread-local reference to the current user. Typically managed by the Flux Capacitor runtime and automatically injected for message handling.
-
-
Method Details
-
getCurrent
Returns the user currently associated with the executing thread.- Type Parameters:
U
- the expected user subtype- Returns:
- the current
User
, ornull
if none is set
-
apply
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
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
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
-