title: Adding InclusiveNamespaces with WSS4J
body: <p>In a WS-Security header, I'd like to add InclusiveNamespaces like this but I do not know how:</p>
  
  <pre><code>&lt;ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"&gt;
       &lt;InclusiveNamespaces PrefixList="wsse oas soapenv urn urn1 urn2 urn3 urn4" xmlns="http://www.w3.org/2001/10/xml-exc-c14n#"/&gt;
  &lt;/ds:Transform&gt;
  </code></pre>
  
  <p>Here is my code that creates the security header, how do I add the InclusiveNamespaces with WSS4J as seen in above XML snippet?</p>
  
  <pre><code>public static SOAPMessage signSoapMessage(SOAPMessage message,
          String keystorePassword, String irsPrivateKeyPassword,
          char[] passphrase) throws WSSecurityException {
  
      PrivateKeyEntry privateKeyEntry = getPrivateKeyEntry(keystorePassword,
              irsPrivateKeyPassword);
  
      PrivateKey signingKey = privateKeyEntry.getPrivateKey();
      X509Certificate signingCert = (X509Certificate) privateKeyEntry
              .getCertificate();
  
      final String alias = "signingKey";
      final int signatureValidityTime = 3600; // 1hour in seconds
  
      WSSConfig config = new WSSConfig();
      config.setWsiBSPCompliant(false);
  
      WSSecSignature builder = new WSSecSignature(config);
  
      builder.setX509Certificate(signingCert);
      builder.setUserInfo(alias, new String(passphrase));
      builder.setUseSingleCertificate(true);
      builder.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);      
      builder.setDigestAlgo(WSConstants.SHA1);
      builder.setSignatureAlgorithm(WSConstants.RSA_SHA1);
      builder.setSigCanonicalization(WSConstants.C14N_EXCL_WITH_COMMENTS);
  
      try {
          Document document = toDocument(message);
          WSSecHeader secHeader = new WSSecHeader();
          //secHeader.setMustUnderstand(true);
          secHeader.insertSecurityHeader(document);
  
          WSSecTimestamp timestamp = new WSSecTimestamp();
          timestamp.setTimeToLive(signatureValidityTime);
          document = timestamp.build(document, secHeader);
  
          List&lt;WSEncryptionPart&gt; parts = new ArrayList&lt;WSEncryptionPart&gt;();
          WSEncryptionPart timestampPart = new WSEncryptionPart("Timestamp",
                  WSConstants.WSU_NS, "");
  
          WSEncryptionPart aCATransmitterManifestReqDtlPart = new WSEncryptionPart(
                  "ACATransmitterManifestReqDtl",
                  "urn:us:gov:treasury:irs:ext:aca:air:7.0", "");
          WSEncryptionPart aCABusinessHeaderPart = new WSEncryptionPart(
                  "ACABusinessHeader",
                  "urn:us:gov:treasury:irs:msg:acabusinessheader", "");
          parts.add(timestampPart);
          parts.add(aCATransmitterManifestReqDtlPart);
          parts.add(aCABusinessHeaderPart);
          builder.setParts(parts);
  
          Properties properties = new Properties();
          properties.setProperty("org.apache.ws.security.crypto.provider",
                  "org.apache.ws.security.components.crypto.Merlin");
          Crypto crypto = CryptoFactory.getInstance(properties);
          KeyStore keystore = KeyStore.getInstance("JKS");
          keystore.load(null, passphrase);
          keystore.setKeyEntry(alias, signingKey, passphrase,
                  new Certificate[] { signingCert });
          ((Merlin) crypto).setKeyStore(keystore);
          crypto.loadCertificate(new ByteArrayInputStream(signingCert
                  .getEncoded()));
  
          document = builder.build(document, crypto, secHeader);
  
          updateSOAPMessage(document, message);
  
  
      } catch (Exception e) {
          // throw new
          // WSSecurityException(WSSecurityException.Reason.SIGNING_ISSUE, e);
          e.printStackTrace();
      }
  
      return message;
  }
  
  private static Document toDocument(SOAPMessage soapMsg)
          throws TransformerConfigurationException, TransformerException,
          SOAPException, IOException {
      Source src = soapMsg.getSOAPPart().getContent();
      TransformerFactory tf = TransformerFactory.newInstance();
      Transformer transformer = tf.newTransformer();
      DOMResult result = new DOMResult();
      transformer.transform(src, result);
      return (Document) result.getNode();
  }
  
  //https://svn.apache.org/repos/asf/webservices/wss4j/branches/WSS4J_1_1_0_FINAL/test/wssec/SOAPUtil.java
  private static SOAPMessage updateSOAPMessage(Document doc,
                                              SOAPMessage message)
          throws Exception {
      DOMSource domSource = new DOMSource(doc);
      message.getSOAPPart().setContent(domSource);
      return message;
  }
  </code></pre>
  
  <p><strong><em>EDIT WITH ANSWER</em></strong>
  The above code is for v1.6.x of WSS4J and so the solution to above code is</p>
  
  <pre><code>WSSConfig config = new WSSConfig();
  config.setWsiBSPCompliant(true);
  </code></pre>