需要XML的Saml Auth令牌的Xml xpath表达式

时间:2019-06-21 00:14:38

标签: json xpath soap gatling-jsonpath

我有一个xml响应,我希望从该xml响应中提取该XML的Saml Token内容,但内容嵌套在xsi:type =“ xsd:string”>下,我无法提取

我在xpath表达式下面写了      // * [local-name()='ExecuteAuthnRequestResult'] 但是它在ExecuteAuthnRequestResult标签下提供了所有内容,我只需要SamlToken

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <ExecuteAuthnRequestResponse xmlns="http://www.wirds.com/Service/2013-03">
      <ExecuteAuthnRequestResult>&lt;samlp:Response xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="_b9d65dd5-b666-49b4-a625-c84a075f387d" InResponseTo="_4ed957f1-88bf-44e3-35f9-454d535fa420" Version="2.0" IssueInstant="2019-06-20T21:45:10.4188342Z" Destination="SamlWidget"&gt;&lt;saml:Issuer AllowCreate="false" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;IdP&lt;/saml:Issuer&gt;&lt;samlp:Status&gt;&lt;samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" /&gt;&lt;/samlp:Status&gt;&lt;saml:Assertion Version="2.0" ID="_dfc602fd-43a2-4d4f-81f0-1fefd4f5ce15" IssueInstant="2019-06-20T21:45:10.4188342Z" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;saml:Issuer AllowCreate="false"&gt;IdP&lt;/saml:Issuer&gt;&lt;saml:Subject&gt;&lt;saml:NameID AllowCreate="false" NameQualifier="Wizards"&gt;SamlAdapter&lt;/saml:NameID&gt;&lt;saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"&gt;&lt;saml:SubjectConfirmationData /&gt;&lt;/saml:SubjectConfirmation&gt;&lt;/saml:Subject&gt;&lt;saml:Conditions NotBefore="2019-06-20T21:45:10.4188342Z" NotOnOrAfter="2019-06-20T21:50:10.4188342Z"&gt;&lt;saml:AudienceRestriction /&gt;&lt;/saml:Conditions&gt;&lt;saml:AuthnStatement AuthnInstant="2019-06-20T21:45:10.4188342Z"&gt;&lt;saml:AuthnContext&gt;&lt;saml:AuthnContextClassRef&gt;saml:AuthnContextClassRef&lt;/saml:AuthnContextClassRef&gt;&lt;/saml:AuthnContext&gt;&lt;/saml:AuthnStatement&gt;&lt;saml:AttributeStatement&gt;&lt;saml:Attribute Name="SamlToken" NameFormat="urn:oasis:names:tc:SAML:2.0:nameidformat:entity"&gt;&lt;saml:AttributeValue xsi:type="xsd:string"&gt;6tFbq4NmcX7vvh7IPDgNcbQZHvipXqPo0mENVrI+bl4PCcrOWu9fZE9OBmDv7KobVcCHGtVCvSIYI6clhkoe7xk61awPtyTQ+MFWYi+ebO1w/spiu7DJn+2DCKm9FbghHo2RP7MLiwUDHM772r3kcZ70zLhQnH2SoqZygy7I9XfZOcWtFN2nG7GoPcXwcLUvPu+iue6w91EhepcV7IVkYF40H+ft1VZ4Nv5BYpWQz8qqAa3StImYMHS1t8mSSvZtQ5QsJJgSSxbsrVX1EO5F9Ge4CaFhTKB/ux3cS81480+nh+6cMk+FGMlENhWK2xBdkPt89DJHl7h5DeBknX95Nnm8QPnlinTosVadLjjS187zVs0F+oyBnihgAfLXDYejAXbGuCXQgVHJWS4k/ZA8NSt7wTEJkoQodjYg5sTQOcW+YsAVowjA2YPEDkoJ0AWMzyRPwoebwrDrErCqG8LB4IHeQtY44ym2Elg0zdwCjrkHL/tuiVnp+DoTPXxqtUDOPZ2TaqGChVcX4PcV9FiG+AzA7QeIgwyYC+mxZghlEDLnkXp006tqV4Zpb1zJ5eAP5dfWbOCxKL6flNt2pkT/bbVwdxLqJFhcrfiOiwQTEsbHLloyw011esOvZ2d1FXsp&lt;/saml:AttributeValue&gt;&lt;/saml:Attribute&gt;&lt;saml:Attribute Name="ScreenName" NameFormat="urn:oasis:names:tc:SAML:2.0:nameidformat:entity"&gt;&lt;saml:AttributeValue xsi:nil="true" /&gt;&lt;/saml:Attribute&gt;&lt;saml:Attribute Name="ExpirationDate" NameFormat="urn:oasis:names:tc:SAML:2.0:nameidformat:entity"&gt;&lt;saml:AttributeValue xsi:type="xsd:string"&gt;06/21/2019 04:45:40&lt;/saml:AttributeValue&gt;&lt;/saml:Attribute&gt;&lt;saml:Attribute Name="Permissions" NameFormat="urn:oasis:names:tc:SAML:2.0:nameidformat:entity"&gt;&lt;saml:AttributeValue xsi:type="xsd:string"&gt;&amp;lt;ArrayOfString xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"&amp;gt;&#xD;
       &amp;lt;string&amp;gt;LOGIN&amp;lt;/string&amp;gt;&#xD;
       &amp;lt;string&amp;gt;T&amp;amp;amp;C&amp;lt;/string&amp;gt;&#xD;
       &amp;lt;/ArrayOfString&amp;gt;&lt;/saml:AttributeValue&gt;&lt;/saml:Attribute&gt;&lt;/saml:AttributeStatement&gt;&lt;Signature xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;&lt;SignedInfo&gt;&lt;CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" /&gt;&lt;SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /&gt;&lt;Reference URI="#_dfc602fd-43a2-4d4f-81f0-1fefd4f5ce15"&gt;&lt;Transforms&gt;&lt;Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /&gt;&lt;/Transforms&gt;&lt;DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /&gt;&lt;DigestValue&gt;TeClTVB9KvGl6zdBwsH6TChyBNQ=&lt;/DigestValue&gt;&lt;/Reference&gt;&lt;/SignedInfo&gt;&lt;SignatureValue&gt;zczmd+bJb8kzM35RJ9FRx3+dx4vTMYpSoSqNCXKIJV5I4TBbCmc6H8U44bLl4ziudS9eVRiyF4hpRU2SaaB472Sz1trqI3PmEzU/6Dw8qveLq9uya+KHR8SyFMBeRp6DgC24TQe8HweuEBxAfFYVcwJvpXBZs1Sh/ehp+T4tvhN6LepahARS4cZQ3uJpyaXiT8HEMacXYdhtlGtgM4+Fri/Eq+peSkBe8cEp0wdwYJFAMe7RAR3Wl6tZhRjoYVjzCBbBF4570BNIt4TQ+if5JjI9KLEW1Otp/6HozGhuNxzjhqExACj13EkNLPC5twL5X2cUOTKlJm1aiu4mIN+C0A==&lt;/SignatureValue&gt;&lt;/Signature&gt;&lt;/saml:Assertion&gt;&lt;Signature xmlns="http://www.w3.org/2000/09/xmldsig#"&gt;&lt;SignedInfo&gt;&lt;CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#WithComments" /&gt;&lt;SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /&gt;&lt;Reference URI=""&gt;&lt;DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /&gt;&lt;DigestValue&gt;gP6oqV97oj000S/5G87Ub96VbMw=&lt;/DigestValue&gt;&lt;/Reference&gt;&lt;/SignedInfo&gt;&lt;SignatureValue&gt;hsgE/FHSKm32OYBMfu8ruUZVh+IGF4MVsOi5AqsxkRTT2NXMo4J45sjypxA8mFdAF9ULtxHqAv1O+HMKRD4wLiENXQjPyMOx2Ar3rLxxZIBTbJpUhbZorVt/4/Ifd26D5OjNtJ1p3gCMkwi72RGRKXtuyj1hrkpZ8gUTV+DC7cc=&lt;/SignatureValue&gt;&lt;/Signature&gt;&lt;/samlp:Response&gt;
    </ExecuteAuthnRequestResult>
   </ExecuteAuthnRequestResponse>
  </s:Body>
</s:Envelope>

我希望从此xml中提取Saml Token内容,但是内容嵌套在xsi:type =“ xsd:string”>下,我无法提取

1 个答案:

答案 0 :(得分:0)

我知道这个xpath更大。

因此,基本上,您必须使用substring-berforesubstring-after获取令牌字符串。下面是xpath

substring-before(substring-after(//*[local-name() = 'ExecuteAuthnRequestResult'] /text(),'<saml:AttributeValue xsi:type="xsd:string">'),'</saml:AttributeValue>')

屏幕截图:

enter image description here

输出:

  

'6tFbq4NmcX7vvh7IPDgNcbQZHvipXqPo0mENVrI + bl4PCcrOWu9fZE9OBmDv7KobVcCHGtVCvSIYI6clhkoe7xk61awPtyTQ + MFWYi + ebO1w / spiu7DJn + 2DCKm9FbghHo2RP7MLiwUDHM772r3kcZ70zLhQnH2SoqZygy7I9XfZOcWtFN2nG7GoPcXwcLUvPu + iue6w91EhepcV7IVkYF40H + ft1VZ4Nv5BYpWQz8qqAa3StImYMHS1t8mSSvZtQ5QsJJgSSxbsrVX1EO5F9Ge4CaFhTKB / ux3cS81480 + NH + 6cMk + FGMlENhWK2xBdkPt89DJHl7h5DeBknX95Nnm8QPnlinTosVadLjjS187zVs0F + oyBnihgAfLXDYejAXbGuCXQgVHJWS4k / ZA8NSt7wTEJkoQodjYg5sTQOcW + YsAVowjA2YPEDkoJ0AWMzyRPwoebwrDrErCqG8LB4IHeQtY44ym2Elg0zdwCjrkHL / tuiVnp + DoTPXxqtUDOPZ2TaqGChVcX4PcV9FiG + AzA7QeIgwyYC + mxZghlEDLnkXp006tqV4Zpb1zJ5eAP5dfWbOCxKL6flNt2pkT / bbVwdxLqJFhcrfiOiwQTEsbHLloyw011esOvZ2d1FXsp'