@@ -160,10 +160,10 @@ const DROP_HEADERS: [&str; 4] = ["authorization", "cookie", "user-agent", "x-p-s
160160
161161pub struct AuditLogBuilder {
162162 version : AuditLogVersion ,
163- pub deployment_id : Ulid ,
163+ deployment_id : Ulid ,
164164 audit_id : Ulid ,
165165 start_time : DateTime < Utc > ,
166- pub stream : String ,
166+ stream : String ,
167167 pub actor : ActorLog ,
168168 pub request : RequestLog ,
169169 pub response : ResponseLog ,
@@ -198,7 +198,23 @@ impl AuditLogBuilder {
198198 }
199199
200200 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+ }
202218
203219 let conn = req. connection_info ( ) ;
204220 self . request = RequestLog {
@@ -235,27 +251,6 @@ impl AuditLogBuilder {
235251 }
236252}
237253
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-
259254impl Drop for AuditLogBuilder {
260255 fn drop ( & mut self ) {
261256 let audit_json = json ! ( {
0 commit comments