Skip to main content

AuthenticationMetadataManager

Trait AuthenticationMetadataManager 

Source
pub trait AuthenticationMetadataManager: Send + Sync {
    // Required methods
    async fn shutdown(&mut self) -> AuthServiceResult<()>;
    async fn init_user(&self, auth_config: &AuthConfig) -> AuthServiceResult<()>;
    async fn create_user(&self, user: User) -> AuthServiceResult<()>;
    async fn update_user(&self, user: User) -> AuthServiceResult<()>;
    async fn delete_user(&self, username: &str) -> AuthServiceResult<()>;
    async fn get_user(&self, username: &str) -> AuthServiceResult<User>;
    async fn list_users(
        &self,
        filter: Option<&str>,
    ) -> AuthServiceResult<Vec<User>>;
    async fn is_super_user(&self, username: &str) -> AuthServiceResult<bool>;
}
Expand description

Authentication metadata manager trait.

This trait provides high-level operations for managing authentication metadata, wrapping the underlying AuthenticationMetadataProvider and adding validation, initialization, and error handling logic.

§Responsibilities

  • User lifecycle management (create, update, delete)
  • User query and listing
  • Super user privilege checking
  • Provider initialization and shutdown
  • Input validation and error handling

§Concurrency

All methods are async and designed for concurrent access. Implementations should ensure thread-safety through appropriate synchronization mechanisms.

§Example

ⓘ
use rocketmq_auth::AuthenticationMetadataManager;
use rocketmq_auth::AuthConfig;

async fn example(manager: &dyn AuthenticationMetadataManager, config: AuthConfig) {
    // Initialize default users
    manager.init_user(config).await?;
     
    // Create a user
    let user = User::of_with_type("alice", "password123", UserType::Normal);
    manager.create_user(user).await?;
     
    // Check if user is super user
    let is_super = manager.is_super_user("alice").await?;
}

Required Methods§

Source

async fn shutdown(&mut self) -> AuthServiceResult<()>

Shutdown the metadata manager and release resources.

This method should cleanup all resources including:

  • Closing database connections
  • Shutting down thread pools
  • Flushing pending operations
Source

async fn init_user(&self, auth_config: &AuthConfig) -> AuthServiceResult<()>

Initialize default super user from configuration.

This method reads the default user credentials from AuthConfig and creates the super user if it doesn’t exist. This is typically called during system initialization.

§Arguments
  • auth_config - Authentication configuration containing default user settings
Source

async fn create_user(&self, user: User) -> AuthServiceResult<()>

Create a new user.

§Arguments
  • user - The user to create
§Returns
  • Ok(()) - User created successfully
  • Err(AuthServiceError) - Validation failed or creation error
§Errors
  • AuthenticationFailed - Username is blank or invalid
  • InvalidCredential - Password is missing or invalid
  • Storage errors from underlying provider
Source

async fn update_user(&self, user: User) -> AuthServiceResult<()>

Update an existing user.

§Arguments
  • user - The user with updated information
§Returns
  • Ok(()) - User updated successfully
  • Err(AuthServiceError) - Validation failed or update error
Source

async fn delete_user(&self, username: &str) -> AuthServiceResult<()>

Delete a user by username.

§Arguments
  • username - The username of the user to delete
§Returns
  • Ok(()) - User deleted successfully
  • Err(AuthServiceError) - Username is blank or deletion error
Source

async fn get_user(&self, username: &str) -> AuthServiceResult<User>

Get a user by username.

§Arguments
  • username - The username to query
§Returns
  • Ok(User) - User found
  • Err(AuthServiceError) - Username is blank or user not found
Source

async fn list_users(&self, filter: Option<&str>) -> AuthServiceResult<Vec<User>>

List users with optional filtering.

§Arguments
  • filter - Optional username filter (substring match)
§Returns
  • Ok(Vec<User>) - List of matching users
  • Err(AuthServiceError) - Query error
Source

async fn is_super_user(&self, username: &str) -> AuthServiceResult<bool>

Check if a user is a super user.

§Arguments
  • username - The username to check
§Returns
  • Ok(true) - User exists and is a super user
  • Ok(false) - User doesn’t exist or is not a super user
  • Err(AuthServiceError) - Query error

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§