Skip to main content

rocketmq_auth/authentication/provider/
authentication_metadata_provider.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Authentication Metadata Provider Trait (Rust 2021 Standard)
16
17use std::any::Any;
18use std::future::Future;
19use std::pin::Pin;
20use std::sync::Arc;
21
22use crate::authentication::model::user::User;
23use crate::config::AuthConfig;
24use crate::AuthServiceResult;
25
26/// Authentication metadata provider for user management.
27pub trait AuthenticationMetadataProvider: Send + Sync {
28    /// Initialize the provider.
29    fn initialize<'a>(
30        &'a mut self,
31        config: AuthConfig,
32        metadata_service: Option<Arc<dyn Any + Send + Sync>>,
33    ) -> Pin<Box<dyn Future<Output = AuthServiceResult<()>> + Send + 'a>>;
34
35    /// Shutdown the provider.
36    fn shutdown(&mut self) -> Pin<Box<dyn Future<Output = AuthServiceResult<()>> + Send + '_>>;
37
38    /// Create a user.
39    fn create_user<'a>(&'a self, user: User) -> Pin<Box<dyn Future<Output = AuthServiceResult<()>> + Send + 'a>>;
40
41    /// Delete a user.
42    fn delete_user<'a>(&'a self, username: &'a str)
43        -> Pin<Box<dyn Future<Output = AuthServiceResult<()>> + Send + 'a>>;
44
45    /// Update a user.
46    fn update_user<'a>(&'a self, user: User) -> Pin<Box<dyn Future<Output = AuthServiceResult<()>> + Send + 'a>>;
47
48    /// Get a user by username.
49    fn get_user<'a>(&'a self, username: &'a str) -> Pin<Box<dyn Future<Output = AuthServiceResult<User>> + Send + 'a>>;
50
51    /// List users with optional filter.
52    fn list_user<'a>(
53        &'a self,
54        filter: Option<&'a str>,
55    ) -> Pin<Box<dyn Future<Output = AuthServiceResult<Vec<User>>> + Send + 'a>>;
56}