Module libunftp::auth [−][src]
Contains the Authenticator
and UserDetail
traits that are used to extend libunftp’s authentication and user detail storage capabilities.
Pre-made implemenations exists on crates.io and you can define your own implementation to
integrate your FTP(S) server with whatever authentication mechanism you need. For example, to
define an Authenticator
that will randomly decide:
- Declare a dependency on the async-trait crate
async-trait = "0.1.42"
- Implement the
Authenticator
trait and optionally theUserDetail
trait:
use libunftp::auth::{Authenticator, AuthenticationError, UserDetail}; use async_trait::async_trait; use unftp_sbe_fs::Filesystem; #[derive(Debug)] struct RandomAuthenticator; #[async_trait] impl Authenticator<RandomUser> for RandomAuthenticator { async fn authenticate(&self, _username: &str, _password: &str) -> Result<RandomUser, AuthenticationError> { Ok(RandomUser{}) } } #[derive(Debug)] struct RandomUser; impl UserDetail for RandomUser {} impl std::fmt::Display for RandomUser { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "RandomUser") } }
- Initialize it with the server:
let server = libunftp::Server::with_authenticator( Box::new(move || { unftp_sbe_fs::Filesystem::new("/srv/ftp") }), std::sync::Arc::new(RandomAuthenticator{}) );
Re-exports
pub use anonymous::AnonymousAuthenticator; |
Modules
anonymous | This module provides an anonymous authenticator |
Structs
DefaultUser | DefaultUser is a default implementation of the |
Enums
AuthenticationError | The error type returned by |
Traits
Authenticator | Defines the requirements for Authentication implementations |
UserDetail | UserDetail defines the requirements for implementations that hold Security Subject information for use by the server. |