@@ -348,41 +348,21 @@ def _populate_attributes(self, config, record):
348
348
}
349
349
return new_attr_values
350
350
351
- def _populate_input_for_name_id (self , config , record , context , data ):
351
+ def _populate_input_for_name_id (self , config , record , data ):
352
352
"""
353
353
Use a record found in LDAP to populate input for
354
354
NameID generation.
355
355
"""
356
- state = context .state
357
-
358
- user_id = ""
359
356
user_id_from_attrs = config ["user_id_from_attrs" ]
360
- for attr in user_id_from_attrs :
361
- if attr in record ["attributes" ]:
362
- value = record ["attributes" ][attr ]
363
- if isinstance (value , list ):
364
- # Use a default sort to ensure some predictability since
365
- # the # LDAP directory server may return multi-valued
366
- # attributes in any order.
367
- value .sort ()
368
- user_id += "" .join (value )
369
- msg = "Added attribute {} with values {} "
370
- msg = msg + "to input for NameID"
371
- msg = msg .format (attr , value )
372
- satosa_logging (logger , logging .DEBUG , msg , state )
373
- else :
374
- user_id += value
375
- msg = "Added attribute {} with value {} to input "
376
- msg = msg + "for NameID"
377
- msg = msg .format (attr , value )
378
- satosa_logging (logger , logging .DEBUG , msg , state )
379
- if not user_id :
380
- msg = "Input for NameID is empty so not overriding default"
381
- satosa_logging (logger , logging .WARNING , msg , state )
382
- else :
383
- data .subject_id = user_id
384
- msg = "Input for NameID is {}" .format (data .subject_id )
385
- satosa_logging (logger , logging .DEBUG , msg , state )
357
+ user_ids = [
358
+ sorted_list_value
359
+ for attr in user_id_from_attrs
360
+ for value in [record ["attributes" ].get (attr )]
361
+ if value
362
+ for list_value in [value if type (value ) is list else [value ]]
363
+ for sorted_list_value in sorted (list_value )
364
+ ]
365
+ return user_ids
386
366
387
367
def process (self , context , data ):
388
368
"""
@@ -544,7 +524,11 @@ def process(self, context, data):
544
524
545
525
# Populate input for NameID if configured. SATOSA core does the
546
526
# hashing of input to create a persistent NameID.
547
- self ._populate_input_for_name_id (config , record , context , data )
527
+ user_ids = self ._populate_input_for_name_id (config , record , data )
528
+ if user_ids :
529
+ data .subject_id = "" .join (user_ids )
530
+ msg = "NameID value is {}" .format (data .subject_id )
531
+ satosa_logging (logger , logging .DEBUG , msg , None )
548
532
549
533
# Add the record to the context so that later microservices
550
534
# may use it if required.
0 commit comments