* extraction. In the 128 and 256 bit encrypted files, AssembleDocument,
* ExtractForAccessibility and PrintDegraded are also disabled.
*/
public void testPermissions() throws Exception
{
AccessPermission fullAP = new AccessPermission();
AccessPermission restrAP = new AccessPermission();
restrAP.setCanPrint(false);
restrAP.setCanExtractContent(false);
restrAP.setCanModify(false);
byte[] inputFileAsByteArray = getFileResourceAsByteArray("PasswordSample-40bit.pdf");
checkPerms(inputFileAsByteArray, "owner", false, fullAP);
checkPerms(inputFileAsByteArray, "owner", true, fullAP);
checkPerms(inputFileAsByteArray, "user", false, restrAP);
checkPerms(inputFileAsByteArray, "user", true, restrAP);
try
{
checkPerms(inputFileAsByteArray, "", false, null);
fail("wrong password not detected");
}
catch (IOException ex)
{
assertEquals("Cannot decrypt PDF, the password is incorrect", ex.getMessage());
}
try
{
checkPerms(inputFileAsByteArray, "", true, null);
fail("wrong password not detected");
}
catch (IOException ex)
{
assertEquals("Cannot decrypt PDF, the password is incorrect", ex.getMessage());
}
restrAP.setCanAssembleDocument(false);
restrAP.setCanExtractForAccessibility(false);
restrAP.setCanPrintDegraded(false);
inputFileAsByteArray = getFileResourceAsByteArray("PasswordSample-128bit.pdf");
checkPerms(inputFileAsByteArray, "owner", false, fullAP);
checkPerms(inputFileAsByteArray, "owner", true, fullAP);
checkPerms(inputFileAsByteArray, "user", false, restrAP);