libunftp 0.23.0

Extensible, async, cloud orientated FTP(S) server library.
Documentation
//! This module provides an anonymous authenticator

use async_trait::async_trait;
use unftp_core::auth::{AuthenticationError, Authenticator, Credentials, Principal};

/// [`Authenticator`] implementation that simply allows everyone.
///
/// # Example
///
/// ```rust
/// # #[tokio::main]
/// # async fn main() {
/// use unftp_core::auth::{Authenticator, Principal};
/// use libunftp::auth::AnonymousAuthenticator;
///
/// let my_auth = AnonymousAuthenticator{};
/// assert_eq!(my_auth.authenticate("Finn", &"I ❤️ PB".into()).await.unwrap().username, "Finn");
/// # }
/// ```
///
#[derive(Debug)]
pub struct AnonymousAuthenticator;

#[async_trait]
impl Authenticator for AnonymousAuthenticator {
    #[allow(clippy::type_complexity)]
    #[tracing_attributes::instrument]
    async fn authenticate(&self, username: &str, _creds: &Credentials) -> Result<Principal, AuthenticationError> {
        Ok(Principal {
            username: username.to_string(),
        })
    }

    async fn cert_auth_sufficient(&self, _username: &str) -> bool {
        true
    }
}