@@ -10,13 +10,10 @@ module RubySaml
1010 class Response < SamlMessage
1111 include ErrorHandling
1212
13- ASSERTION = "urn:oasis:names:tc:SAML:2.0:assertion"
14- PROTOCOL = "urn:oasis:names:tc:SAML:2.0:protocol"
15- DSIG = "http://www.w3.org/2000/09/xmldsig#"
16- XENC = "http://www.w3.org/2001/04/xmlenc#"
13+ # TODO: Migrate this to RubySaml::XML
1714 SAML_NAMESPACES = {
18- "p" => PROTOCOL ,
19- "a" => ASSERTION
15+ 'p' => RubySaml :: XML :: NS_PROTOCOL ,
16+ 'a' => RubySaml :: XML :: NS_ASSERTION
2017 } . freeze
2118
2219 # TODO: Settings should probably be initialized too... WDYT?
@@ -197,7 +194,7 @@ def handle_rexml_attribute(node, attributes)
197194 # this is useful for allowing eduPersonTargetedId to be passed as an opaque identifier to use to
198195 # identify the subject in an SP rather than email or other less opaque attributes
199196 # NameQualifier, if present is prefixed with a "/" to the value
200- REXML ::XPath . match ( e , 'a:NameID' , { "a" => ASSERTION } ) . collect do |n |
197+ REXML ::XPath . match ( e , 'a:NameID' , { "a" => RubySaml :: XML :: NS_ASSERTION } ) . map do |n |
201198 base_path = n . attributes [ 'NameQualifier' ] ? "#{ n . attributes [ 'NameQualifier' ] } /" : ''
202199 "#{ base_path } #{ Utils . element_text ( n ) } "
203200 end
@@ -224,7 +221,7 @@ def handle_nokogiri_attribute(node, attributes)
224221 # this is useful for allowing eduPersonTargetedId to be passed as an opaque identifier to use to
225222 # identify the subject in an SP rather than email or other less opaque attributes
226223 # NameQualifier, if present is prefixed with a "/" to the value
227- e . xpath ( 'a:NameID' , { "a" => ASSERTION } ) . map do |n |
224+ e . xpath ( 'a:NameID' , { "a" => RubySaml :: XML :: NS_ASSERTION } ) . map do |n |
228225 next unless ( value = n &.content )
229226 base_path = n [ 'NameQualifier' ] ? "#{ n [ 'NameQualifier' ] } /" : ''
230227 "#{ base_path } #{ value } "
@@ -281,7 +278,7 @@ def status_code
281278 nodes = REXML ::XPath . match (
282279 document ,
283280 "/p:Response/p:Status/p:StatusCode" ,
284- { "p" => PROTOCOL }
281+ { "p" => RubySaml :: XML :: NS_PROTOCOL }
285282 )
286283 if nodes . size == 1
287284 node = nodes [ 0 ]
@@ -291,9 +288,9 @@ def status_code
291288 nodes = REXML ::XPath . match (
292289 document ,
293290 "/p:Response/p:Status/p:StatusCode/p:StatusCode" ,
294- { "p" => PROTOCOL }
291+ { "p" => RubySaml :: XML :: NS_PROTOCOL }
295292 )
296- statuses = nodes . collect do |inner_node |
293+ statuses = nodes . map do |inner_node |
297294 inner_node . attributes [ "Value" ]
298295 end
299296
@@ -312,7 +309,7 @@ def status_message
312309 nodes = REXML ::XPath . match (
313310 document ,
314311 "/p:Response/p:Status/p:StatusMessage" ,
315- { "p" => PROTOCOL }
312+ { "p" => RubySaml :: XML :: NS_PROTOCOL }
316313 )
317314
318315 Utils . element_text ( nodes . first ) if nodes . size == 1
@@ -376,7 +373,7 @@ def in_response_to
376373 node = REXML ::XPath . first (
377374 document ,
378375 "/p:Response" ,
379- { "p" => PROTOCOL }
376+ { "p" => RubySaml :: XML :: NS_PROTOCOL }
380377 )
381378 node . nil? ? nil : node . attributes [ 'InResponseTo' ]
382379 end
@@ -389,7 +386,7 @@ def destination
389386 node = REXML ::XPath . first (
390387 document ,
391388 "/p:Response" ,
392- { "p" => PROTOCOL }
389+ { "p" => RubySaml :: XML :: NS_PROTOCOL }
393390 )
394391 node . nil? ? nil : node . attributes [ 'Destination' ]
395392 end
@@ -546,12 +543,12 @@ def validate_num_assertion
546543 assertions = REXML ::XPath . match (
547544 document ,
548545 "//a:Assertion" ,
549- { "a" => ASSERTION }
546+ { "a" => RubySaml :: XML :: NS_ASSERTION }
550547 )
551548 encrypted_assertions = REXML ::XPath . match (
552549 document ,
553550 "//a:EncryptedAssertion" ,
554- { "a" => ASSERTION }
551+ { "a" => RubySaml :: XML :: NS_ASSERTION }
555552 )
556553
557554 unless assertions . size + encrypted_assertions . size == 1
@@ -562,7 +559,7 @@ def validate_num_assertion
562559 assertions = REXML ::XPath . match (
563560 decrypted_document ,
564561 "//a:Assertion" ,
565- { "a" => ASSERTION }
562+ { "a" => RubySaml :: XML :: NS_ASSERTION }
566563 )
567564 unless assertions . size == 1
568565 return append_error ( error_msg )
@@ -598,7 +595,7 @@ def validate_signed_elements
598595 signature_nodes = REXML ::XPath . match (
599596 decrypted_document . nil? ? document : decrypted_document ,
600597 "//ds:Signature" ,
601- { "ds" => DSIG }
598+ { "ds" => RubySaml :: XML :: DSIG }
602599 )
603600 signed_elements = [ ]
604601 verified_seis = [ ]
@@ -620,7 +617,7 @@ def validate_signed_elements
620617 verified_ids . push ( id )
621618
622619 # Check that reference URI matches the parent ID and no duplicate References or IDs
623- ref = REXML ::XPath . first ( signature_node , ".//ds:Reference" , { "ds" => DSIG } )
620+ ref = REXML ::XPath . first ( signature_node , ".//ds:Reference" , { "ds" => RubySaml :: XML :: DSIG } )
624621 if ref
625622 uri = ref . attributes . get_attribute ( "URI" )
626623 if uri && !uri . value . empty?
@@ -838,7 +835,7 @@ def validate_subject_confirmation
838835 confirmation_data_node = REXML ::XPath . first (
839836 subject_confirmation ,
840837 'a:SubjectConfirmationData' ,
841- { "a" => ASSERTION }
838+ { "a" => RubySaml :: XML :: NS_ASSERTION }
842839 )
843840
844841 next unless confirmation_data_node
@@ -870,7 +867,7 @@ def validate_subject_confirmation_nokogiri(subject_confirmation_nodes)
870867 next
871868 end
872869
873- confirmation_data_node = subject_confirmation . at_xpath ( 'a:SubjectConfirmationData' , { "a" => ASSERTION } )
870+ confirmation_data_node = subject_confirmation . at_xpath ( 'a:SubjectConfirmationData' , { "a" => RubySaml :: XML :: NS_ASSERTION } )
874871
875872 next unless confirmation_data_node
876873
@@ -916,7 +913,7 @@ def doc_to_validate
916913 sig_elements = REXML ::XPath . match (
917914 document ,
918915 "/p:Response[@ID=$id]/ds:Signature" ,
919- { "p" => PROTOCOL , "ds" => DSIG } ,
916+ { "p" => RubySaml :: XML :: NS_PROTOCOL , "ds" => RubySaml :: XML :: DSIG } ,
920917 { 'id' => document . signed_element_id }
921918 )
922919
@@ -941,7 +938,7 @@ def validate_signature
941938 sig_elements = REXML ::XPath . match (
942939 document ,
943940 "/p:Response[@ID=$id]/ds:Signature" ,
944- { "p" => PROTOCOL , "ds" => DSIG } ,
941+ { "p" => RubySaml :: XML :: NS_PROTOCOL , "ds" => RubySaml :: XML :: DSIG } ,
945942 { 'id' => document . signed_element_id }
946943 )
947944
@@ -950,7 +947,7 @@ def validate_signature
950947 sig_elements = REXML ::XPath . match (
951948 doc ,
952949 "/p:Response/a:Assertion[@ID=$id]/ds:Signature" ,
953- SAML_NAMESPACES . merge ( { "ds" => DSIG } ) ,
950+ SAML_NAMESPACES . merge ( { "ds" => RubySaml :: XML :: DSIG } ) ,
954951 { 'id' => doc . signed_element_id }
955952 )
956953 end
@@ -1037,10 +1034,10 @@ def cached_signed_assertion
10371034
10381035 assertion = empty_doc
10391036 if root . name == "Response"
1040- if REXML ::XPath . first ( root , "a:Assertion" , { "a" => ASSERTION } )
1041- assertion = REXML ::XPath . first ( root , "a:Assertion" , { "a" => ASSERTION } )
1042- elsif REXML ::XPath . first ( root , "a:EncryptedAssertion" , { "a" => ASSERTION } )
1043- assertion = RubySaml ::XML ::Decryptor . decrypt_assertion ( REXML ::XPath . first ( root , "a:EncryptedAssertion" , { "a" => ASSERTION } ) , settings &.get_sp_decryption_keys )
1037+ if REXML ::XPath . first ( root , "a:Assertion" , { "a" => RubySaml :: XML :: NS_ASSERTION } )
1038+ assertion = REXML ::XPath . first ( root , "a:Assertion" , { "a" => RubySaml :: XML :: NS_ASSERTION } )
1039+ elsif REXML ::XPath . first ( root , "a:EncryptedAssertion" , { "a" => RubySaml :: XML :: NS_ASSERTION } )
1040+ assertion = RubySaml ::XML ::Decryptor . decrypt_assertion ( REXML ::XPath . first ( root , "a:EncryptedAssertion" , { "a" => RubySaml :: XML :: NS_ASSERTION } ) , settings &.get_sp_decryption_keys )
10441041 end
10451042 elsif root . name == "Assertion"
10461043 assertion = root
0 commit comments