pub struct BasicAuthConfig {
pub realm: String,
pub validator: Arc<dyn UserValidator>,
pub cache: Option<Arc<AuthCache>>,
pub path_filter: Option<Arc<PathFilter>>,
pub max_header_size: usize,
pub log_failures: bool,
pub custom_error_handler: Option<Arc<dyn Fn(&AuthError, &str) -> HttpResponse + Send + Sync>>,
pub max_concurrent_validations: Option<usize>,
pub validation_timeout: Option<Duration>,
pub rate_limit_per_ip: Option<(usize, Duration)>,
pub enable_metrics: bool,
pub log_usernames_in_production: bool,
}
Expand description
Basic authentication config
Fields§
§realm: String
Authentication realm (for WWW-Authenticate header)
validator: Arc<dyn UserValidator>
User validator
cache: Option<Arc<AuthCache>>
Auth result cache (optional)
path_filter: Option<Arc<PathFilter>>
Path filter (optional)
max_header_size: usize
Request header size limit (bytes)
log_failures: bool
Log details on authentication failure
custom_error_handler: Option<Arc<dyn Fn(&AuthError, &str) -> HttpResponse + Send + Sync>>
Custom error handler
max_concurrent_validations: Option<usize>
Maximum concurrent authentication validations
validation_timeout: Option<Duration>
Validation timeout
rate_limit_per_ip: Option<(usize, Duration)>
Rate limiting: (max_requests, time_window)
enable_metrics: bool
Enable metrics collection
log_usernames_in_production: bool
Log usernames in production (security risk)
Implementations§
Source§impl BasicAuthConfig
impl BasicAuthConfig
Sourcepub fn new(validator: Arc<dyn UserValidator>) -> Self
pub fn new(validator: Arc<dyn UserValidator>) -> Self
Create new basic auth config
Sourcepub fn with_cache(self, cache_config: CacheConfig) -> AuthResult<Self>
pub fn with_cache(self, cache_config: CacheConfig) -> AuthResult<Self>
Create auth config with cache config
Sourcepub fn disable_cache(self) -> Self
pub fn disable_cache(self) -> Self
Disable cache
Sourcepub fn path_filter(self, filter: PathFilter) -> Self
pub fn path_filter(self, filter: PathFilter) -> Self
Set path filter
Sourcepub fn max_header_size(self, size: usize) -> Self
pub fn max_header_size(self, size: usize) -> Self
Set max request header size
Sourcepub fn log_failures(self, enabled: bool) -> Self
pub fn log_failures(self, enabled: bool) -> Self
Enable or disable logging on authentication failure
Sourcepub fn custom_error_handler<F>(self, handler: F) -> Self
pub fn custom_error_handler<F>(self, handler: F) -> Self
Set custom error handler function
Sourcepub fn max_concurrent_validations(self, max: usize) -> Self
pub fn max_concurrent_validations(self, max: usize) -> Self
Set maximum concurrent validations
Sourcepub fn validation_timeout(self, timeout: Duration) -> Self
pub fn validation_timeout(self, timeout: Duration) -> Self
Set validation timeout
Sourcepub fn rate_limit_per_ip(self, max_requests: usize, window: Duration) -> Self
pub fn rate_limit_per_ip(self, max_requests: usize, window: Duration) -> Self
Set rate limiting per IP
Sourcepub fn enable_metrics(self, enabled: bool) -> Self
pub fn enable_metrics(self, enabled: bool) -> Self
Enable or disable metrics collection
Sourcepub fn log_usernames_in_production(self, enabled: bool) -> Self
pub fn log_usernames_in_production(self, enabled: bool) -> Self
Enable or disable logging usernames in production (security risk)
Sourcepub fn validate(&self) -> AuthResult<()>
pub fn validate(&self) -> AuthResult<()>
Enhanced config validation