aboutsummaryrefslogtreecommitdiff
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
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
-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
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java2
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java3
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java11
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java5
-rw-r--r--src/main/resources/config/help_text.properties2
7 files changed, 52 insertions, 8 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.");
+ }
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
index 0ae2e8e..423c222 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java
@@ -43,6 +43,7 @@ import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
import at.gv.egiz.pdfas.impl.api.commons.PdfDataSourceAdapter;
import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
+import at.gv.egiz.pdfas.utils.PDFASUtils;
import at.gv.egiz.pdfas.web.VerifySessionInformation;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
@@ -1256,6 +1257,7 @@ public abstract class PdfAS
// first check pageinstruction in TablePos-object
// new,auto,absolut
PdfReader reader = readInPdfDocument(pdfDataSource);
+ PDFASUtils.checkReaderPermissions(reader);
// get pages of currentdocument
int doc_pages = reader.getNumberOfPages();
int page = doc_pages;
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java
index 8cb0d42..d1e227a 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java
@@ -37,11 +37,13 @@ import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.api.timestamp.TimeStamper;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.gv.egiz.pdfas.exceptions.framework.CorrectorException;
import at.gv.egiz.pdfas.exceptions.pdf.CaptionNotFoundException;
import at.gv.egiz.pdfas.exceptions.pdf.KZSettingNotFoundException;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
import at.gv.egiz.pdfas.framework.output.DataSink;
import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
+import at.gv.egiz.pdfas.utils.PDFASUtils;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
import at.knowcenter.wag.egov.egiz.exceptions.PlaceholderException;
@@ -795,6 +797,7 @@ public abstract class BinarySignature
// InputStream is = original_document.createInputStream();
byte[] pdf_data = original_document.getAsByteArray();
PdfReader reader = new PdfReader(pdf_data);
+ PDFASUtils.checkReaderPermissions(reader);
// is.close();
OutputStream baos = written_pdf.createOutputStream("application/pdf");
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java
index 841e2a6..85bc4fd 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java
@@ -30,6 +30,7 @@ import org.pdfbox.util.PDFTextStripper;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
import at.gv.egiz.pdfas.performance.PerformanceCounters;
+import at.gv.egiz.pdfas.utils.PDFASUtils;
import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
@@ -85,11 +86,7 @@ public class TextualSignature
byte [] pdf_data = pdfDataSource.getAsByteArray();
PdfReader reader = new PdfReader(pdf_data);
- if (!reader.isOpenedWithFullPermissions()) {
- // cannot perform modification and extraction
- throw new PDFDocumentException(ErrorCode.DOCUMENT_IS_PROTECTED, "Document is protected.");
-
- }
+ PDFASUtils.checkReaderPermissions(reader);
//pdf_stream.close();
// PERF: PDF normalization needs byte array - this is costy
@@ -212,12 +209,14 @@ public class TextualSignature
* @return Returns the normalized pdf.
* @throws IOException
* @throws DocumentException
+ * @throws PDFDocumentException
*/
- public static byte[] normalizePDF(PdfDataSource pdfDataSource) throws IOException, DocumentException
+ public static byte[] normalizePDF(PdfDataSource pdfDataSource) throws IOException, DocumentException, PDFDocumentException
{
//iText
byte [] pdf_data = pdfDataSource.getAsByteArray();
PdfReader reader = new PdfReader(pdf_data);
+ PDFASUtils.checkReaderPermissions(reader);
//input_pdf.close();
// PERF: PDF Normalization needs byte array
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
index f30f0fb..c946225 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java
@@ -315,6 +315,11 @@ public class SignServlet extends HttpServlet
log.error(e.getMessage(), e);
prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ PresentableException pe = new PresentableException(ErrorCode.UNKNOWN_ERROR, e);
+ prepareDispatchToErrorPage(pe, request);
+ dispatch(request, response, "/jsp/error.jsp");
}
}
diff --git a/src/main/resources/config/help_text.properties b/src/main/resources/config/help_text.properties
index 290e59f..61b35d1 100644
--- a/src/main/resources/config/help_text.properties
+++ b/src/main/resources/config/help_text.properties
@@ -35,7 +35,7 @@ error.code.227=Der angegebene Wert für die Seitennummer im Positionsparameter is
error.code.228=Der angegebene Wert für die x-Position in der absoluten Position darf nicht kleiner gleich 0 sein.
error.code.229=Der angegebene Wert für die y-Position in der absoluten Position darf nicht kleiner gleich 0 sein.
error.code.230=Die Schriftart konnte nicht geladen werden.
-error.code.231=Das Dokument kann nicht signiert werden, da es geschützt ist.
+error.code.231=Das Dokument kann nicht verarbeitet werden, da es geschützt ist.
error.code.250=Das angegebene Dokument ist leer.
error.code.251=Das angegebene Dokument enthält keinen extrahierbaren Text. Falls sich der Inhalt ausschließlich aus Bildern zusammensetzt, wird die Verwendung einer binären Signatur empfohlen.