From 4852f856d9713ec07d1223417932cd5d5070ff8c Mon Sep 17 00:00:00 2001 From: tknall Date: Tue, 19 Jan 2010 21:59:41 +0000 Subject: - 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 --- src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java | 2 ++ .../java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java | 3 +++ .../at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java | 11 +++++------ .../at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java | 5 +++++ 4 files changed, 15 insertions(+), 6 deletions(-) (limited to 'src/main/java/at/knowcenter/wag/egov/egiz') 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"); } } -- cgit v1.2.3