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
// Copyright (c) 2026 Kirky.X🌠
// SPDX-License-Identifier: Apache-2.0
//! 密码策略套件子模块(吸收 Keycloak PasswordPolicyRule):可插拔规则 + 统一引擎执行。
//!
//! # 核心类型
//!
//! `PasswordPolicyRule` trait 为规则抽象(同步纯函数,`name` + `validate`),`PolicyContext` 为校验上下文,
//! `PasswordPolicyEngine` 为规则引擎(FirstError/AllErrors),`PolicyError` 为校验错误。
//!
//! # 设计
//!
//! 规则为同步纯函数(无 IO/await),参数由构造器注入(支持 `GarrisonConfig` 加载);引擎按 `ErrorMode`
//! 执行:`FirstError` 短路,`AllErrors` 收集全部。
pub use PolicyError;
use Arc;
/// 密码策略规则 trait:同步纯函数(不执行 IO/await,无 `#[async_trait]`),对象安全,可作
/// `Box<dyn PasswordPolicyRule>` / `Vec<Box<dyn PasswordPolicyRule>>` 使用。
///
/// # 示例
///
/// ```ignore
/// use garrison::account::policy::{PasswordPolicyRule, PolicyContext, PolicyError};
///
/// struct AlwaysPassRule;
/// impl PasswordPolicyRule for AlwaysPassRule {
/// fn name(&self) -> &'static str { "always_pass" }
/// fn validate(&self, _ctx: &PolicyContext, _password: &str) -> Result<(), PolicyError> {
/// Ok(())
/// }
/// }
/// ```
/// 策略校验上下文(6 字段 schema 锁定,pre-1.0 起字段不可增删)。
/// 引擎错误返回模式。
/// 密码策略引擎:持规则列表 + 错误模式,按 `mode` 执行规则校验。
///
/// # 示例
///
/// ```ignore
/// use garrison::account::policy::{ErrorMode, PasswordPolicyEngine, PolicyContext};
/// // 实现具体规则后注入
/// let engine = PasswordPolicyEngine::new(Vec::new(), ErrorMode::FirstError);
/// let ctx = PolicyContext {
/// user_id: "alice".into(),
/// tenant_id: None,
/// username: None,
/// email: None,
/// password_history: Vec::new(),
/// password_created_at: None,
/// };
/// assert!(engine.validate(&ctx, "password").is_ok()); // 空规则集 → Ok
/// ```