Skip to main content

actix_security_core/http/security/
mod.rs

1//! Security module providing authentication and authorization.
2//!
3//! # Spring Equivalent
4//! `org.springframework.security` package
5//!
6//! # Module Structure
7//!
8//! - `authenticator` - User authentication implementations (MemoryAuthenticator)
9//! - `authorizer` - Request authorization implementations (RequestMatcherAuthorizer)
10//! - `config` - Core traits (Authenticator, Authorizer)
11//! - `crypto` - Password encoding (Argon2, BCrypt, NoOp, Delegating)
12//! - `extractor` - Actix Web extractors (AuthenticatedUser, OptionalUser)
13//! - `http_basic` - HTTP Basic Authentication support
14//! - `jwt` - JWT (JSON Web Token) Authentication
15//! - `session` - Session-based Authentication
16//! - `manager` - Factory methods (AuthenticationManager, AuthorizationManager)
17//! - `middleware` - Security middleware (SecurityTransform)
18//! - `user` - User model
19//! - `web` - Re-exports for backward compatibility
20//! - `expression` - Security Expression Language (SpEL-like)
21//! - `context` - Security context for accessing current user
22//! - `headers` - Security headers middleware (X-Frame-Options, CSP, HSTS, etc.)
23//! - `rate_limit` - Rate limiting middleware (brute-force protection)
24//! - `audit` - Security audit logging
25//! - `account` - Account locking on failed attempts
26//! - `ldap` - LDAP/Active Directory Authentication
27//! - `saml` - SAML 2.0 Single Sign-On
28//! - `ant_matcher` - Ant-style URL pattern matching
29//! - `channel` - Channel security (HTTPS enforcement)
30//!
31//! # Feature Flags
32//! - `argon2`: Enables `Argon2PasswordEncoder` and `DelegatingPasswordEncoder`
33//! - `bcrypt`: Enables `BCryptPasswordEncoder`
34//! - `http-basic`: Enables HTTP Basic Authentication
35//! - `jwt`: Enables JWT Authentication
36//! - `session`: Enables Session-based Authentication
37//! - `oauth2`: Enables OAuth2/OIDC Authentication
38//! - `rate-limit`: Enables Rate Limiting middleware
39//! - `audit`: Enables Security Audit Logging
40//! - `account-lock`: Enables Account Locking
41//! - `ldap`: Enables LDAP/Active Directory Authentication
42//! - `saml`: Enables SAML 2.0 Single Sign-On
43
44// Re-exports for convenience
45#[cfg(feature = "account-lock")]
46pub use account::{
47    check_login, AccountLockManager, AccountStats, LockConfig, LockStatus, LoginCheckResult,
48};
49pub use ant_matcher::{AntMatcher, AntMatcherBuilder, AntMatchers, IntoAntMatcher};
50#[cfg(feature = "audit")]
51pub use audit::{
52    audit_log, global_logger, init_global_logger, AuditLogger, InMemoryEventStore, SecurityEvent,
53    SecurityEventHandler, SecurityEventSeverity, SecurityEventType, StdoutHandler,
54};
55pub use authenticator::MemoryAuthenticator;
56pub use authorizer::{Access, RequestMatcherAuthorizer};
57pub use channel::{ChannelRequirement, ChannelSecurity, ChannelSecurityConfig, PortMapper};
58pub use config::{Authenticator, Authorizer};
59pub use context::SecurityContext;
60#[cfg(feature = "bcrypt")]
61pub use crypto::BCryptPasswordEncoder;
62#[cfg(feature = "argon2")]
63pub use crypto::{Argon2PasswordEncoder, DefaultEncoder, DelegatingPasswordEncoder};
64pub use crypto::{NoOpPasswordEncoder, PasswordEncoder};
65#[cfg(feature = "csrf")]
66pub use csrf::{
67    CsrfConfig, CsrfError, CsrfProtection, CsrfToken, CsrfTokenRepository,
68    SessionCsrfTokenRepository,
69};
70pub use extractor::{AuthenticatedUser, OptionalUser, SecurityExt};
71#[cfg(feature = "form-login")]
72pub use form_login::{
73    FormLoginConfig, FormLoginError, FormLoginHandler, FormLoginService, LoginForm,
74};
75pub use headers::SecurityHeaders;
76#[cfg(feature = "http-basic")]
77pub use http_basic::HttpBasicConfig;
78#[cfg(feature = "jwt")]
79pub use jwt::{Claims as JwtClaims, JwtAuthenticator, JwtConfig, JwtTokenService};
80#[cfg(feature = "ldap")]
81pub use ldap::{
82    LdapAuthResult, LdapAuthenticator, LdapConfig, LdapContextMapper, LdapError, MockLdapClient,
83};
84pub use manager::{AuthenticationManager, AuthorizationManager};
85#[cfg(feature = "oauth2")]
86pub use oauth2::{
87    OAuth2Authenticator, OAuth2Client, OAuth2Config, OAuth2Provider, OAuth2User, OidcUser,
88};
89#[cfg(feature = "rate-limit")]
90pub use rate_limit::{
91    KeyExtractor, RateLimitAlgorithm, RateLimitConfig, RateLimitInfo, RateLimiter, RateLimiterState,
92};
93#[cfg(feature = "remember-me")]
94pub use remember_me::{RememberMeConfig, RememberMeError, RememberMeServices, RememberMeToken};
95#[cfg(feature = "saml")]
96pub use saml::{
97    AuthnContextClass, AuthnRequest, NameIdFormat, SamlAssertion, SamlAuthResult,
98    SamlAuthenticator, SamlBinding, SamlConfig, SamlError, SamlResponse, SamlStatusCode,
99};
100#[cfg(feature = "session")]
101pub use session::{
102    CredentialAuthenticator, SessionAuthenticator, SessionConfig, SessionError,
103    SessionFixationStrategy, SessionLoginService, SessionUser,
104};
105pub use user::User;
106#[cfg(feature = "user-details")]
107pub use user_details::{
108    CachingUserDetailsService, InMemoryUserDetailsService, UserDetailsAuthenticator,
109    UserDetailsError, UserDetailsManager, UserDetailsService,
110};
111
112// Internal modules (private implementation details)
113mod config;
114mod extractor;
115mod user;
116
117// Public modules
118#[cfg(feature = "account-lock")]
119pub mod account;
120pub mod ant_matcher;
121#[cfg(feature = "audit")]
122pub mod audit;
123pub mod authenticator;
124pub mod authorizer;
125pub mod channel;
126pub mod context;
127pub mod crypto;
128#[cfg(feature = "csrf")]
129pub mod csrf;
130pub mod expression;
131#[cfg(feature = "form-login")]
132pub mod form_login;
133pub mod headers;
134pub mod http_basic;
135#[cfg(feature = "jwt")]
136pub mod jwt;
137#[cfg(feature = "ldap")]
138pub mod ldap;
139pub mod manager;
140pub mod middleware;
141#[cfg(feature = "oauth2")]
142pub mod oauth2;
143#[cfg(feature = "rate-limit")]
144pub mod rate_limit;
145#[cfg(feature = "remember-me")]
146pub mod remember_me;
147#[cfg(feature = "saml")]
148pub mod saml;
149#[cfg(feature = "session")]
150pub mod session;
151#[cfg(feature = "user-details")]
152pub mod user_details;
153
154// Backward compatibility module
155pub mod web;