@@ -135,84 +135,82 @@ def parse(
135135 idp_entity_id = want_authn_requests_signed = idp_name_id_format = idp_sso_url = idp_slo_url = certs = None
136136
137137 if len (entity_descriptor_nodes ) > 0 :
138- for entity_descriptor_node in entity_descriptor_nodes :
139- idp_descriptor_nodes = OneLogin_Saml2_Utils .query (entity_descriptor_node , './md:IDPSSODescriptor' )
140- if len (idp_descriptor_nodes ) > 0 :
141- idp_descriptor_node = idp_descriptor_nodes [0 ]
142-
143- idp_entity_id = entity_descriptor_node .get ('entityID' , None )
144-
145- want_authn_requests_signed = entity_descriptor_node .get ('WantAuthnRequestsSigned' , None )
146-
147- name_id_format_nodes = OneLogin_Saml2_Utils .query (idp_descriptor_node , './md:NameIDFormat' )
148- if len (name_id_format_nodes ) > 0 :
149- idp_name_id_format = name_id_format_nodes [0 ].text
150-
151- sso_nodes = OneLogin_Saml2_Utils .query (
152- idp_descriptor_node ,
153- "./md:SingleSignOnService[@Binding='%s']" % required_sso_binding
154- )
155-
156- if len (sso_nodes ) > 0 :
157- idp_sso_url = sso_nodes [0 ].get ('Location' , None )
158-
159- slo_nodes = OneLogin_Saml2_Utils .query (
160- idp_descriptor_node ,
161- "./md:SingleLogoutService[@Binding='%s']" % required_slo_binding
162- )
163- if len (slo_nodes ) > 0 :
164- idp_slo_url = slo_nodes [0 ].get ('Location' , None )
165-
166- signing_nodes = OneLogin_Saml2_Utils .query (idp_descriptor_node , "./md:KeyDescriptor[not(contains(@use, 'encryption'))]/ds:KeyInfo/ds:X509Data/ds:X509Certificate" )
167- encryption_nodes = OneLogin_Saml2_Utils .query (idp_descriptor_node , "./md:KeyDescriptor[not(contains(@use, 'signing'))]/ds:KeyInfo/ds:X509Data/ds:X509Certificate" )
168-
169- if len (signing_nodes ) > 0 or len (encryption_nodes ) > 0 :
170- certs = {}
171- if len (signing_nodes ) > 0 :
172- certs ['signing' ] = []
173- for cert_node in signing_nodes :
174- certs ['signing' ].append ('' .join (cert_node .text .split ()))
175- if len (encryption_nodes ) > 0 :
176- certs ['encryption' ] = []
177- for cert_node in encryption_nodes :
178- certs ['encryption' ].append ('' .join (cert_node .text .split ()))
179-
180- data ['idp' ] = {}
181-
182- if idp_entity_id is not None :
183- data ['idp' ]['entityId' ] = idp_entity_id
184-
185- if idp_sso_url is not None :
186- data ['idp' ]['singleSignOnService' ] = {}
187- data ['idp' ]['singleSignOnService' ]['url' ] = idp_sso_url
188- data ['idp' ]['singleSignOnService' ]['binding' ] = required_sso_binding
189-
190- if idp_slo_url is not None :
191- data ['idp' ]['singleLogoutService' ] = {}
192- data ['idp' ]['singleLogoutService' ]['url' ] = idp_slo_url
193- data ['idp' ]['singleLogoutService' ]['binding' ] = required_slo_binding
194-
195- if certs is not None :
196- if len (certs ) == 1 or \
197- (('signing' in certs and len (certs ['signing' ]) == 1 ) and
198- ('encryption' in certs and len (certs ['encryption' ]) == 1 and
199- certs ['signing' ][0 ] == certs ['encryption' ][0 ])):
200- if 'signing' in certs :
201- data ['idp' ]['x509cert' ] = certs ['signing' ][0 ]
202- else :
203- data ['idp' ]['x509cert' ] = certs ['encryption' ][0 ]
138+ entity_descriptor_node = entity_descriptor_nodes [0 ]
139+ idp_descriptor_nodes = OneLogin_Saml2_Utils .query (entity_descriptor_node , './md:IDPSSODescriptor' )
140+ if len (idp_descriptor_nodes ) > 0 :
141+ idp_descriptor_node = idp_descriptor_nodes [0 ]
142+
143+ idp_entity_id = entity_descriptor_node .get ('entityID' , None )
144+
145+ want_authn_requests_signed = entity_descriptor_node .get ('WantAuthnRequestsSigned' , None )
146+
147+ name_id_format_nodes = OneLogin_Saml2_Utils .query (idp_descriptor_node , './md:NameIDFormat' )
148+ if len (name_id_format_nodes ) > 0 :
149+ idp_name_id_format = name_id_format_nodes [0 ].text
150+
151+ sso_nodes = OneLogin_Saml2_Utils .query (
152+ idp_descriptor_node ,
153+ "./md:SingleSignOnService[@Binding='%s']" % required_sso_binding
154+ )
155+
156+ if len (sso_nodes ) > 0 :
157+ idp_sso_url = sso_nodes [0 ].get ('Location' , None )
158+
159+ slo_nodes = OneLogin_Saml2_Utils .query (
160+ idp_descriptor_node ,
161+ "./md:SingleLogoutService[@Binding='%s']" % required_slo_binding
162+ )
163+ if len (slo_nodes ) > 0 :
164+ idp_slo_url = slo_nodes [0 ].get ('Location' , None )
165+
166+ signing_nodes = OneLogin_Saml2_Utils .query (idp_descriptor_node , "./md:KeyDescriptor[not(contains(@use, 'encryption'))]/ds:KeyInfo/ds:X509Data/ds:X509Certificate" )
167+ encryption_nodes = OneLogin_Saml2_Utils .query (idp_descriptor_node , "./md:KeyDescriptor[not(contains(@use, 'signing'))]/ds:KeyInfo/ds:X509Data/ds:X509Certificate" )
168+
169+ if len (signing_nodes ) > 0 or len (encryption_nodes ) > 0 :
170+ certs = {}
171+ if len (signing_nodes ) > 0 :
172+ certs ['signing' ] = []
173+ for cert_node in signing_nodes :
174+ certs ['signing' ].append ('' .join (cert_node .text .split ()))
175+ if len (encryption_nodes ) > 0 :
176+ certs ['encryption' ] = []
177+ for cert_node in encryption_nodes :
178+ certs ['encryption' ].append ('' .join (cert_node .text .split ()))
179+
180+ data ['idp' ] = {}
181+
182+ if idp_entity_id is not None :
183+ data ['idp' ]['entityId' ] = idp_entity_id
184+
185+ if idp_sso_url is not None :
186+ data ['idp' ]['singleSignOnService' ] = {}
187+ data ['idp' ]['singleSignOnService' ]['url' ] = idp_sso_url
188+ data ['idp' ]['singleSignOnService' ]['binding' ] = required_sso_binding
189+
190+ if idp_slo_url is not None :
191+ data ['idp' ]['singleLogoutService' ] = {}
192+ data ['idp' ]['singleLogoutService' ]['url' ] = idp_slo_url
193+ data ['idp' ]['singleLogoutService' ]['binding' ] = required_slo_binding
194+
195+ if certs is not None :
196+ if len (certs ) == 1 or \
197+ (('signing' in certs and len (certs ['signing' ]) == 1 ) and
198+ ('encryption' in certs and len (certs ['encryption' ]) == 1 and
199+ certs ['signing' ][0 ] == certs ['encryption' ][0 ])):
200+ if 'signing' in certs :
201+ data ['idp' ]['x509cert' ] = certs ['signing' ][0 ]
204202 else :
205- data ['idp' ]['x509certMulti' ] = certs
203+ data ['idp' ]['x509cert' ] = certs ['encryption' ][0 ]
204+ else :
205+ data ['idp' ]['x509certMulti' ] = certs
206206
207- if want_authn_requests_signed is not None :
208- data ['security' ] = {}
209- data ['security' ]['authnRequestsSigned' ] = want_authn_requests_signed
207+ if want_authn_requests_signed is not None :
208+ data ['security' ] = {}
209+ data ['security' ]['authnRequestsSigned' ] = want_authn_requests_signed
210210
211- if idp_name_id_format :
212- data ['sp' ] = {}
213- data ['sp' ]['NameIDFormat' ] = idp_name_id_format
214-
215- break
211+ if idp_name_id_format :
212+ data ['sp' ] = {}
213+ data ['sp' ]['NameIDFormat' ] = idp_name_id_format
216214 return data
217215
218216 @staticmethod
0 commit comments