@@ -248,6 +248,39 @@ def not_on_or_after
248248 @not_on_or_after ||= parse_time ( conditions , "NotOnOrAfter" )
249249 end
250250
251+ # Gets the Issuers (from Response and Assertion).
252+ # (returns the first node that matches the supplied xpath from the Response and from the Assertion)
253+ # @return [Array] Array with the Issuers (REXML::Element)
254+ #
255+ def issuers
256+ @issuers ||= begin
257+ issuers = [ ]
258+ issuer_response_nodes = REXML ::XPath . match (
259+ document ,
260+ "/p:Response/a:Issuer" ,
261+ { "p" => PROTOCOL , "a" => ASSERTION }
262+ )
263+
264+ unless issuer_response_nodes . size == 1
265+ error_msg = "Issuer of the Response not found or multiple."
266+ raise ValidationError . new ( error_msg )
267+ end
268+
269+ doc = decrypted_document . nil? ? document : decrypted_document
270+ issuer_assertion_nodes = xpath_from_signed_assertion ( "/a:Issuer" )
271+ unless issuer_assertion_nodes . size == 1
272+ error_msg = "Issuer of the Assertion not found or multiple."
273+ raise ValidationError . new ( error_msg )
274+ end
275+
276+ nodes = issuer_response_nodes + issuer_assertion_nodes
277+ nodes . each do |node |
278+ issuers << node . text if node . text
279+ end
280+ issuers . uniq
281+ end
282+ end
283+
251284 # @return [String|nil] The InResponseTo attribute from the SAML Response.
252285 #
253286 def in_response_to
@@ -635,32 +668,13 @@ def validate_conditions
635668 def validate_issuer
636669 return true if settings . idp_entity_id . nil?
637670
638- issuers = [ ]
639- issuer_response_nodes = REXML ::XPath . match (
640- document ,
641- "/p:Response/a:Issuer" ,
642- { "p" => PROTOCOL , "a" => ASSERTION }
643- )
644-
645- unless issuer_response_nodes . size == 1
646- error_msg = "Issuer of the Response not found or multiple."
647- return append_error ( error_msg )
648- end
649-
650- doc = decrypted_document . nil? ? document : decrypted_document
651- issuer_assertion_nodes = xpath_from_signed_assertion ( "/a:Issuer" )
652- unless issuer_assertion_nodes . size == 1
653- error_msg = "Issuer of the Assertion not found or multiple."
654- return append_error ( error_msg )
655- end
656-
657- nodes = issuer_response_nodes + issuer_assertion_nodes
658- nodes . each do |node |
659- issuers << node . text if node . text
671+ begin
672+ obtained_issuers = issuers
673+ rescue ValidationError => e
674+ return append_error ( e . message )
660675 end
661- issuers . uniq
662676
663- issuers . each do |issuer |
677+ obtained_issuers . each do |issuer |
664678 unless URI . parse ( issuer ) == URI . parse ( settings . idp_entity_id )
665679 error_msg = "Doesn't match the issuer, expected: <#{ settings . idp_entity_id } >, but was: <#{ issuer } >"
666680 return append_error ( error_msg )
0 commit comments