pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1634930 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
Date Tue, 28 Oct 2014 17:37:14 GMT
Author: tilman
Date: Tue Oct 28 17:37:13 2014
New Revision: 1634930

URL: http://svn.apache.org/r1634930
Log:
PDFBOX-2460: keep accessPermission locally after decryption, so that the real permissions
are available

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1634930&r1=1634929&r2=1634930&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Tue Oct 28
17:37:13 2014
@@ -95,6 +95,9 @@ public class PDDocument implements Close
     // the File to read incremental data from
     private File incrementalFile;
 
+    // the access permissions of the document
+    private AccessPermission accessPermission;
+    
     /**
      * Creates an empty PDF document.
      * You need to add at least one page for the document to be valid.
@@ -1250,6 +1253,7 @@ public class PDDocument implements Close
             parser.clearResources();
             parser = null;
         }
+        accessPermission = null;
     }
 
     /**
@@ -1293,7 +1297,9 @@ public class PDDocument implements Close
     {
         if (isEncrypted())
         {
-            getEncryption().getSecurityHandler().decryptDocument(this, decryptionMaterial);
+            SecurityHandler securityHandler = getEncryption().getSecurityHandler();
+            securityHandler.decryptDocument(this, decryptionMaterial);
+            accessPermission = securityHandler.getCurrentAccessPermission();
             document.dereferenceObjectStreams();
             document.setEncryptionDictionary(null);
             getDocumentCatalog();
@@ -1314,22 +1320,11 @@ public class PDDocument implements Close
      */
     public AccessPermission getCurrentAccessPermission()
     {
-        if (isEncrypted() && getEncryption().hasSecurityHandler())
-        {
-            try
-            {
-                return getEncryption().getSecurityHandler().getCurrentAccessPermission();
-            }
-            catch (IOException e)
-            {
-                // will never happen because we checked hasSecurityHandler() first
-                throw new RuntimeException(e);
-            }
-        }
-        else
+        if (accessPermission == null)
         {
-            return AccessPermission.getOwnerAccessPermission();
+            accessPermission = AccessPermission.getOwnerAccessPermission();
         }
+        return accessPermission;
     }
 
     /**



Mime
View raw message