@@ -247,31 +247,24 @@ def resolve_username(self, username_supplied_by_user):
247
247
if self .escape_userdn :
248
248
search_dn = escape_filter_chars (search_dn )
249
249
conn = self .get_connection (
250
- userdn = search_dn , password = self .lookup_dn_search_password
250
+ userdn = search_dn ,
251
+ password = self .lookup_dn_search_password ,
251
252
)
252
- is_bound = conn .bind ()
253
- if not is_bound :
254
- msg = "Failed to connect to LDAP server with search user '{search_dn}'"
255
- self . log . warning ( msg . format ( search_dn = search_dn ) )
253
+ if not conn .bind ():
254
+ self . log . warning (
255
+ f "Failed to connect to LDAP server with search user '{ search_dn } '"
256
+ )
256
257
return (None , None )
257
258
258
259
search_filter = self .lookup_dn_search_filter .format (
259
- login_attr = self .user_attribute , login = username_supplied_by_user
260
- )
261
- msg = "\n " .join (
262
- [
263
- "Looking up user with:" ,
264
- " search_base = '{search_base}'" ,
265
- " search_filter = '{search_filter}'" ,
266
- " attributes = '{attributes}'" ,
267
- ]
260
+ login_attr = self .user_attribute ,
261
+ login = username_supplied_by_user ,
268
262
)
269
263
self .log .debug (
270
- msg .format (
271
- search_base = self .user_search_base ,
272
- search_filter = search_filter ,
273
- attributes = self .user_attribute ,
274
- )
264
+ "Looking up user with:\n " ,
265
+ f" search_base = '{ self .user_search_base } '\n " ,
266
+ f" search_filter = '{ search_filter } '\n " ,
267
+ f" attributes = '{ self .user_attribute } '" ,
275
268
)
276
269
conn .search (
277
270
search_base = self .user_search_base ,
@@ -281,14 +274,9 @@ def resolve_username(self, username_supplied_by_user):
281
274
)
282
275
response = conn .response
283
276
if len (response ) == 0 or "attributes" not in response [0 ].keys ():
284
- msg = (
285
- "No entry found for user '{username}' "
286
- "when looking up attribute '{attribute}'"
287
- )
288
277
self .log .warning (
289
- msg .format (
290
- username = username_supplied_by_user , attribute = self .user_attribute
291
- )
278
+ f"No entry found for user '{ username_supplied_by_user } ' "
279
+ f"when looking up attribute '{ self .user_attribute } '"
292
280
)
293
281
return (None , None )
294
282
@@ -299,19 +287,11 @@ def resolve_username(self, username_supplied_by_user):
299
287
elif len (user_dn ) == 1 :
300
288
user_dn = user_dn [0 ]
301
289
else :
302
- msg = (
303
- "A lookup of the username '{username}' returned a list "
304
- "of entries for the attribute '{attribute}'. Only the "
305
- "first among these ('{first_entry}') was used. The other "
306
- "entries ({other_entries}) were ignored."
307
- )
308
290
self .log .warn (
309
- msg .format (
310
- username = username_supplied_by_user ,
311
- attribute = self .lookup_dn_user_dn_attribute ,
312
- first_entry = user_dn [0 ],
313
- other_entries = ", " .join (user_dn [1 :]),
314
- )
291
+ f"A lookup of the username '{ username_supplied_by_user } ' returned a list "
292
+ f"of entries for the attribute '{ self .lookup_dn_user_dn_attribute } '. Only "
293
+ f"the first among these ('{ user_dn [0 ]} ') was used. The other entries "
294
+ f"({ ', ' .join (user_dn [1 :])} ) were ignored."
315
295
)
316
296
user_dn = user_dn [0 ]
317
297
@@ -389,8 +369,7 @@ def authenticate(self, handler, data):
389
369
userdn = dn .format (username = username )
390
370
if self .escape_userdn :
391
371
userdn = escape_filter_chars (userdn )
392
- msg = "Attempting to bind {username} with {userdn}"
393
- self .log .debug (msg .format (username = username , userdn = userdn ))
372
+ self .log .debug (f"Attempting to bind { username } with { userdn } " )
394
373
msg = "Status of user bind {username} with {userdn} : {is_bound}"
395
374
try :
396
375
conn = self .get_connection (userdn , password )
@@ -408,8 +387,7 @@ def authenticate(self, handler, data):
408
387
break
409
388
410
389
if not is_bound :
411
- msg = "Invalid password for user '{username}'"
412
- self .log .warning (msg .format (username = username ))
390
+ self .log .warning (f"Invalid password for user '{ username } '" )
413
391
return None
414
392
415
393
if self .search_filter :
@@ -424,20 +402,14 @@ def authenticate(self, handler, data):
424
402
)
425
403
n_users = len (conn .response )
426
404
if n_users == 0 :
427
- msg = "User with '{userattr}={username}' not found in directory"
428
405
self .log .warning (
429
- msg . format ( userattr = self .user_attribute , username = username )
406
+ f"User with ' { self .user_attribute } = { username } ' not found in directory"
430
407
)
431
408
return None
432
409
if n_users > 1 :
433
- msg = (
434
- "Duplicate users found! "
435
- "{n_users} users found with '{userattr}={username}'"
436
- )
437
410
self .log .warning (
438
- msg .format (
439
- userattr = self .user_attribute , username = username , n_users = n_users
440
- )
411
+ "Duplicate users found! {n_users} users found "
412
+ f"with '{ self .user_attribute } ={ username } '"
441
413
)
442
414
return None
443
415
@@ -464,8 +436,9 @@ def authenticate(self, handler, data):
464
436
break
465
437
if not found :
466
438
# If we reach here, then none of the groups matched
467
- msg = "username:{username} User not in any of the allowed groups"
468
- self .log .warning (msg .format (username = username ))
439
+ self .log .warning (
440
+ f"username:{ username } User not in any of the allowed groups"
441
+ )
469
442
return None
470
443
471
444
if not self .use_lookup_dn_username :
0 commit comments