next_web_dev/security/
memory_auth_service.rs1use async_trait::async_trait;
2use hashbrown::HashMap;
3use rudi_dev::Singleton;
4
5use super::{
6 authorization_service::AuthorizationService, login_type::LoginType, user_info::UserInfo,
7};
8
9#[derive(Clone)]
10pub struct MemoryAuthService {
11 users: HashMap<String, UserInfo>,
12}
13
14impl MemoryAuthService {
16 pub fn new() -> Self {
18 Self {
19 users: HashMap::new()
20 }
21 }
22}
23
24#[async_trait]
25impl AuthorizationService<Vec<String>> for MemoryAuthService {
26 async fn user_role(&self, user_id: &String, login_type: &LoginType) -> Vec<String> {
27 vec![]
28 }
29
30 async fn user_permission(&self, user_id: &String, login_type: &LoginType) -> Vec<String> {
31 vec![]
32 }
33
34 async fn verify_token(&self, user_id: &String, login_type: &LoginType) -> bool {
35 self.users.contains_key(user_id)
36 }
37}