actix_web_security/authentication/scheme/basic/
user_details_service.rs

1//! The trait definition of a user details service and its clone capabilities for basic authentication.
2
3use async_trait::async_trait;
4use downcast_rs::impl_downcast;
5use downcast_rs::Downcast;
6
7use crate::user_details::UserDetails;
8
9/// The trait definition of a user details service for basic authentication.
10/// A user details service is used to load the `UserDetails` for a given username
11/// and passwort from a datastore.
12#[async_trait]
13pub trait BasicUserDetailsService: Downcast + BasicUserDetailsServiceClone {
14    async fn find_user(&self, username: &str, password: &str) -> Option<Box<dyn UserDetails>>;
15}
16impl_downcast!(BasicUserDetailsService);
17
18/// An user details service must be cloneable, `send` and `sync`.
19/// Therefore it has to implement the `BasicUserDetailsServiceClone` trait to be cloneable as a boxed object.
20pub trait BasicUserDetailsServiceClone: Sync + Send {
21    fn clone_box(&self) -> Box<dyn BasicUserDetailsService>;
22}
23
24impl<U> BasicUserDetailsServiceClone for U
25where
26    U: 'static + BasicUserDetailsService + Clone,
27{
28    fn clone_box(&self) -> Box<dyn BasicUserDetailsService> {
29        Box::new(self.clone())
30    }
31}
32
33impl Clone for Box<dyn BasicUserDetailsService> {
34    fn clone(&self) -> Self {
35        self.clone_box()
36    }
37}