CONNECTSignatureProcessor extends SignatureProcessor { private static void inlineIncludes(NodeList signatureNodes, Collection<Attachment> attachments) throws IOException { for (int i = 0; i < signatureNodes.getLength(); ++i) { Element sigElement = (Element) signatureNodes.item(i); Object child = sigElement.getFirstChild(); if (child instanceof Element && isIncludeElement((Element) child)) { String refId = ((Element) child).getAttribute(HREF_ATTRIBUTE).replaceFirst(CONTENT_ID_PREFIX, ""); Optional<Attachment> attachment = getAttachment(attachments, refId); if (attachment.isPresent()) { String attachmentValue = convertToBase64Data(attachment.get().getDataHandler()); sigElement.setTextContent(attachmentValue); } else { LOG.warn( "Failed to inline signature/digest element to the header. Cannot find reference id: {}", refId); } } } }  @Override List<WSSecurityEngineResult> handleToken(Element signatureElem, RequestData data, WSDocInfo wsDocInfo);  }
@Test public void inlineIncludes() throws ParserConfigurationException, WSSecurityException { SoapMessage msg = mock(SoapMessage.class); Collection<Attachment> attachmentList = new ArrayList<>(); attachmentList.add(createMockAttachment(DIG_REF_ID, DIG_BINARY_DATA)); attachmentList.add(createMockAttachment(SIG_REF_ID, SIG_BINARY_DATA)); when(msg.getAttachments()).thenReturn(attachmentList); Element signatureElem = createSignatureElementWithIncludes(DIG_REF_ID, SIG_REF_ID); CONNECTSignatureProcessor processor = new CONNECTSignatureProcessor(); processor.inlineSignatureAttachments(msg, signatureElem); assertDigitalValueIsInline(signatureElem, DIG_BASE64_DATA); assertSignatureValueIsInline(signatureElem, SIG_BASE64_DATA); }