Interface User
- All Superinterfaces:
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
FieldsModifier and TypeFieldDescriptionstatic final ThreadLocal<User> Thread-local reference to the current user. -
Method Summary
Modifier and TypeMethodDescriptiondefault <T> TExecutes 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.default StringgetName()Returns this user's principal name, using the explicit identity when no separate name is supplied.booleanIndicates whether this user has the specified role.id()Returns the stable identifier of this user.default voidrun(io.fluxzero.common.ThrowingRunnable f) 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 Fluxzero 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, ornullif 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 theirUserProvidercan resolve.- Returns:
- the stable user identifier
-
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 usesid(). This one-way default does not infer an identity from a name. -
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
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
Indicates whether this user has the specified role.- Parameters:
role- a role string such as"admin"or"viewer"- Returns:
trueif the user has the role,falseotherwise
-