@@ -36,16 +36,14 @@ def validate!
3636 # The value of the user identifier as designated by the initialization request response
3737 def name_id
3838 @name_id ||= begin
39- node = REXML ::XPath . first ( document , "/p:Response/a:Assertion[@ID='#{ document . signed_element_id } ']/a:Subject/a:NameID" , { "p" => PROTOCOL , "a" => ASSERTION } )
40- node ||= REXML ::XPath . first ( document , "/p:Response[@ID='#{ document . signed_element_id } ']/a:Assertion/a:Subject/a:NameID" , { "p" => PROTOCOL , "a" => ASSERTION } )
39+ node = xpath_first_from_signed_assertion ( '/a:Subject/a:NameID' )
4140 node . nil? ? nil : node . text
4241 end
4342 end
4443
4544 def sessionindex
4645 @sessionindex ||= begin
47- node = REXML ::XPath . first ( document , "/p:Response/a:Assertion[@ID='#{ document . signed_element_id } ']/a:AuthnStatement" , { "p" => PROTOCOL , "a" => ASSERTION } )
48- node ||= REXML ::XPath . first ( document , "/p:Response[@ID='#{ document . signed_element_id } ']/a:Assertion/a:AuthnStatement" , { "p" => PROTOCOL , "a" => ASSERTION } )
46+ node = xpath_first_from_signed_assertion ( '/a:AuthnStatement' )
4947 node . nil? ? nil : node . attributes [ 'SessionIndex' ]
5048 end
5149 end
@@ -55,7 +53,7 @@ def attributes
5553 @attr_statements ||= begin
5654 result = { }
5755
58- stmt_element = REXML :: XPath . first ( document , "/p:Response/a:Assertion/a: AttributeStatement" , { "p" => PROTOCOL , "a" => ASSERTION } )
56+ stmt_element = xpath_first_from_signed_assertion ( '/a: AttributeStatement' )
5957 return { } if stmt_element . nil?
6058
6159 stmt_element . elements . each do |attr_element |
@@ -76,7 +74,7 @@ def attributes
7674 # When this user session should expire at latest
7775 def session_expires_at
7876 @expires_at ||= begin
79- node = REXML :: XPath . first ( document , "/p:Response/a:Assertion/a: AuthnStatement" , { "p" => PROTOCOL , "a" => ASSERTION } )
77+ node = xpath_first_from_signed_assertion ( '/a: AuthnStatement' )
8078 parse_time ( node , "SessionNotOnOrAfter" )
8179 end
8280 end
@@ -91,15 +89,13 @@ def success?
9189
9290 # Conditions (if any) for the assertion to run
9391 def conditions
94- @conditions ||= begin
95- REXML ::XPath . first ( document , "/p:Response/a:Assertion[@ID='#{ document . signed_element_id } ']/a:Conditions" , { "p" => PROTOCOL , "a" => ASSERTION } )
96- end
92+ @conditions ||= xpath_first_from_signed_assertion ( '/a:Conditions' )
9793 end
9894
9995 def issuer
10096 @issuer ||= begin
10197 node = REXML ::XPath . first ( document , "/p:Response/a:Issuer" , { "p" => PROTOCOL , "a" => ASSERTION } )
102- node ||= REXML :: XPath . first ( document , "/p:Response/a:Assertion/a: Issuer" , { "p" => PROTOCOL , "a" => ASSERTION } )
98+ node ||= xpath_first_from_signed_assertion ( '/a: Issuer' )
10399 node . nil? ? nil : node . text
104100 end
105101 end
@@ -146,6 +142,12 @@ def validate_response_state(soft = true)
146142 true
147143 end
148144
145+ def xpath_first_from_signed_assertion ( subelt = nil )
146+ node = REXML ::XPath . first ( document , "/p:Response/a:Assertion[@ID='#{ document . signed_element_id } ']#{ subelt } " , { "p" => PROTOCOL , "a" => ASSERTION } )
147+ node ||= REXML ::XPath . first ( document , "/p:Response[@ID='#{ document . signed_element_id } ']/a:Assertion#{ subelt } " , { "p" => PROTOCOL , "a" => ASSERTION } )
148+ node
149+ end
150+
149151 def get_fingerprint
150152 if settings . idp_cert
151153 cert = OpenSSL ::X509 ::Certificate . new ( settings . idp_cert )
0 commit comments