List of usage examples for org.w3c.dom Element removeChild
public Node removeChild(Node oldChild) throws DOMException;
oldChild
from the list of children, and returns it. From source file:wssec.TestWSSecurityWSS178.java
/** * Test where the Assertion is referenced using direct reference * (from the SecurityTokenReference)./*from www. ja v a 2s.c o m*/ */ public void testDirectReference() throws Exception { SOAPEnvelope unsignedEnvelope = message.getSOAPEnvelope(); Document doc = unsignedEnvelope.getAsDocument(); WSSecHeader secHeader = new WSSecHeader(); secHeader.insertSecurityHeader(doc); SAMLIssuer saml = SAMLIssuerFactory.getInstance("saml.properties"); SAMLAssertion assertion = saml.newAssertion(); String issuerKeyName = saml.getIssuerKeyName(); String issuerKeyPW = saml.getIssuerKeyPassword(); Crypto issuerCrypto = saml.getIssuerCrypto(); WSSecSignatureSAML wsSign = new WSSecSignatureSAML(); wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); Document samlDoc = wsSign.build(doc, null, assertion, issuerCrypto, issuerKeyName, issuerKeyPW, secHeader); WSSecEncrypt builder = new WSSecEncrypt(); builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e"); builder.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); Document encryptedDoc = builder.build(samlDoc, crypto, secHeader); // // Remove the assertion its place in the security header and then append it // org.w3c.dom.Element secHeaderElement = secHeader.getSecurityHeader(); org.w3c.dom.Node assertionNode = secHeaderElement.getElementsByTagName("Assertion").item(0); secHeaderElement.removeChild(assertionNode); secHeaderElement.appendChild(assertionNode); String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc); if (LOG.isDebugEnabled()) { LOG.debug("Encrypted message:"); LOG.debug(outputString); } verify(encryptedDoc); }