@@ -526,13 +526,13 @@ def process(self, context, data):
526
526
527
527
# For now consider only the first record found (if any).
528
528
if len (responses ) > 0 :
529
- if len (responses ) > 1 :
529
+ if len (responses ) > 1 and not config . get ( "use_all_results" , False ) :
530
530
msg = "LDAP server returned {} records using search filter"
531
531
msg = msg + " value {}"
532
532
msg = msg .format (len (responses ), filter_val )
533
533
logline = lu .LOG_FMT .format (id = session_id , message = msg )
534
534
logger .warning (logline )
535
- record = responses [0 ]
535
+ responses = responses [0 : 1 ]
536
536
break
537
537
538
538
# Before using a found record, if any, to populate attributes
@@ -544,73 +544,76 @@ def process(self, context, data):
544
544
logger .debug (logline )
545
545
data .attributes = {}
546
546
547
- # This adapts records with different search and connection strategy
548
- # (sync without pool), it should be tested with anonimous bind with
549
- # message_id.
550
- if isinstance (results , bool ) and record :
551
- record = {
552
- "dn" : record .entry_dn if hasattr (record , "entry_dn" ) else "" ,
553
- "attributes" : (
554
- record .entry_attributes_as_dict
555
- if hasattr (record , "entry_attributes_as_dict" )
556
- else {}
557
- ),
558
- }
559
-
560
- # Use a found record, if any, to populate attributes and input for
561
- # NameID
562
- if record :
563
- msg = {
564
- "message" : "Using record with DN and attributes" ,
565
- "DN" : record ["dn" ],
566
- "attributes" : record ["attributes" ],
567
- }
568
- logline = lu .LOG_FMT .format (id = session_id , message = msg )
569
- logger .debug (logline )
547
+ for record in responses :
548
+ # This adapts records with different search and connection strategy
549
+ # (sync without pool), it should be tested with anonimous bind with
550
+ # message_id.
551
+ if isinstance (results , bool ) and record :
552
+ record = {
553
+ "dn" : record .entry_dn if hasattr (record , "entry_dn" ) else "" ,
554
+ "attributes" : (
555
+ record .entry_attributes_as_dict
556
+ if hasattr (record , "entry_attributes_as_dict" )
557
+ else {}
558
+ ),
559
+ }
560
+
561
+ # Use a found record, if any, to populate attributes and input for
562
+ # NameID
563
+ if record :
564
+ msg = {
565
+ "message" : "Using record with DN and attributes" ,
566
+ "DN" : record ["dn" ],
567
+ "attributes" : record ["attributes" ],
568
+ }
569
+ logline = lu .LOG_FMT .format (id = session_id , message = msg )
570
+ logger .debug (logline )
570
571
571
- # Populate attributes as configured.
572
- new_attrs = self ._populate_attributes (config , record )
573
-
574
- overwrite = config ["overwrite_existing_attributes" ]
575
- for attr , values in new_attrs .items ():
576
- if not overwrite :
577
- values = list (set (data .attributes .get (attr , []) + values ))
578
- data .attributes [attr ] = values
579
-
580
- # Populate input for NameID if configured. SATOSA core does the
581
- # hashing of input to create a persistent NameID.
582
- user_ids = self ._populate_input_for_name_id (config , record , data )
583
- if user_ids :
584
- data .subject_id = "" .join (user_ids )
585
- msg = "NameID value is {}" .format (data .subject_id )
586
- logger .debug (msg )
572
+ # Populate attributes as configured.
573
+ new_attrs = self ._populate_attributes (config , record )
574
+
575
+ overwrite = config ["overwrite_existing_attributes" ]
576
+ for attr , values in new_attrs .items ():
577
+ if not overwrite :
578
+ values = list (map (str , set (data .attributes .get (attr , []) + values )))
579
+ else :
580
+ values = list (map (str , set (values )))
581
+ data .attributes [attr ] = values
582
+
583
+ # Populate input for NameID if configured. SATOSA core does the
584
+ # hashing of input to create a persistent NameID.
585
+ user_ids = self ._populate_input_for_name_id (config , record , data )
586
+ if user_ids :
587
+ data .subject_id = "" .join (user_ids )
588
+ msg = "NameID value is {}" .format (data .subject_id )
589
+ logger .debug (msg )
587
590
588
- # Add the record to the context so that later microservices
589
- # may use it if required.
590
- context .decorate (KEY_FOUND_LDAP_RECORD , record )
591
- msg = "Added record {} to context" .format (record )
592
- logline = lu .LOG_FMT .format (id = session_id , message = msg )
593
- logger .debug (logline )
594
- else :
595
- msg = "No record found in LDAP so no attributes will be added"
596
- logline = lu .LOG_FMT .format (id = session_id , message = msg )
597
- logger .warning (logline )
598
- on_ldap_search_result_empty = config ["on_ldap_search_result_empty" ]
599
- if on_ldap_search_result_empty :
600
- # Redirect to the configured URL with
601
- # the entityIDs for the target SP and IdP used by the user
602
- # as query string parameters (URL encoded).
603
- encoded_sp_entity_id = urllib .parse .quote_plus (requester )
604
- encoded_idp_entity_id = urllib .parse .quote_plus (issuer )
605
- url = "{}?sp={}&idp={}" .format (
606
- on_ldap_search_result_empty ,
607
- encoded_sp_entity_id ,
608
- encoded_idp_entity_id ,
609
- )
610
- msg = "Redirecting to {}" .format (url )
591
+ # Add the record to the context so that later microservices
592
+ # may use it if required.
593
+ context .decorate (KEY_FOUND_LDAP_RECORD , record )
594
+ msg = "Added record {} to context" .format (record )
611
595
logline = lu .LOG_FMT .format (id = session_id , message = msg )
612
- logger .info (logline )
613
- return Redirect (url )
596
+ logger .debug (logline )
597
+ else :
598
+ msg = "No record found in LDAP so no attributes will be added"
599
+ logline = lu .LOG_FMT .format (id = session_id , message = msg )
600
+ logger .warning (logline )
601
+ on_ldap_search_result_empty = config ["on_ldap_search_result_empty" ]
602
+ if on_ldap_search_result_empty :
603
+ # Redirect to the configured URL with
604
+ # the entityIDs for the target SP and IdP used by the user
605
+ # as query string parameters (URL encoded).
606
+ encoded_sp_entity_id = urllib .parse .quote_plus (requester )
607
+ encoded_idp_entity_id = urllib .parse .quote_plus (issuer )
608
+ url = "{}?sp={}&idp={}" .format (
609
+ on_ldap_search_result_empty ,
610
+ encoded_sp_entity_id ,
611
+ encoded_idp_entity_id ,
612
+ )
613
+ msg = "Redirecting to {}" .format (url )
614
+ logline = lu .LOG_FMT .format (id = session_id , message = msg )
615
+ logger .info (logline )
616
+ return Redirect (url )
614
617
615
618
msg = "Returning data.attributes {}" .format (data .attributes )
616
619
logline = lu .LOG_FMT .format (id = session_id , message = msg )
0 commit comments