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§
Sourceasync fn shutdown(&mut self) -> AuthServiceResult<()>
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
Sourceasync fn init_user(&self, auth_config: &AuthConfig) -> AuthServiceResult<()>
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
Sourceasync fn create_user(&self, user: User) -> AuthServiceResult<()>
async fn create_user(&self, user: User) -> AuthServiceResult<()>
Create a new user.
§Arguments
user- The user to create
§Returns
Ok(())- User created successfullyErr(AuthServiceError)- Validation failed or creation error
§Errors
AuthenticationFailed- Username is blank or invalidInvalidCredential- Password is missing or invalid- Storage errors from underlying provider
Sourceasync fn update_user(&self, user: User) -> AuthServiceResult<()>
async fn update_user(&self, user: User) -> AuthServiceResult<()>
Sourceasync fn delete_user(&self, username: &str) -> AuthServiceResult<()>
async fn delete_user(&self, username: &str) -> AuthServiceResult<()>
Sourceasync fn get_user(&self, username: &str) -> AuthServiceResult<User>
async fn get_user(&self, username: &str) -> AuthServiceResult<User>
Sourceasync fn list_users(&self, filter: Option<&str>) -> AuthServiceResult<Vec<User>>
async fn list_users(&self, filter: Option<&str>) -> AuthServiceResult<Vec<User>>
Sourceasync fn is_super_user(&self, username: &str) -> AuthServiceResult<bool>
async fn is_super_user(&self, username: &str) -> AuthServiceResult<bool>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".