]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Ported the command-line options for PDF encryption to trunk.
authorJeremias Maerki <jeremias@apache.org>
Tue, 25 Oct 2005 18:40:44 +0000 (18:40 +0000)
committerJeremias Maerki <jeremias@apache.org>
Tue, 25 Oct 2005 18:40:44 +0000 (18:40 +0000)
Warnings if required providers are not available.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@328449 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/cli/CommandLineOptions.java
src/java/org/apache/fop/pdf/PDFEncryptionManager.java

index 44fa2b17459cc96c2075efd833e7681508495e3c..b0c1bf4e01b6d3d12511bac2db31d4f0487d2eb3 100644 (file)
@@ -29,6 +29,8 @@ import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.fo.Constants;
+import org.apache.fop.pdf.PDFEncryptionManager;
+import org.apache.fop.pdf.PDFEncryptionParams;
 import org.apache.fop.render.awt.AWTRenderer;
 import org.apache.fop.util.CommandLineLogger;
 
@@ -233,6 +235,18 @@ public class CommandLineOptions implements Constants {
                   } else {
                     throw new FOPException("invalid param usage: use -param <name> <value>");
                   }
+            } else if (args[i].equals("-o")) {
+                i = i + parsePDFOwnerPassword(args, i);
+            } else if (args[i].equals("-u")) {
+                i = i + parsePDFUserPassword(args, i);
+            } else if (args[i].equals("-noprint")) {
+                getPDFEncryptionParams().setAllowPrint(false);
+            } else if (args[i].equals("-nocopy")) {
+                getPDFEncryptionParams().setAllowCopyContent(false);
+            } else if (args[i].equals("-noedit")) {
+                getPDFEncryptionParams().setAllowEditContent(false);
+            } else if (args[i].equals("-noannotations")) {
+                getPDFEncryptionParams().setAllowEditAnnotations(false);
             } else {
                 printUsage();
                 return false;
@@ -453,6 +467,39 @@ public class CommandLineOptions implements Constants {
         }
     }
 
+    private PDFEncryptionParams getPDFEncryptionParams() throws FOPException {
+        if (foUserAgent.getPDFEncryptionParams() == null) {
+            if (!PDFEncryptionManager.checkAvailableAlgorithms()) {
+                throw new FOPException("PDF encryption requested but it is not available."
+                        + " Please make sure MD5 and RC4 algorithms are available.");
+            }
+            foUserAgent.setPDFEncryptionParams(new PDFEncryptionParams());
+        }
+        return foUserAgent.getPDFEncryptionParams();
+    }
+    
+    private int parsePDFOwnerPassword(String[] args, int i) throws FOPException {
+        if ((i + 1 == args.length)
+                || (args[i + 1].charAt(0) == '-')) {
+            getPDFEncryptionParams().setOwnerPassword("");
+            return 0;
+        } else {
+            getPDFEncryptionParams().setOwnerPassword(args[i + 1]);
+            return 1;
+        }
+    }
+
+    private int parsePDFUserPassword(String[] args, int i) throws FOPException {
+        if ((i + 1 == args.length)
+                || (args[i + 1].charAt(0) == '-')) {
+            getPDFEncryptionParams().setUserPassword("");
+            return 0;
+        } else {
+            getPDFEncryptionParams().setUserPassword(args[i + 1]);
+            return 1;
+        }
+    }
+
     private void setOutputMode(int mode) throws FOPException {
         if (outputmode == NOT_SET) {
             outputmode = mode;
@@ -703,15 +750,21 @@ public class CommandLineOptions implements Constants {
               "\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] "
                     + "[-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at|-print] <outfile>\n"
             + " [OPTIONS]  \n"
-            + "  -d          debug mode   \n"
-            + "  -x          dump configuration settings  \n"
-            + "  -q          quiet mode  \n"
-            + "  -c cfg.xml  use additional configuration file cfg.xml\n"
-            + "  -l lang     the language to use for user information \n"
-            + "  -r          relaxed/less strict validation (where available)\n"
-            + "  -dpi xxx    resolution in dots per inch (dpi) where xxx is a number\n"
-            + "  -s          for area tree XML, down to block areas only\n"
-            + "  -v          to show FOP version being used\n\n"
+            + "  -d             debug mode   \n"
+            + "  -x             dump configuration settings  \n"
+            + "  -q             quiet mode  \n"
+            + "  -c cfg.xml     use additional configuration file cfg.xml\n"
+            + "  -l lang        the language to use for user information \n"
+            + "  -r             relaxed/less strict validation (where available)\n"
+            + "  -dpi xxx       resolution in dots per inch (dpi) where xxx is a number\n"
+            + "  -s             for area tree XML, down to block areas only\n"
+            + "  -v             to show FOP version being used\n\n"
+            + "  -o [password]  PDF file will be encrypted with option owner password\n"
+            + "  -u [password]  PDF file will be encrypted with option user password\n"
+            + "  -noprint       PDF file will be encrypted without printing permission\n"
+            + "  -nocopy        PDF file will be encrypted without copy content permission\n"
+            + "  -noedit        PDF file will be encrypted without edit content permission\n"
+            + "  -noannotations PDF file will be encrypted without edit annotation permission\n\n"
             + " [INPUT]  \n"
             + "  infile            xsl:fo input file (the same as the next) \n"
             + "  -fo  infile       xsl:fo input file  \n"
index a2257c310de9754113f2cec974b74199a87d131f..737c653621de83df3a518dc11a71952a5854e4ee 100644 (file)
@@ -59,10 +59,12 @@ public class PDFEncryptionManager {
             Provider[] providers;
             providers = Security.getProviders("Cipher.RC4");
             if (providers == null) {
+                log.warn("Cipher provider for RC4 not available.");
                 return false;
             }
             providers = Security.getProviders("MessageDigest.MD5");
             if (providers == null) {
+                log.warn("MessageDigest provider for MD5 not available.");
                 return false;
             }
             return true;