Dhairya-007 opened a new pull request, #29972:
URL: https://github.com/apache/camel/pull/29972
## Problem
The header is documented as mandatory for encrypted documents:
```java
@Metadata(description = """
Expected type is
https://pdfbox.apache.org/docs/2.0.13/javadocs/org/apache/pdfbox/pdmodel/encryption/DecryptionMaterial.html[DecryptionMaterial].
*Mandatory* header if PDF document is encrypted.""",
javaType =
"org.apache.pdfbox.pdmodel.encryption.DecryptionMaterial")
public static final String DECRYPTION_MATERIAL_HEADER_NAME =
"CamelPdfDecryptionMaterial";
```
The component never looks it up. `PdfProducer` statically imports the
constants and reads `PDF_DOCUMENT_HEADER_NAME` and
`PROTECTION_POLICY_HEADER_NAME` by name, but `DECRYPTION_MATERIAL_HEADER_NAME`
appears nowhere in the main sources. The only other references are two tests,
which decrypt the document themselves before sending it:
```java
// Encryption happens after saving.
PDDocument encryptedDocument = Loader.loadPDF(output.toByteArray(),
userPass);
expectText();
template.sendBodyAndHeader("direct:start",
encryptedDocument,
PdfHeaderConstants.DECRYPTION_MATERIAL_HEADER_NAME,
new StandardDecryptionMaterial(userPass));
```
so the header they set alongside is decoration - the body is a `PDDocument`
that is already decrypted, and that is why the tests pass.
Following the documentation instead does not work. The one point where the
material could be applied is the converter, which loads without a password:
```java
@Converter
public PDDocument convertToPDF(byte[] bytes) throws Exception {
return Loader.loadPDF(bytes);
}
```
so sending an encrypted PDF as `byte[]` with `CamelPdfDecryptionMaterial`
set fails inside the type converter with PDFBox's `InvalidPasswordException`,
before the producer is even entered - with nothing to connect that to the
header the docs said was mandatory.
It reads like a leftover of the PDFBox 1.x API, where you opened the
document and then decrypted it with
`document.openProtection(decryptionMaterial)`. PDFBox 2 and 3 take the password
at load time, so by the time the component has a `PDDocument` there is nothing
left to decrypt.
## Fix
Deprecate the constant with a `deprecationNote` saying why, so the catalog
and the header table stop presenting it as the way to read an encrypted PDF.
The constant stays, so nothing stops compiling.
The alternative is to make it work: give `PdfConverter` an `Exchange`
parameter, read the header there and pass the password to
`Loader.loadPDF(bytes, password)`. That covers `StandardDecryptionMaterial`
only - `Loader` has no overload for `PublicKeyDecryptionMaterial` - and it
changes a shared type converter, so I did not want to decide it here. Happy to
do it instead if you would rather have the header work.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]