Raxol.Security.UserContext (Raxol v2.0.1)
View SourceRefactored Security User Context module with GenServer-based state management.
This module provides user context management for security operations, eliminating Process dictionary usage in favor of supervised state.
Migration Notes
This module replaces Process.get(:current_user) calls in encryption modules with proper OTP-compliant state management.
Summary
Functions
Records an audit log entry for the current user.
Clears the current user.
Gets security context for the current operation.
Gets the current user for security operations.
Sets security context for the current operation.
Sets the current user for security operations.
Executes a function with a specific user context.
Functions
Records an audit log entry for the current user.
Examples
iex> audit_log(:encrypt_data, %{file: "sensitive.txt"})
:ok
Clears the current user.
Examples
iex> clear_current_user()
:ok
Gets security context for the current operation.
Examples
iex> get_context(:encryption_key_id)
"key_123"
Gets the current user for security operations.
Examples
iex> get_current_user()
"alice"
Sets security context for the current operation.
Examples
iex> set_context(:encryption_key_id, "key_123")
:ok
Sets the current user for security operations.
Examples
iex> set_current_user("alice")
:ok
Executes a function with a specific user context.
Examples
iex> with_user("bob", fn ->
...> # Operations will be performed as "bob"
...> encrypt_file("data.txt")
...> end)