aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-10-25 18:40:44 +0000
committerJeremias Maerki <jeremias@apache.org>2005-10-25 18:40:44 +0000
commit80d945088399b17f440ef7432353dc799f76d2ec (patch)
tree32a42dcb30f8e61c1297ab4c6439dc67d21b44b9 /src
parent5cdaf10f11c193c2a2b833d2ea37a914764c665a (diff)
downloadxmlgraphics-fop-80d945088399b17f440ef7432353dc799f76d2ec.tar.gz
xmlgraphics-fop-80d945088399b17f440ef7432353dc799f76d2ec.zip
Ported the command-line options for PDF encryption to trunk.
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
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/cli/CommandLineOptions.java71
-rw-r--r--src/java/org/apache/fop/pdf/PDFEncryptionManager.java2
2 files changed, 64 insertions, 9 deletions
diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java
index 44fa2b174..b0c1bf4e0 100644
--- a/src/java/org/apache/fop/cli/CommandLineOptions.java
+++ b/src/java/org/apache/fop/cli/CommandLineOptions.java
@@ -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"
diff --git a/src/java/org/apache/fop/pdf/PDFEncryptionManager.java b/src/java/org/apache/fop/pdf/PDFEncryptionManager.java
index a2257c310..737c65362 100644
--- a/src/java/org/apache/fop/pdf/PDFEncryptionManager.java
+++ b/src/java/org/apache/fop/pdf/PDFEncryptionManager.java
@@ -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;