aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-01-19 21:59:41 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-01-19 21:59:41 +0000
commit4852f856d9713ec07d1223417932cd5d5070ff8c (patch)
tree2ff1a8b8d72865f9a4cbda0f2296b3f32fa1dc8e /src/main/java/at/gv/egiz
parent5161308e1650f1b7252c36bd39ec338e2471d54e (diff)
downloadpdf-as-3-4852f856d9713ec07d1223417932cd5d5070ff8c.tar.gz
pdf-as-3-4852f856d9713ec07d1223417932cd5d5070ff8c.tar.bz2
pdf-as-3-4852f856d9713ec07d1223417932cd5d5070ff8c.zip
- handling protected documents improved.
- minor web application improvements git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@557 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/gv/egiz')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java7
-rw-r--r--src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java30
2 files changed, 36 insertions, 1 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java b/src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java
index 409a600..6f73739 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java
@@ -11,6 +11,8 @@ import at.gv.egiz.pdfas.exceptions.framework.CorrectorException;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
import at.gv.egiz.pdfas.framework.input.correction.Corrector;
import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
+import at.gv.egiz.pdfas.utils.PDFASUtils;
+import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfReader;
@@ -33,6 +35,7 @@ public class InternalCorrector implements Corrector
{
byte[] pdf = document.getAsByteArray();
PdfReader reader = new PdfReader(pdf);
+ PDFASUtils.checkReaderPermissions(reader);
ByteArrayOutputStream baos = new ByteArrayOutputStream(pdf.length);
@@ -51,7 +54,9 @@ public class InternalCorrector implements Corrector
catch (IOException e)
{
throw new CorrectorException(ErrorCode.CORRECTOR_EXCEPTION, e);
- }
+ } catch (PDFDocumentException e) {
+ throw new CorrectorException(e.getErrorCode(), e);
+ }
}
}
diff --git a/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java b/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java
new file mode 100644
index 0000000..b26cc9b
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java
@@ -0,0 +1,30 @@
+package at.gv.egiz.pdfas.utils;
+
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
+
+import com.lowagie.text.pdf.PdfReader;
+
+/**
+ * @author tknall
+ */
+public class PDFASUtils {
+
+ private PDFASUtils() {
+ }
+
+ /**
+ * Verifies that a document could be opened with full permissions.
+ * @param pdfReader The PdfReader
+ * @throws PDFDocumentException Thrown if document has not been opened with full permissions.
+ */
+ public static void checkReaderPermissions(PdfReader pdfReader) throws PDFDocumentException {
+ if (pdfReader.isEncrypted()) {
+ throw new PDFDocumentException(ErrorCode.DOCUMENT_IS_PROTECTED, "Document is encrypted.");
+ }
+ if (!pdfReader.isOpenedWithFullPermissions()) {
+ throw new PDFDocumentException(ErrorCode.DOCUMENT_IS_PROTECTED, "Document is protected.");
+ }
+ }
+
+}