Skip to main content

reifydb_auth/
registry.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use std::collections::HashMap;
5
6use reifydb_core::interface::auth::AuthenticationProvider;
7
8use crate::{password::PasswordProvider, token::TokenProvider};
9
10pub struct AuthenticationRegistry {
11	providers: HashMap<String, Box<dyn AuthenticationProvider>>,
12}
13
14impl AuthenticationRegistry {
15	pub fn new() -> Self {
16		let mut providers: HashMap<String, Box<dyn AuthenticationProvider>> = HashMap::new();
17		providers.insert("password".to_string(), Box::new(PasswordProvider));
18		providers.insert("token".to_string(), Box::new(TokenProvider));
19		Self {
20			providers,
21		}
22	}
23
24	pub fn get(&self, method: &str) -> Option<&dyn AuthenticationProvider> {
25		self.providers.get(method).map(|p| p.as_ref())
26	}
27}
28
29impl Default for AuthenticationRegistry {
30	fn default() -> Self {
31		Self::new()
32	}
33}