@@ -160,10 +160,10 @@ const DROP_HEADERS: [&str; 4] = ["authorization", "cookie", "user-agent", "x-p-s
160
160
161
161
pub struct AuditLogBuilder {
162
162
version : AuditLogVersion ,
163
- pub deployment_id : Ulid ,
163
+ deployment_id : Ulid ,
164
164
audit_id : Ulid ,
165
165
start_time : DateTime < Utc > ,
166
- pub stream : String ,
166
+ stream : String ,
167
167
pub actor : ActorLog ,
168
168
pub request : RequestLog ,
169
169
pub response : ResponseLog ,
@@ -198,7 +198,23 @@ impl AuditLogBuilder {
198
198
}
199
199
200
200
pub fn update_from_http ( & mut self , req : & mut ServiceRequest ) {
201
- let ( username, authorization_method) = get_auth_details ( req) ;
201
+ let mut username = "Unknown" . to_owned ( ) ;
202
+ let mut authorization_method = "None" . to_owned ( ) ;
203
+
204
+ // Extract authorization details from request, either from basic auth
205
+ // header or cookie, else use default value.
206
+ if let Ok ( creds) = req. extract :: < BasicAuth > ( ) . into_inner ( ) {
207
+ username = creds. user_id ( ) . trim ( ) . to_owned ( ) ;
208
+ authorization_method = "Basic Auth" . to_owned ( ) ;
209
+ } else if let Some ( cookie) = req. cookie ( "session" ) {
210
+ authorization_method = "Session Cookie" . to_owned ( ) ;
211
+ if let Some ( user_id) = Ulid :: from_string ( cookie. value ( ) )
212
+ . ok ( )
213
+ . and_then ( |ulid| Users . get_username_from_session ( & SessionKey :: SessionId ( ulid) ) )
214
+ {
215
+ username = user_id;
216
+ }
217
+ }
202
218
203
219
let conn = req. connection_info ( ) ;
204
220
self . request = RequestLog {
@@ -235,27 +251,6 @@ impl AuditLogBuilder {
235
251
}
236
252
}
237
253
238
- fn get_auth_details ( req : & mut ServiceRequest ) -> ( String , String ) {
239
- let mut username = "Unknown" . to_owned ( ) ;
240
- let mut auth_method = "None" . to_owned ( ) ;
241
-
242
- if let Ok ( creds) = req. extract :: < BasicAuth > ( ) . into_inner ( ) {
243
- return ( creds. user_id ( ) . trim ( ) . to_owned ( ) , "Basic Auth" . to_owned ( ) ) ;
244
- }
245
-
246
- if let Some ( cookie) = req. cookie ( "session" ) {
247
- auth_method = "Session Cookie" . to_owned ( ) ;
248
- if let Some ( user_id) = Ulid :: from_string ( cookie. value ( ) )
249
- . ok ( )
250
- . and_then ( |ulid| Users . get_username_from_session ( & SessionKey :: SessionId ( ulid) ) )
251
- {
252
- username = user_id;
253
- }
254
- }
255
-
256
- ( username, auth_method)
257
- }
258
-
259
254
impl Drop for AuditLogBuilder {
260
255
fn drop ( & mut self ) {
261
256
let audit_json = json ! ( {
0 commit comments