attachmentInputStream.mark(Integer.MAX_VALUE); //we can process at maximum 2G with the standard jdk streams
try {
DigestOutputStream digestOutputStream =
createMessageDigestOutputStream(referenceType, inputProcessorChain.getSecurityContext());
UnsynchronizedBufferedOutputStream bufferedDigestOutputStream =
new UnsynchronizedBufferedOutputStream(digestOutputStream);
if (referenceType.getTransforms() != null) {
Transformer transformer =
buildTransformerChain(referenceType, bufferedDigestOutputStream, inputProcessorChain, null);
if (!(transformer instanceof AttachmentContentSignatureTransform)) {
throw new WSSecurityException(
WSSecurityException.ErrorCode.INVALID_SECURITY,
"empty", "First transform must be Attachment[Content|Complete]SignatureTransform"
);
}
Map<String, Object> transformerProperties = new HashMap<String, Object>(2);
transformerProperties.put(
AttachmentContentSignatureTransform.ATTACHMENT, attachment);
transformer.setProperties(transformerProperties);
transformer.transform(attachmentInputStream);
bufferedDigestOutputStream.close();
} else {
XMLSecurityUtils.copy(attachmentInputStream, bufferedDigestOutputStream);
bufferedDigestOutputStream.close();
}
compareDigest(digestOutputStream.getDigestValue(), referenceType);
//reset the inputStream to be able to reuse it
attachmentInputStream.reset();