1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! # Actix Security
//!
//! Spring Security-inspired authentication and authorization for Actix Web.
//!
//! This crate provides a unified API combining:
//! - `actix-security-core`: Security middleware, authentication, and authorization
//! - `actix-security-codegen`: Procedural macros (`#[secured]`, `#[pre_authorize]`, etc.)
//!
//! ## Quick Start
//!
//! Add to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! actix-web = "4"
//! actix-security = { version = "0.2", features = ["argon2", "http-basic"] }
//! ```
//!
//! ## Example
//!
//! ```rust,ignore
//! use actix_web::{get, App, HttpServer, HttpResponse, Responder};
//! use actix_security::{secured, pre_authorize};
//! use actix_security::http::security::{
//! AuthenticatedUser, AuthenticationManager, AuthorizationManager,
//! Argon2PasswordEncoder, PasswordEncoder, User,
//! };
//! use actix_security::http::security::middleware::SecurityTransform;
//!
//! #[secured("ADMIN")]
//! #[get("/admin")]
//! async fn admin(user: AuthenticatedUser) -> impl Responder {
//! HttpResponse::Ok().body(format!("Welcome, Admin {}!", user.get_username()))
//! }
//!
//! #[pre_authorize("hasRole('USER') AND hasAuthority('posts:write')")]
//! #[post("/posts")]
//! async fn create_post(user: AuthenticatedUser) -> impl Responder {
//! HttpResponse::Created().body("Post created")
//! }
//! ```
//!
//! ## Features
//!
//! | Feature | Default | Description |
//! |---------|---------|-------------|
//! | `macros` | Yes | Procedural macros (`#[secured]`, `#[pre_authorize]`, etc.) |
//! | `argon2` | Yes | Argon2 password encoder |
//! | `http-basic` | Yes | HTTP Basic authentication |
//! | `jwt` | No | JWT authentication (with RSA support) |
//! | `session` | No | Session-based authentication with fixation protection |
//! | `form-login` | No | Form-based login with redirect support |
//! | `remember-me` | No | Remember-me persistent authentication |
//! | `csrf` | No | CSRF protection middleware |
//! | `oauth2` | No | OAuth2/OIDC authentication |
//! | `user-details` | No | Async UserDetailsService trait |
//! | `full` | No | All features enabled |
//!
//! ## Modules
//!
//! The main functionality is available through the `http` module:
//!
//! - [`http::security`] - Authentication, authorization, and middleware
//! - [`http::error`] - Error types
// Re-export everything from actix-security-core
pub use *;
// Re-export actix_security_core as a module so macros can find it
// This is needed because macros generate code like ::actix_security_core::http::error::AuthError
pub use actix_security_core;
// Re-export procedural macros when the "macros" feature is enabled
pub use *;
/// Prelude module for convenient imports