@@ -329,32 +329,24 @@ def _ldap_connection_factory(self, config):
329
329
330
330
return connection
331
331
332
- def _populate_attributes (self , config , record , context , data ):
332
+ def _populate_attributes (self , config , record ):
333
333
"""
334
334
Use a record found in LDAP to populate attributes.
335
335
"""
336
- state = context .state
337
- attributes = data .attributes
338
-
339
- if config ["ldap_to_internal_map" ]:
340
- ldap_to_internal_map = config ["ldap_to_internal_map" ]
341
- else :
336
+ ldap_to_internal_map = (
337
+ config ["ldap_to_internal_map" ]
338
+ if config ["ldap_to_internal_map" ]
342
339
# Deprecated configuration. Will be removed in future.
343
- ldap_to_internal_map = config ["search_return_attributes" ]
344
- for attr in ldap_to_internal_map .keys ():
345
- if attr in record ["attributes" ]:
346
- if record ["attributes" ][attr ]:
347
- internal_attr = ldap_to_internal_map [attr ]
348
- value = record ["attributes" ][attr ]
349
- attributes [internal_attr ] = value
350
- msg = "Setting internal attribute {} with values {}"
351
- msg = msg .format (internal_attr , value )
352
- satosa_logging (logger , logging .DEBUG , msg , state )
353
- else :
354
- msg = "Not setting internal attribute {} because value {}"
355
- msg = msg + " is null or empty"
356
- msg = msg .format (internal_attr , value )
357
- satosa_logging (logger , logging .DEBUG , msg , state )
340
+ else config ["search_return_attributes" ]
341
+ )
342
+
343
+ new_attr_values = {
344
+ internal_attr : value
345
+ for attr , internal_attr in ldap_to_internal_map .items ()
346
+ for value in [record ["attributes" ].get (attr )]
347
+ if value
348
+ }
349
+ return new_attr_values
358
350
359
351
def _populate_input_for_name_id (self , config , record , context , data ):
360
352
"""
@@ -546,7 +538,9 @@ def process(self, context, data):
546
538
satosa_logging (logger , logging .DEBUG , msg , state )
547
539
548
540
# Populate attributes as configured.
549
- self ._populate_attributes (config , record , context , data )
541
+ new_attrs = self ._populate_attributes (config , record )
542
+ msg = "Updating internal attributes with new values {}" .format (new_attrs )
543
+ satosa_logging (logger , logging .DEBUG , msg , None )
550
544
551
545
# Populate input for NameID if configured. SATOSA core does the
552
546
# hashing of input to create a persistent NameID.
0 commit comments