2014-09-05 2 views
0

jQuery ajax를 사용하여 WS-Trust 서비스를 호출하여 SAML 어설 션을 검색합니다. 내 서비스의 응답에는 완전한 WS-Trust 응답이 포함되어 있으며 문서의 중간 부분에서만 어설 션이 필요합니다.XML 문서에서 jQuery 추출 및 표시 노드

하는 XML 문서는 다음과 같습니다

<ns3:RequestSecurityTokenResponse xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ns10="http://www.w3.org/2000/09/xmldsig#" xmlns:ns2="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://docs.oasis-open.org/ws-sx/ws-trust/200512/" xmlns:ns4="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns5="http://docs.oasis-open.org/ws-sx/ws-trust/200802" xmlns:ns6="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:ns7="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:ns8="http://schemas.xmlsoap.org/ws/2005/02/sc" xmlns:ns9="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity"> 
     <ns3:RequestedSecurityToken> 
      <saml2:Assertion xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://www.w3.org/2001/04/xmlenc#" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="SAML_4e367081-34ab-11e4-b48c-e062ecbc9f52" IssueInstant="2014-09-04T20:18:28.420-07:00" Version="2.0"> 
       <saml2:Issuer>pmdomain</saml2:Issuer> 
       <saml2:Subject> 
        <saml2:NameID Format="urn:com:soa:saml:nameid-format:QualifiedName" NameQualifier="PolicyManager">Local LDAP\igoldsmith</saml2:NameID> 
        <saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:sender-vouches" /> 
       </saml2:Subject> 
       <saml2:Conditions NotOnOrAfter="2014-09-05T00:18:28.420-07:00" /> 
       <saml2:AuthnStatement AuthnInstant="2014-09-04T20:18:28.420-07:00"> 
        <saml2:AuthnContext> 
         <saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified</saml2:AuthnContextClassRef> 
        </saml2:AuthnContext> 
       </saml2:AuthnStatement> 
       <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> 
    <ds:SignedInfo> 
    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> 
    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /> 
    <ds:Reference URI="#SAML_4e367081-34ab-11e4-b48c-e062ecbc9f52"> 
    <ds:Transforms> 
    <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /> 
    <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> 
    </ds:Transforms> 
    <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
    <ds:DigestValue>/9WRlKPTL5N2SJOYe9pSw9Coy4I=</ds:DigestValue> 
    </ds:Reference> 
    </ds:SignedInfo> 
    <ds:SignatureValue> 
    Lgxq9PdlgSTU5R6JvhFBLbGv6PZUo64DhZvlovtg/sfTSZcljHKld9XQvE5cWT4Q2O0EVhxb332O 
    XBipazlw8Tluvlf5s/k2m8L9LhtR2X/kdI+HooGEyHFBFLg4cX4nKP8Mbmc+bJegOtMlFSy/Zj5y 
    gZr+bNwPk0xdniblmco= 
    </ds:SignatureValue> 
    <ds:KeyInfo> 
    <ds:X509Data> 
    <ds:X509Certificate> 
    MIICATCCAWqgAwIBAgIIZ7i81vjsmF0wDQYJKoZIhvcNAQEFBQAwQzELMAkGA1UEBhMCVVMxCzAJ 
    BgNVBAgTAkNBMQwwCgYDVQQKEwNTT0ExDDAKBgNVBAsTA1NPQTELMAkGA1UEAxMCcG0wHhcNMTQw 
    NjE3MjA0ODIxWhcNMTkwNjE4MTM0NTAwWjBDMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExDDAK 
    BgNVBAoTA1NPQTEMMAoGA1UECxMDU09BMQswCQYDVQQDEwJwbTCBnzANBgkqhkiG9w0BAQEFAAOB 
    jQAwgYkCgYEAlyVusLGwuaFjL7nFdnvqbLVMq7T0wONpLTYDGMFwg5gEz+8gDzi7nZrtwxOe31V8 
    gEz6u6KdZXfjBUNkp0JgDt8uBGWr55Rol6kYnxix5r/UwvU2gRCAl0TGwipyShqW+FmWyK/y/+R6 
    5mtdD8FgmrmuBVwTGc2DxZxWJQOcqhMCAwEAATANBgkqhkiG9w0BAQUFAAOBgQAnoiHMEdGvVa57 
    o+f+o6oknHsZDz8ipWG0vLzE+Pv3ordsVLKb2iG2o8DZAG7WuECirbXiLmZQ7cV+CqBiIqm82apZ 
    Aw2pnD1uTBxaakf4KRkOct/Dk8MDr/2RyOUUQcxOnW3GeJV2q6YiIiGqAPN1/7Qf9cYSSQQC7/uV 
    kFPf1g== 
    </ds:X509Certificate> 
    </ds:X509Data> 
    </ds:KeyInfo> 
    </ds:Signature> 
      </saml2:Assertion> 
     </ns3:RequestedSecurityToken> 
     <ns3:TokenType>http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0</ns3:TokenType> 
     <ns3:RequestedAttachedReference> 
      <ns4:SecurityTokenReference> 
       <ns4:Reference URI="#SAML_4e367081-34ab-11e4-b48c-e062ecbc9f52" ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0" /> 
      </ns4:SecurityTokenReference> 
     </ns3:RequestedAttachedReference> 
     <ns3:Lifetime> 
      <ns1:Created>2014-09-05T03:18:28.450Z</ns1:Created> 
      <ns1:Expires>2014-09-05T07:18:28.420Z</ns1:Expires> 
     </ns3:Lifetime> 
    </ns3:RequestSecurityTokenResponse> 

나는이 개 질문이 :

1 - SAML2를 추출하는 가장 좋은 방법은 무엇입니까 : 어설 노드가 새 XML 개체로?

2 -이 개체를 내 페이지 본문에 표시 할 문자열로 변환하는 가장 좋은 방법은 무엇입니까?

감사합니다. 업데이트

답변

0

편집,

TODO : 태그의 내용을 렌더링하려면 태그

에 원본 문서 대문자를 유지, 시도 saml2:Assertionsxml 요소

saml2\\:assertion 요소 outerHTML을 활용할 수

v2

html

<textarea></textarea> 

JS

// `ajax` method , options 
$.ajax() 
// `ajax` `.done()` , `success` callback 
.done(function(data, status, jqxhr) { 
     var xml = $(data.documentElement); 
     var assertion = xml 
     .children("ns3\\:requestedsecuritytoken") 
     .children("saml2\\:assertion"); 
     // raw xml , 
     // TODO: retain original document 
     // uppercase letters at tag 
     $("textarea").val(assertion[0].outerHTML); 
    }); 

jsfiddle http://jsfiddle.net/guest271314/sqz12ma2/

+0

나는 그것이 모든 소문자하게하는 HTML로 강제 주로하기 때문에,이 작품 생각하지 않습니다. 또한 원시 XML을 표시해야하는데, 태그 자체가 아닌 태그의 내용 만 표시합니다. – IanG

+0

업데이트 된 게시물보기. 감사합니다 – guest271314

+0

고마워요. – IanG

관련 문제