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
//! Security Expression Language (SpEL-like) for authorization.
//!
//! # Spring Security Equivalent
//! `org.springframework.security.access.expression`
//!
//! # Overview
//! This module provides a Spring Security-like expression language for
//! defining complex authorization rules.
//!
//! # Supported Expressions
//!
//! ## Built-in Functions
//! - `hasRole('ROLE')` - Check if user has the specified role
//! - `hasAnyRole('ROLE1', 'ROLE2')` - Check if user has any of the roles
//! - `hasAuthority('AUTH')` - Check if user has the specified authority
//! - `hasAnyAuthority('AUTH1', 'AUTH2')` - Check if user has any authority
//! - `isAuthenticated()` - Check if user is authenticated
//! - `permitAll()` - Always returns true
//! - `denyAll()` - Always returns false
//!
//! ## Operators
//! - `AND` / `and` / `&&` - Logical AND
//! - `OR` / `or` / `||` - Logical OR
//! - `NOT` / `not` / `!` - Logical NOT
//! - `(` `)` - Grouping
//!
//! # Examples
//! ```ignore
//! use actix_security_core::http::security::expression::SecurityExpression;
//!
//! let expr = SecurityExpression::parse("hasRole('ADMIN') OR hasAuthority('users:write')")?;
//! let result = expr.evaluate(&user);
//! ```
//!
//! # Extensibility
//! Custom expressions can be added by implementing the `ExpressionRoot` trait:
//!
//! ```ignore
//! use actix_security_core::http::security::expression::{ExpressionRoot, DefaultExpressionRoot};
//! use actix_security_core::http::security::User;
//!
//! struct CustomExpressionRoot {
//! default: DefaultExpressionRoot,
//! }
//!
//! impl ExpressionRoot for CustomExpressionRoot {
//! fn evaluate_function(&self, name: &str, args: &[String], user: Option<&User>) -> Option<bool> {
//! match name {
//! "isAdmin" => Some(user.map_or(false, |u| u.has_role("ADMIN"))),
//! "hasIpAddress" => {
//! // Custom IP check logic
//! Some(true)
//! }
//! _ => self.default.evaluate_function(name, args, user),
//! }
//! }
//! }
//! ```
pub use ;
pub use ExpressionEvaluator;
pub use ;
pub use ;