@@ -11,31 +11,20 @@ module RubySaml
1111 # make sure to validate it properly before use it in a parse_remote method.
1212 # Read the `Security warning` section of the README.md file to get more info
1313 class IdpMetadataParser
14- module SamlMetadata
15- module Vocabulary
16- METADATA = "urn:oasis:names:tc:SAML:2.0:metadata"
17- DSIG = "http://www.w3.org/2000/09/xmldsig#"
18- NAME_FORMAT = "urn:oasis:names:tc:SAML:2.0:attrname-format:*"
19- SAML_ASSERTION = "urn:oasis:names:tc:SAML:2.0:assertion"
20- end
21-
22- NAMESPACE = {
23- "md" => Vocabulary ::METADATA ,
24- "NameFormat" => Vocabulary ::NAME_FORMAT ,
25- "saml" => Vocabulary ::SAML_ASSERTION ,
26- "ds" => Vocabulary ::DSIG
27- } . freeze
28- end
14+ NAMESPACES = {
15+ "ds" => RubySaml ::XML ::DSIG ,
16+ "md" => RubySaml ::XML ::NS_METADATA ,
17+ "saml" => RubySaml ::XML ::NS_ASSERTION
18+ } . freeze
2919
30- include SamlMetadata ::Vocabulary
3120 attr_reader :document
3221 attr_reader :response
3322 attr_reader :options
3423
3524 # fetch IdP descriptors from a metadata document
3625 def self . get_idps ( noko_document , only_entity_id = nil )
3726 path = "//md:EntityDescriptor#{ "[@entityID=\" #{ only_entity_id } \" ]" if only_entity_id } /md:IDPSSODescriptor"
38- noko_document . xpath ( path , SamlMetadata :: NAMESPACE )
27+ noko_document . xpath ( path , NAMESPACES )
3928 end
4029
4130 # Parse the Identity Provider metadata and update the settings with the
@@ -272,7 +261,7 @@ def cache_duration
272261 def idp_name_id_format ( name_id_priority = nil )
273262 nodes = @idpsso_descriptor . xpath (
274263 "md:NameIDFormat" ,
275- SamlMetadata :: NAMESPACE
264+ NAMESPACES
276265 )
277266 first_ranked_text ( nodes , name_id_priority )
278267 end
@@ -283,7 +272,7 @@ def idp_name_id_format(name_id_priority = nil)
283272 def single_signon_service_binding ( binding_priority = nil )
284273 nodes = @idpsso_descriptor . xpath (
285274 "md:SingleSignOnService/@Binding" ,
286- SamlMetadata :: NAMESPACE
275+ NAMESPACES
287276 )
288277 first_ranked_value ( nodes , binding_priority )
289278 end
@@ -294,7 +283,7 @@ def single_signon_service_binding(binding_priority = nil)
294283 def single_logout_service_binding ( binding_priority = nil )
295284 nodes = @idpsso_descriptor . xpath (
296285 "md:SingleLogoutService/@Binding" ,
297- SamlMetadata :: NAMESPACE
286+ NAMESPACES
298287 )
299288 first_ranked_value ( nodes , binding_priority )
300289 end
@@ -308,7 +297,7 @@ def single_signon_service_url(binding_priority = nil)
308297
309298 @idpsso_descriptor . at_xpath (
310299 "md:SingleSignOnService[@Binding=\" #{ binding } \" ]/@Location" ,
311- SamlMetadata :: NAMESPACE
300+ NAMESPACES
312301 ) &.value
313302 end
314303
@@ -321,7 +310,7 @@ def single_logout_service_url(binding_priority = nil)
321310
322311 @idpsso_descriptor . at_xpath (
323312 "md:SingleLogoutService[@Binding=\" #{ binding } \" ]/@Location" ,
324- SamlMetadata :: NAMESPACE
313+ NAMESPACES
325314 ) &.value
326315 end
327316
@@ -334,7 +323,7 @@ def single_logout_response_service_url(binding_priority = nil)
334323
335324 node = @idpsso_descriptor . at_xpath (
336325 "md:SingleLogoutService[@Binding=\" #{ binding } \" ]/@ResponseLocation" ,
337- SamlMetadata :: NAMESPACE
326+ NAMESPACES
338327 )
339328 node &.value
340329 end
@@ -345,12 +334,12 @@ def certificates
345334 @certificates ||= begin
346335 signing_nodes = @idpsso_descriptor . xpath (
347336 "md:KeyDescriptor[not(contains(@use, 'encryption'))]/ds:KeyInfo/ds:X509Data/ds:X509Certificate" ,
348- SamlMetadata :: NAMESPACE
337+ NAMESPACES
349338 )
350339
351340 encryption_nodes = @idpsso_descriptor . xpath (
352341 "md:KeyDescriptor[not(contains(@use, 'signing'))]/ds:KeyInfo/ds:X509Data/ds:X509Certificate" ,
353- SamlMetadata :: NAMESPACE
342+ NAMESPACES
354343 )
355344
356345 return nil if signing_nodes . empty? && encryption_nodes . empty?
@@ -389,7 +378,7 @@ def fingerprint(certificate, fingerprint_algorithm = RubySaml::XML::SHA256)
389378 def attribute_names
390379 nodes = @idpsso_descriptor . xpath (
391380 "saml:Attribute/@Name" ,
392- SamlMetadata :: NAMESPACE
381+ NAMESPACES
393382 )
394383 nodes . map ( &:value )
395384 end
0 commit comments