From 9ef042419014ebe9ea3e6ce0af5568de2d933c7d Mon Sep 17 00:00:00 2001 From: netconomy Date: Mon, 17 Dec 2007 15:43:39 +0000 Subject: Change Request "Document Correction" git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@239 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../java/at/gv/egiz/pdfas/commandline/Main.java | 4 - .../at/gv/egiz/pdfas/exceptions/ErrorCode.java | 3 +- .../exceptions/framework/CorrectorException.java | 36 +++ .../framework/input/correction/Corrector.java | 41 ++++ .../input/correction/CorrectorFactory.java | 43 ++++ .../at/gv/egiz/pdfas/impl/api/PdfAsObject.java | 2 + .../impl/input/correction/ExternalCorrector.java | 263 +++++++++++++++++++++ .../impl/input/correction/InternalCorrector.java | 57 +++++ .../at/gv/egiz/pdfas/web/helper/TempDirHelper.java | 23 +- .../java/at/knowcenter/wag/egov/egiz/PdfAS.java | 39 ++- .../wag/egov/egiz/cfg/SettingsReader.java | 7 + .../knowcenter/wag/egov/egiz/commandline/Main.java | 2 +- .../wag/egov/egiz/web/servlets/SignServlet.java | 2 +- work/cfg/config.properties | 31 ++- work/cfg/help_text.properties | 6 +- 15 files changed, 544 insertions(+), 15 deletions(-) create mode 100644 src/main/java/at/gv/egiz/pdfas/exceptions/framework/CorrectorException.java create mode 100644 src/main/java/at/gv/egiz/pdfas/framework/input/correction/Corrector.java create mode 100644 src/main/java/at/gv/egiz/pdfas/framework/input/correction/CorrectorFactory.java create mode 100644 src/main/java/at/gv/egiz/pdfas/impl/input/correction/ExternalCorrector.java create mode 100644 src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java diff --git a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java index 147b540..b4546e4 100644 --- a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java +++ b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java @@ -573,10 +573,6 @@ public abstract class Main public static void processSign(DataSource dataSource, String connector, String signature_mode, String signature_type, String pos_string, DataSink dataSink) throws PdfAsException { - // FIXME implement this - // TODO this will change soon due to the document-cleaning change request. - //PdfAS.applyStrictMode(pdfDataSource); - TablePos pos = null; if (pos_string != null) { diff --git a/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java b/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java index d2345c8..417c48f 100644 --- a/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java +++ b/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java @@ -50,6 +50,7 @@ public final class ErrorCode public static final int PLACEHOLDER_EXCEPTION = 700; public static final int CAPTION_NOT_FOUND_EXCEPTION = 701; - + public static final int CORRECTOR_EXCEPTION = 801; + public static final int EXTERNAL_CORRECTOR_TIMEOUT_REACHED = 802; } diff --git a/src/main/java/at/gv/egiz/pdfas/exceptions/framework/CorrectorException.java b/src/main/java/at/gv/egiz/pdfas/exceptions/framework/CorrectorException.java new file mode 100644 index 0000000..d4759f3 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/exceptions/framework/CorrectorException.java @@ -0,0 +1,36 @@ +/** + * + */ +package at.gv.egiz.pdfas.exceptions.framework; + +import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; + +/** + * Exceptions thrown by Correctors. + * + * @author wprinz + * + */ +public class CorrectorException extends PresentableException +{ + /** + * SVUID. + */ + private static final long serialVersionUID = -8646964226476111797L; + + public CorrectorException(int errorCode, String message, Throwable cause) + { + super(errorCode, message, cause); + } + + public CorrectorException(int errorCode, String message) + { + super(errorCode, message); + } + + public CorrectorException(int errorCode, Throwable cause) + { + super(errorCode, cause); + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/framework/input/correction/Corrector.java b/src/main/java/at/gv/egiz/pdfas/framework/input/correction/Corrector.java new file mode 100644 index 0000000..3b4d4b4 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/framework/input/correction/Corrector.java @@ -0,0 +1,41 @@ +/** + * + */ +package at.gv.egiz.pdfas.framework.input.correction; + +import at.gv.egiz.pdfas.exceptions.framework.CorrectorException; +import at.gv.egiz.pdfas.framework.input.PdfDataSource; + +/** + * Interface for PDF corretors. + * + *

+ * Often PDF documents generated by various document to PDF converters have an + * invalid structure that upsets PDF-AS. The correction mechanism allows these + * documents to be corrected before being signed. + *

+ *

+ * A PDF corrector takes an incorrect PDF document and transforms it into a + * correct one. + *

+ *

+ * Note that correcting a document destroys all signatures in that document, so + * never correct an already signed document. + *

+ * + * @author wprinz + */ +public interface Corrector +{ + /** + * Corrects the given PDF document to a form that PDF-AS can use. + * + * @param document + * The (incorrect) PDF document. + * @return Returns the corrected PDF document. + * @throws CorrectorException + * Exception thrown if the document couldn't be corrected. + */ + public PdfDataSource correctDocument(PdfDataSource document) throws CorrectorException; + +} diff --git a/src/main/java/at/gv/egiz/pdfas/framework/input/correction/CorrectorFactory.java b/src/main/java/at/gv/egiz/pdfas/framework/input/correction/CorrectorFactory.java new file mode 100644 index 0000000..083713f --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/framework/input/correction/CorrectorFactory.java @@ -0,0 +1,43 @@ +/** + * + */ +package at.gv.egiz.pdfas.framework.input.correction; + +import at.gv.egiz.pdfas.impl.input.correction.ExternalCorrector; +import at.gv.egiz.pdfas.impl.input.correction.InternalCorrector; +import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; +import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; + +/** + * Factory for creating Correctors. + * + * @author wprinz + */ +public class CorrectorFactory +{ + public static final String INTERNAL_CORRECTOR = "internal"; + + public static final String EXTERNAL_CORRECTOR = "external"; + + public static final String CORRECTOR_KEY = "corrector"; + + public static Corrector createCorrector(String id) throws SettingsException + { + if (id.equals(INTERNAL_CORRECTOR)) + { + return new InternalCorrector(); + } + if (id.equals(EXTERNAL_CORRECTOR)) + { + return new ExternalCorrector(); + } + throw new SettingsException("The connector id '" + id + "' is not a valid corrector id."); + } + + public static Corrector createCorrector() throws SettingsException + { + String id = SettingsReader.getInstance().getSetting(CORRECTOR_KEY, INTERNAL_CORRECTOR); + return createCorrector(id); + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java index a343de8..3b5d0a6 100644 --- a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java +++ b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java @@ -134,6 +134,8 @@ public class PdfAsObject implements PdfAs public SignResult sign(SignParameters signParameters) throws PdfAsException { CheckHelper.checkSignParameters(signParameters); + + signParameters.setDocument(PdfAS.applyStrictMode(signParameters.getDocument())); PdfASID signatorId = null; if (signParameters.getSignatureType().equals(Constants.SIGNATURE_TYPE_BINARY)) diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/correction/ExternalCorrector.java b/src/main/java/at/gv/egiz/pdfas/impl/input/correction/ExternalCorrector.java new file mode 100644 index 0000000..e244746 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/input/correction/ExternalCorrector.java @@ -0,0 +1,263 @@ +/** + * + */ +package at.gv.egiz.pdfas.impl.input.correction; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.gv.egiz.pdfas.exceptions.ErrorCode; +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.FileBased; +import at.gv.egiz.pdfas.impl.input.FileBasedPdfDataSourceImpl; +import at.gv.egiz.pdfas.web.helper.TempDirHelper; +import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; +import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException; +import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; + +/** + * Corrects the document using an extrenal commandline tool. + * + *

+ * Process.destroy after a certain timeout does not work if the executable is a + * Windows batch file. + *

+ * + * @author wprinz + */ +public class ExternalCorrector implements Corrector +{ + public static final String INPUT_DOCUMENT_REPLACE = "##input_document##"; + + public static final String OUTPUT_DOCUMENT_REPLACE = "##output_document##"; + + public static final String COMMANDLINE_KEY = "external_corrector_commandline"; + + public static final String TIMEOUT_KEY = "external_corrector_timeout"; + + protected static final int DEFAULT_TIMEOUT = 1000; + + /** + * The log. + */ + private static final Log log = LogFactory.getLog(ExternalCorrector.class); + + /** + * @see at.gv.egiz.pdfas.framework.input.correction.Corrector#correctDocument(at.gv.egiz.pdfas.framework.input.PdfDataSource) + */ + public PdfDataSource correctDocument(PdfDataSource document) throws CorrectorException + { + + try + { + String outName = null; + File in = null; + if (document instanceof FileBased) + { + FileBased fb = (FileBased) document; + in = fb.getFile(); + outName = in.getName() + "_correction_outfile.pdf"; + } + else + { + in = TempDirHelper.placeInputIntoTempDirFile(document.createInputStream(), "correction_infile.pdf"); + outName = "correction_outfile.pdf"; + } + + File out = TempDirHelper.formTempFile(outName); + + String commandline = SettingsReader.getInstance().getSetting(COMMANDLINE_KEY); + long timeout = SettingsReader.getInstance().getIntSetting(TIMEOUT_KEY, DEFAULT_TIMEOUT); + + String inF = in.getAbsolutePath(); + commandline = commandline.replaceFirst(INPUT_DOCUMENT_REPLACE, inF.replaceAll("\\\\", "\\\\\\\\")); + String outF = out.getAbsolutePath(); + commandline = commandline.replaceFirst(OUTPUT_DOCUMENT_REPLACE, outF.replaceAll("\\\\", "\\\\\\\\")); + + log.info(commandline); + + Process p = Runtime.getRuntime().exec(commandline); + + Thread outT = null; + Thread errT = null; + TimeoutThread tt = null; + BufferedReader outReader = null; + BufferedReader errReader = null; + + try + { + outReader = new BufferedReader(new InputStreamReader(p.getInputStream())); + errReader = new BufferedReader(new InputStreamReader(p.getErrorStream())); + + outT = new Thread(new ReaderPrinter(outReader, "STDOUT")); + errT = new Thread(new ReaderPrinter(errReader, "STDERR")); + + tt = new TimeoutThread(p, timeout, new Thread[] { outT, errT }); + + tt.start(); + outT.start(); + errT.start(); + + log.trace("Joining the STDOUT thread..."); + outT.join(); + log.trace("STDOUT thread joined."); + log.trace("Joining the STDERR thread..."); + errT.join(); + log.trace("STDERR thread joined."); + + log.trace("Waiting for process to end..."); + p.waitFor(); + log.trace("process has ended."); + + log.trace("Interrupting timeout thread..."); + tt.interrupt(); + log.trace("timeout thread has been interrupted."); + + int exitValue = p.exitValue(); + log.info("External Corrector exited with: " + exitValue); + + if (tt.isTimedOut()) + { + throw new CorrectorException(ErrorCode.EXTERNAL_CORRECTOR_TIMEOUT_REACHED, "The external corrector process timed out. timeout = " + timeout); + } + + PdfDataSource ds = new FileBasedPdfDataSourceImpl(out, (int) out.length()); + return ds; + } + finally + { + if (outT != null) + { + outT.interrupt(); + } + if (errT != null) + { + errT.interrupt(); + } + if (tt != null) + { + tt.interrupt(); + } + if (outReader != null) + { + outReader.close(); + } + if (errReader != null) + { + errReader.close(); + } + } + + } + catch (IOException e) + { + throw new CorrectorException(ErrorCode.CORRECTOR_EXCEPTION, e); + } + catch (InterruptedException e) + { + throw new CorrectorException(ErrorCode.CORRECTOR_EXCEPTION, e); + } + catch (SettingNotFoundException e) + { + throw new CorrectorException(ErrorCode.CORRECTOR_EXCEPTION, e); + } + catch (SettingsException e) + { + throw new CorrectorException(ErrorCode.CORRECTOR_EXCEPTION, e); + } + } + + protected static class ReaderPrinter implements Runnable + { + protected BufferedReader reader = null; + + protected String streamName = null; + + public ReaderPrinter(BufferedReader reader, String streamName) + { + this.reader = reader; + this.streamName = streamName; + } + + public void run() + { + try + { + String line = null; + + while ((line = this.reader.readLine()) != null) + { + if (line != null) + { + log.info(streamName + ": " + line); + } + } + } + catch (IOException e) + { + log.error(e); + } + } + } + + protected static class TimeoutThread extends Thread + { + protected Process proc = null; + + protected long timeout = -1; + + protected boolean ranIntoTimeout = false; + + protected Thread[] threads; + + protected BufferedReader errReader; + + public TimeoutThread(Process proc, long timeout, Thread[] threadsToInterrupt) + { + this.proc = proc; + this.timeout = timeout; + this.threads = threadsToInterrupt; + } + + public void run() + { + try + { + Thread.sleep(this.timeout); + log.info("The timeout was reached. Destroying the process."); + proc.destroy(); + ranIntoTimeout = true; + log.trace("destroy has been called."); + log.trace("Interrupting threads..."); + for (int i = 0; i < this.threads.length; i++) + { + this.threads[i].interrupt(); + } + log.trace("threads have been interrupted."); + } + catch (InterruptedException e) + { + log.debug("Timeout thread interrupted. This means that the process finished successfully."); + } + } + + /** + * Tells, if the process ran into the timeout. + * + * @return Returns true if the timeout was reached. Returns false if the + * timeout was not reached. + */ + public boolean isTimedOut() + { + return this.ranIntoTimeout; + } + } + +} 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 new file mode 100644 index 0000000..409a600 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java @@ -0,0 +1,57 @@ +/** + * + */ +package at.gv.egiz.pdfas.impl.input.correction; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import at.gv.egiz.pdfas.exceptions.ErrorCode; +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 com.lowagie.text.DocumentException; +import com.lowagie.text.pdf.PdfReader; +import com.lowagie.text.pdf.PdfStamper; + +/** + * Corrects a document using iText. + * + * @author wprinz + */ +public class InternalCorrector implements Corrector +{ + + /** + * @see at.gv.egiz.pdfas.framework.input.correction.Corrector#correctDocument(at.gv.egiz.pdfas.framework.input.PdfDataSource) + */ + public PdfDataSource correctDocument(PdfDataSource document) throws CorrectorException + { + try + { + byte[] pdf = document.getAsByteArray(); + PdfReader reader = new PdfReader(pdf); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(pdf.length); + + PdfStamper stamper = new PdfStamper(reader, baos, '\0', false); + stamper.close(); + + baos.close(); + byte[] corrected_pdf = baos.toByteArray(); + + return new ByteArrayPdfDataSourceImpl(corrected_pdf); + } + catch (DocumentException e) + { + throw new CorrectorException(ErrorCode.CORRECTOR_EXCEPTION, e); + } + catch (IOException e) + { + throw new CorrectorException(ErrorCode.CORRECTOR_EXCEPTION, e); + } + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java b/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java index 3775776..1b7971c 100644 --- a/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java +++ b/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java @@ -137,7 +137,7 @@ public class TempDirHelper return pdfDataSource; } - protected static File placeInputIntoTempDirFile(InputStream input, String fileNameSuffix) throws IOException + public static File placeInputIntoTempDirFile(InputStream input, String fileNameSuffix) throws IOException { String fileName = formatFileName(fileNameSuffix); @@ -156,6 +156,23 @@ public class TempDirHelper return tmpFile; } + + public static File formTempFile(String fileNameSuffix) + { + String fileName = formatFileName(fileNameSuffix); + File tmpFile = getFileInTempDir(fileName); + + return tmpFile; + } + + protected static File getFileInTempDir (String fileName) + { + File tempDir = new File(new File(SettingsReader.RESOURCES_PATH), "pdfastmp"); + + File tmpFile = new File(tempDir, fileName); + + return tmpFile; + } protected static String formatFileName(String fileNameSuffix) { @@ -176,9 +193,7 @@ public class TempDirHelper protected static File createTempFileInDir(String fileName) throws IOException { - File tempDir = new File(new File(SettingsReader.RESOURCES_PATH), "pdfastmp"); - - File tmpFile = new File(tempDir, fileName); + File tmpFile = getFileInTempDir(fileName); tmpFile.createNewFile(); 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 9aef071..973b6f4 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -31,10 +31,14 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.pdfas.commandline.CommandlineConnectorChooser; import at.gv.egiz.pdfas.exceptions.ErrorCode; +import at.gv.egiz.pdfas.exceptions.framework.CorrectorException; import at.gv.egiz.pdfas.framework.ConnectorParameters; import at.gv.egiz.pdfas.framework.input.PdfDataSource; +import at.gv.egiz.pdfas.framework.input.correction.Corrector; +import at.gv.egiz.pdfas.framework.input.correction.CorrectorFactory; import at.gv.egiz.pdfas.framework.output.DataSink; 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.web.VerifySessionInformation; @@ -105,6 +109,8 @@ public abstract class PdfAS * The Mime Type of a PDF document. */ public static final String PDF_MIME_TYPE = "application/pdf"; + + public static final String CORRECT_DOCUMENT_IF_NECESSARY_KEY = "correct_document_if_necessary"; /** * The logger definition. @@ -182,8 +188,10 @@ public abstract class PdfAS * @param pdfDataSource * The pdf to be checked against strict mode. * @throws PDFDocumentException + * @throws SettingsException + * @throws CorrectorException */ - public static void applyStrictMode(PdfDataSource pdfDataSource) throws PDFDocumentException + public static PdfDataSource applyStrictMode(PdfDataSource pdfDataSource) throws PDFDocumentException, SettingsException, CorrectorException { if (isStrictPdfChecking()) { @@ -200,8 +208,35 @@ public abstract class PdfAS catch (Exception e) { log.debug("Error while parsing Document.", e); - throw new PDFDocumentException(201, e); + + boolean tryToCorrect = SettingsReader.getInstance().getSetting(CORRECT_DOCUMENT_IF_NECESSARY_KEY, "false").equals("true"); + if (!tryToCorrect) + { + throw new PDFDocumentException(201, e); + } + log.debug("Correcting document..."); + Corrector cor = CorrectorFactory.createCorrector(); + PdfDataSource correctedDS = cor.correctDocument(pdfDataSource); + log.debug("Correction finished."); + + return correctedDS; + } + + return pdfDataSource; + } + + public static at.gv.egiz.pdfas.api.io.DataSource applyStrictMode (at.gv.egiz.pdfas.api.io.DataSource dataSource) throws PDFDocumentException, SettingsException, CorrectorException + { + if (dataSource.getMimeType().equals("application/pdf")) + { + PdfDataSource pdfDS = new PdfDataSourceAdapter(dataSource); + PdfDataSource correctedDS = applyStrictMode(pdfDS); + if (correctedDS != pdfDS) + { + return new at.gv.egiz.pdfas.impl.api.commons.DataSourceApiAdapter(correctedDS); + } } + return dataSource; } // TODO: unused method - remove diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java index 054da24..c58da3f 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java @@ -418,6 +418,13 @@ public class SettingsReader implements Serializable // } return result; } + + // TODO in the next change request, the Setting system will be refactored + // this is just for testing purposes. + public void setSetting(String key, String value) + { + properties_.setProperty(key, value); + } /** * Relocates the relative file. diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java index 11bd0e0..76159ec 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java @@ -565,7 +565,7 @@ public abstract class Main public static void processSign(PdfDataSource pdfDataSource, String connector, String signature_mode, String signature_type, String pos_string, DataSink dataSink) throws PresentableException { - PdfAS.applyStrictMode(pdfDataSource); + pdfDataSource = PdfAS.applyStrictMode(pdfDataSource); TablePos pos = null; if (pos_string != null) 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 16b12e1..e2de8ae 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 @@ -254,7 +254,7 @@ public class SignServlet extends HttpServlet try { - PdfAS.applyStrictMode(ud.pdfDataSource); + ud.pdfDataSource = PdfAS.applyStrictMode(ud.pdfDataSource); SignSessionInformation si = new SignSessionInformation(); // SessionTable.generateSessionInformationObject(); si.connector = ud.sig_app; diff --git a/work/cfg/config.properties b/work/cfg/config.properties index bc97731..913cbc5 100644 --- a/work/cfg/config.properties +++ b/work/cfg/config.properties @@ -14,13 +14,42 @@ ldap.url=http://xxx.yyy.z.com:5000/some/fake/url cert.alg.rsa=http://www.w3.org/2000/09/xmldsig#rsa-sha1 cert.alg.ecdsa=http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1 +# Beim Signieren: Überprüfung ob Dokument PDF-Version 1.4 (oder weniger) hat strict_mode=false +# Beim Signieren: +# Wenn das Dokument nicht verarbeitet werden kann wird versucht es +# zuerst zu korrigieren und dann das korrigierte Dokument zu signieren. +correct_document_if_necessary=true + +# Wenn ein Dokument korrigiert werden soll: +# Gibt an mit welchem Corrector ein zu korrigierendes Dokument korrigiert wird: +# internal - das Dokument wird mit dem "internen" iText Corrector korrigiert +# external - das Dokument wird durch einen externen Kommandozeilenaufruf korrigiert. +# Hinweis: ein externes Programm aufzurufen birgt gewisse Risiken in sich +# und sollte daher nöglichst nicht verwendet werden. +corrector=internal + +# Kommandozeile für den externen Connector. +# Die Variablen ##input_document## bzw. ##output_document## werden von PDF-AS +# durch die absoluten Pfad- und Dateinamen des zu korrigierenden bzw. des +# korrigierten Dokuments ersetzt. +# Als Pfad-Separator sollte '/' verwendet werden. +external_corrector_commandline=C:/correct.exe "##input_document##" "##output_document##" + +# Timeout (ms) für die Ausführung des externen Correctors. +# Das Kommando wird abgebrochen, wenn das Timeout erreicht wird bevor +# das Kommando abgearbeitet wurde. +# Achtung: Es besteht allerdings keine Garantie, dass der Korrekturvorgang auch tatsächlich +# durch ein Timeout abgebrochen wird. Dies ist im Wesentlichen abhängig von der Beschaffenheit +# des Korrekturprogramms sowie vom verwendeten Betriebssystem. +external_corrector_timeout=15000 + # Überprüfe Korrektheit des Dokuments # bei binary_only=true: Fehler falls textuelle Signatur # bei assume_only_signauture_blocks=false: Fehler falls inkremetelle Updates nach Signatur # In beiden Fällen wird check_old_textual_sigs berücksichtigt. -check_document=true +check_document=false #VerificationFilterPatameters # modify only if you really know the algorithms diff --git a/work/cfg/help_text.properties b/work/cfg/help_text.properties index 3a9e4ae..699ab54 100644 --- a/work/cfg/help_text.properties +++ b/work/cfg/help_text.properties @@ -70,4 +70,8 @@ error.code.600=Die Sitzung ist entweder ung #PlaceholderException error.code.700=Der Platzhalter für einen Wert wurde zu kurz gewählt. Es konnte nicht der gesamte Wert in die Signatur eingefügt werden. Bitte vergrößern Sie die Länge des entsprechenden Platzhalters im Signaturprofil. #CaptionNotFoundException -error.code.701=Die Überschrift (Caption/Label) konnte nicht eindeutig wiedergefunden werden. Dies geschieht gewöhnlich wenn bei der (häufig absoluten) Positionierung zu wenig Platz für die Überschrift (Caption/Label) verhanden ist und diese ungünstig umgebrochen werden muss. Bitte stellen Sie dieser Überschrift mehr Platz im Signaturblock zur Verfügung oder entfernen Sie aus dieser alle Leerzeichen. +error.code.701=Die Überschrift (Caption/Label) konnte nicht eindeutig wiedergefunden werden. Dies geschieht gewöhnlich wenn bei der (häufig absoluten) Positionierung zu wenig Platz für die Überschrift (Caption/Label) verhanden ist und diese ungünstig umgebrochen werden muss. Bitte stellen Sie dieser Überschrift mehr Platz im Signaturblock zur Verfügung oder entfernen Sie aus dieser alle Leerzeichen. + +#CorrectorException +error.code.801=Das Dokument konnte nicht korrigiert werden. +error.code.802=Die externe Korrektur konnte nicht innerhalb des festgesetzten Timeouts fertiggestellt werden. -- cgit v1.2.3