#[secured]Expand description
Role-based method security annotation.
§Spring Security Equivalent
@Secured("ROLE_ADMIN") or @RolesAllowed("ADMIN")
§Usage
ⓘ
use actix_security_core::http::security::AuthenticatedUser;
use actix_security_codegen::secured;
// Single role
#[secured("ADMIN")]
#[get("/admin")]
async fn admin_only(user: AuthenticatedUser) -> impl Responder {
HttpResponse::Ok().body("Admin area")
}
// Multiple roles (OR logic - user needs ANY of these)
#[secured("ADMIN", "MANAGER")]
#[get("/management")]
async fn management(user: AuthenticatedUser) -> impl Responder {
HttpResponse::Ok().body("Management area")
}§Note
Unlike Spring Security, you don’t need the “ROLE_” prefix. The macro checks if the user has ANY of the specified roles.