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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//! Copyright (c) 2026 Kirky.X. All rights reserved.
//! See LICENSE for full license text.
//! 上下文模块,提供请求 / 响应 / 存储上下文抽象。
//!
//! 对应 上下文抽象层,
//! 通过 trait 隔离 Web 框架差异,实现框架无关的鉴权逻辑。
//!
//! ## 架构
//!
//! - `GarrisonContext`:上下文入口,提供 request/response/storage 访问
//! - `GarrisonRequest`:HTTP 请求抽象(path/method/header/cookie/get_token)
//! - `GarrisonResponse`:HTTP 响应抽象(set_status/set_header/set_cookie)
//! - `GarrisonStorage`:请求级临时存储(set/get/delete,请求结束清理)
//!
//! ## axum 适配器
//!
//! `feature = "web-axum"` 时提供 `AxumContext` 实现:
//! - `AxumRequest` 包装 `&http::Request<axum::body::Body>`
//! - `AxumResponse` 持有 `HeaderMap + StatusCode`,`to_response()` 转换为 axum Response
//! - `AxumStorage` 用 `HashMap<String, String>`
//!
//! ## actix-web 适配器
//!
//! `feature = "web-actix"` 时提供 `ActixContext` 实现:
//! - `ActixRequest` 包装 `&actix_web::HttpRequest`
//! - `ActixResponse` 持有 `HeaderMap + StatusCode`
//! - `ActixStorage` 用 `HashMap<String, String>`
//!
//! ## warp 适配器
//!
//! `feature = "web-warp"` 时提供 `WarpContext` 实现:
//! - `WarpRequest` 持有 `warp::http::HeaderMap` + path + method(owned)
//! - `WarpResponse` 持有 `HeaderMap + StatusCode`
//! - `WarpStorage` 用 `HashMap<String, String>`
use crateGarrisonResult;
// ============================================================================
// 多租户隔离上下文
// ============================================================================
// ============================================================================
// Token 提取公共函数(供 web 框架适配器与 context 适配器共用,无 feature gate)
// ============================================================================
pub use ;
// ============================================================================
// 登录主体
// ============================================================================
/// 当前请求的登录主体。
///
/// 携带从 token 解析出的 `login_id`,由各 web 框架的 extractor
/// (`web_actix::extractor::GarrisonPrincipal` / `web_warp::extractor::GarrisonPrincipal`)
/// 从 `Authorization: Bearer <token>` header 提取并填充。
///
/// # 字段
///
/// - `login_id`: 当前登录用户 ID,从 token-session 映射解析得到。
///
/// # 使用示例
///
/// ```ignore
/// use garrison::context::GarrisonPrincipal;
///
/// fn handler(principal: GarrisonPrincipal) -> String {
/// format!("login_id = {}", principal.login_id)
/// }
/// ```
/// 上下文 trait,提供请求访问入口。
///
/// 对应 `SaTokenContext`,
/// 各 Web 框架适配需实现此 trait。
///
/// # 设计
///
/// 仅暴露 `request()` 方法获取请求对象。
/// 响应数据写入由具体适配器(如 `AxumContext::raw_response_mut()` / `into_response()`)提供,
/// 避免 trait 方法返回新实例破坏状态共享。
/// 请求抽象 trait,提供 HTTP 请求数据访问。
///
/// 对应 `SaTokenRequest`。
/// 响应抽象 trait,提供 HTTP 响应数据写入。
///
/// 对应 `SaTokenResponse`。
/// 存储抽象 trait,提供请求级临时数据存储。
///
/// 对应 `SaTokenStorage`,
/// 用于在单次请求范围内传递数据(如 trace_id、用户上下文)。
// ============================================================================
// 前后端分离模式辅助函数(实现迁移至 helpers.rs,Rule 25 合规)
// ============================================================================
pub use ;
// ============================================================================
// axum 适配器(feature = "web-axum")
// ============================================================================
pub use ;
// ============================================================================
// actix-web 适配器(feature = "web-actix")
// ============================================================================
pub use ;
// ============================================================================
// warp 适配器(feature = "web-warp")
// ============================================================================
pub use ;