开发者

how to insert a SAML Assertion to SOAPHeader

NB-6.8 jdk-1.6.14 WSS4j-1.5.8 ,OpenSAML-2.3.0 I try to modify WSS4J-1.5.8 to operate SAML 2.0, and I could not insert a generated assertion to existing SOAP Header, the code like this:

Assertion assertion = createAssertion("some subject", "some issuer");

    Document doc = docBuilder.parse("request.xml");

    Element parent = doc.getDocumentElement();

    Node node = parent.getElementsByTagName("soapenv:Header");
    node.appendChild(assertion.getDOM());

Error : WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.

but in wss4j, some functions like insertSecurityHeader do so(appendChild or inserBefore) ,too. Th开发者_如何学Cey do work, why it's wrong in my code? what I miss.


The problem is that the owner document of assertion is different from the owner document of node. To resolve this, the owner document of node has to take ownership of assertion before you can append it. As ralph pointed out you can use node.getOwnerDocument().adoptNode(assertion) to resolve that issue.


Actually, I ran into problems using importNode (NAMESPACE_ERR), which could be resolved using adoptNode instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜