diff options
Diffstat (limited to 'pdf-as-lib/src/main/java/at')
15 files changed, 266 insertions, 150 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java index d6ed2028..c710082b 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/PdfAsFactory.java @@ -36,6 +36,7 @@ import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import org.apache.log4j.BasicConfigurator; import org.apache.log4j.PropertyConfigurator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,11 +54,12 @@ public class PdfAsFactory { private static final String DEFAULT_CONFIG_RES = "config/config.zip"; -// private static final String MAN_ATTRIBUTE = "JARMANIFEST"; -// private static final String PDF_AS_LIB = "PDF-AS-LIB"; -// private static final String IMPL_VERSION = "Implementation-Version"; -// private static final String SCM_REVISION = "SCMREVISION"; - + private static final String DEFAULT_LOG4J_ENV = "log4j.configuration"; + + // private static final String MAN_ATTRIBUTE = "JARMANIFEST"; + // private static final String PDF_AS_LIB = "PDF-AS-LIB"; + // private static final String IMPL_VERSION = "Implementation-Version"; + // private static final String SCM_REVISION = "SCMREVISION"; static { /* @@ -66,13 +68,16 @@ public class PdfAsFactory { */ IAIK.addAsProvider(); ECCelerate.addAsProvider(); - - System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + + System.out + .println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println("+ PDF-AS: " + getVersion()); System.out.println("+ PDF-AS SCM Revision: " + getSCMRevision()); System.out.println("+ IAIK-JCE Version: " + IAIK.getVersionInfo()); - System.out.println("+ ECCelerate Version: " + ECCelerate.getInstance().getVersion()); - System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("+ ECCelerate Version: " + + ECCelerate.getInstance().getVersion()); + System.out + .println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); } private static boolean log_configured = false; @@ -86,30 +91,64 @@ public class PdfAsFactory { /** * Create a new instance of PDF-AS - * @param configuration The PDF-AS configuration + * + * @param configuration + * The PDF-AS configuration * @return */ public static PdfAs createPdfAs(File configuration) { if (!log_configured) { synchronized (log_mutex) { if (!log_configured) { - File log4j = new File(configuration.getAbsolutePath() - + File.separator + "cfg" + File.separator - + "log4j.properties"); - logger.info("Loading log4j configuration: " - + log4j.getAbsolutePath()); - if (log4j.exists()) { - try { - System.setProperty("pdf-as.work-dir", - configuration.getAbsolutePath()); - PropertyConfigurator.configure(new FileInputStream( - log4j)); - logger.info("Configured Log4j with: " + log4j.getAbsolutePath()); - } catch (FileNotFoundException e) { - e.printStackTrace(); + + if (System.getProperty(DEFAULT_LOG4J_ENV) != null) { + String file = System.getProperty(DEFAULT_LOG4J_ENV); + File log4j = new File(file); + System.out.println("Configuring logging with: " + log4j.getAbsolutePath()); + logger.info("Loading log4j configuration: " + + log4j.getAbsolutePath()); + if (log4j.exists()) { + try { + System.setProperty("pdf-as.work-dir", + configuration.getAbsolutePath()); + PropertyConfigurator + .configure(new FileInputStream(log4j)); + logger.info("Configured Log4j with: " + + log4j.getAbsolutePath()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.err.println("Failed to initialize logging System. Defaulting to basic configuration!"); + BasicConfigurator.configure(); + } + } else { + System.err.println("Log4j File: " + log4j.getAbsolutePath() + " does not exist! Defaulting to basic configuration!"); + BasicConfigurator.configure(); + } + } else { + File log4j = new File(configuration.getAbsolutePath() + + File.separator + "cfg" + File.separator + + "log4j.properties"); + System.out.println("Configuring logging with: " + log4j.getAbsolutePath()); + logger.info("Loading log4j configuration: " + + log4j.getAbsolutePath()); + if (log4j.exists()) { + try { + System.setProperty("pdf-as.work-dir", + configuration.getAbsolutePath()); + PropertyConfigurator + .configure(new FileInputStream(log4j)); + logger.info("Configured Log4j with: " + + log4j.getAbsolutePath()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + System.err.println("Failed to initialize logging System. Defaulting to basic configuration!"); + BasicConfigurator.configure(); + } + } else { + System.err.println("Log4j File: " + log4j.getAbsolutePath() + " does not exist! Defaulting to basic configuration!"); + BasicConfigurator.configure(); } } - log_configured = true; } } @@ -120,8 +159,11 @@ public class PdfAsFactory { /** * Creates a sign parameter - * @param configuration The configuration to be used - * @param dataSource The data source to be used + * + * @param configuration + * The configuration to be used + * @param dataSource + * The data source to be used * @return */ public static SignParameter createSignParameter( @@ -132,8 +174,11 @@ public class PdfAsFactory { /** * Creates a verification parameter - * @param configuration The configuration to be used - * @param dataSource The data source to be used + * + * @param configuration + * The configuration to be used + * @param dataSource + * The data source to be used * @return */ public static VerifyParameter createVerifyParameter( @@ -216,18 +261,20 @@ public class PdfAsFactory { } } } - + /** * Gets the PDF-AS SCM Revision + * * @return */ public static String getSCMRevision() { Package pack = PdfAsFactory.class.getPackage(); return pack.getSpecificationVersion(); } - - /** - * Gets the PDF-AS Version + + /** + * Gets the PDF-AS Version + * * @return PDF-AS Verison string */ public static String getVersion() { diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java index cf7376c2..ed7033eb 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java @@ -103,16 +103,6 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { if (parameter.getOutput() == null) { throw new PdfAsValidationException("error.pdf.sig.11", null); } - - /* - * try { PDDocument doc = PDDocument.load(new - * ByteArrayInputStream(parameter.getDataSource().getByteData())); - * PDFUtils.checkPDFPermissions(doc); doc.close(); } catch(IOException - * e) { throw new PdfAsValidationException("error.pdf.sig.12", null, e); - * } - */ - - // TODO: verify Sign Parameter } private void verifyVerifyParameter(VerifyParameter parameter) @@ -126,8 +116,6 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { || parameter.getDataSource().getByteData() == null) { throw new PdfAsValidationException("error.pdf.verify.01", null); } - - // TODO: verify Verify Parameter } public SignResult sign(SignParameter parameter) throws PdfAsException { @@ -200,9 +188,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { throw new PdfAsException("error.pdf.sig.01", e); } finally { if(status != null) { - if(status.getPdfObject() != null) { - status.getPdfObject().close(); - } + status.clear(); } logger.trace("sign done"); } @@ -444,9 +430,7 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants { throw new PdfAsException("error.pdf.sig.06", e); } finally { if(status != null) { - if(status.getPdfObject() != null) { - status.getPdfObject().close(); - } + status.clear(); } } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java index b6405c2d..84e85686 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/positioning/Positioning.java @@ -113,6 +113,8 @@ public class Positioning { .getAllPages().get(page - 1); PDRectangle cropBox = pdPage.getCropBox(); + // fallback to MediaBox if Cropbox not available! + if (cropBox == null) { cropBox = pdPage.findCropBox(); } @@ -121,8 +123,6 @@ public class Positioning { cropBox = pdPage.findMediaBox(); } - // TODO: fallback to MediaBox if Cropbox not available! - // getPagedimensions // Rectangle psize = reader.getPageSizeWithRotation(page); // int page_rotation = reader.getPageRotation(page); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java index 8f945414..c3ce8cc8 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/TableFactory.java @@ -278,7 +278,7 @@ public class TableFactory implements IProfileConstants { } */ /* String overrideVal = OverridePropertyHolder.getProperty(key); - if (value != null && sigEntry != null && !sigEntry.isPlaceholder && overrideVal != null) { // TODO this!! SignatureEntry.isPlaceholder + if (value != null && sigEntry != null && !sigEntry.isPlaceholder && overrideVal != null) { value = overrideVal; if (logger.isDebugEnabled()) { logger.debug("Using override property for key '" + key + "' = " + value); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java index 1c001b0c..90f39ed7 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsTemplateCreator.java @@ -32,7 +32,7 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator { public InputStream buildPDF(PDFAsVisualSignatureDesigner properties) throws IOException { - logger.info("pdf building has been started"); + logger.debug("pdf building has been started"); PDFTemplateStructure pdfStructure = pdfBuilder.getStructure(); // we create array of [Text, ImageB, ImageC, ImageI] @@ -134,7 +134,7 @@ public class PDFAsTemplateCreator extends PDFTemplateCreator { { logger.error("COSVisitorException: can't get apereance stream ", e); } - logger.info("stream returning started, size= " + in.available()); + logger.debug("stream returning started, size= " + in.available()); // we must close the document template.close(); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java index f7a6c824..39fe164c 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureBuilder.java @@ -69,7 +69,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { } } - logger.info("Drawing Table:"); + logger.debug("Drawing Table:"); abstractTable.dumpTable(); if (abstractTable.getBGColor() != null) { @@ -90,7 +90,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { } for (int cols_idx = 0; cols_idx < colsSizes.length; cols_idx++) { - logger.info("Col: " + cols_idx + " : " + colsSizes[cols_idx]); + logger.debug("Col: " + cols_idx + " : " + colsSizes[cols_idx]); } float border = abstractTable.style.getBorder(); @@ -106,7 +106,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { // draw the rows float nexty = y + tableHeight; for (int i = 0; i <= rows; i++) { - logger.info("ROW LINE: {} {} {} {}", x, nexty, x + tableWidth, + logger.debug("ROW LINE: {} {} {} {}", x, nexty, x + tableWidth, nexty); contentStream.drawLine(x, nexty, x + tableWidth, nexty); if (i < abstractTable.getRowHeights().length) { @@ -129,7 +129,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { if (subtable && i == cols) { continue; } - logger.info("COL LINE: {} {} {} {}", nextx, ypos, nextx, + logger.debug("COL LINE: {} {} {} {}", nextx, ypos, nextx, yheight); contentStream.drawLine(nextx, ypos, nextx, yheight); if (i < colsSizes.length) { @@ -167,13 +167,13 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { if (innerFormResources.getFonts().containsValue(textFont)) { String fontID = getFontID(textFont); - logger.info("Using Font: " + fontID); + logger.debug("Using Font: " + fontID); contentStream.appendRawCommands("/" + fontID + " " + fontSize + " Tf\n"); } else { contentStream.setFont(textFont, fontSize); } - logger.info("Writing: " + textx + " : " + ttexty + " = " + logger.debug("Writing: " + textx + " : " + ttexty + " = " + text + " as " + cell.getType() + " w " + fontName); contentStream.moveTextPositionByAmount(textx, ttexty); @@ -222,7 +222,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { - abstractTable.getRowHeights()[i] / 2; imgy = imgy - image.getSize() / 2; } - logger.info("Image: " + textx + " : " + imgy); + logger.debug("Image: " + textx + " : " + imgy); contentStream.drawXObject(pdImage, textx, imgy, image.getSize(), image.getSize()); // contentStream.endMarkedContentSequence(); @@ -234,14 +234,14 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { // texty = texty - padding; tableX = textx - padding; PDFBoxTable tbl_value = (PDFBoxTable) cell.getValue(); - logger.info("Table: " + tableX + " : " + tableY); + logger.debug("Table: " + tableX + " : " + tableY); drawTable(page, contentStream, tableX, tableY, tbl_value, doc, true); } textx += (colsSizes != null) ? colsSizes[j] : colWidth; } // if (i + 1 < abstractTable.getRowHeights().length) { - logger.info("Row {} from {} - {} - {} = {}", i, texty, + logger.debug("Row {} from {} - {} - {} = {}", i, texty, abstractTable.getRowHeights()[i], padding * 2, texty - (abstractTable.getRowHeights()[i] + padding * 2)); texty -= abstractTable.getRowHeights()[i] + padding * 2; @@ -286,7 +286,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { procSetArr.add(COSName.getPDFName("ImageB")); procSetArr.add(COSName.getPDFName("ImageI")); getStructure().setProcSet(procSetArr); - logger.info("ProcSet array has been created"); + logger.debug("ProcSet array has been created"); } @Override @@ -311,7 +311,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { } } - logger.info("TOTAL Width: " + table.getWidth()); + logger.debug("TOTAL Width: " + table.getWidth()); float total = 0; @@ -325,7 +325,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { } for (int cols_idx = 0; cols_idx < colsSizes.length; cols_idx++) { - logger.info("Col: " + cols_idx + " : " + colsSizes[cols_idx]); + logger.debug("Col: " + cols_idx + " : " + colsSizes[cols_idx]); } /* @@ -417,7 +417,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { stream.close(); PDStream innterFormStream = getStructure().getPage().getContents(); getStructure().setInnterFormStream(innterFormStream); - logger.info("Strean of another form (inner form - it would be inside holder form) has been created"); + logger.debug("Strean of another form (inner form - it would be inside holder form) has been created"); } catch (Throwable e) { e.printStackTrace(); @@ -439,7 +439,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { */ holderFormResources.getCOSDictionary().setItem(COSName.PROC_SET, procSet); - logger.info("inserted ProcSet to PDF"); + logger.debug("inserted ProcSet to PDF"); } public void injectAppearanceStreams(PDStream holderFormStream, @@ -470,7 +470,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { String innerFormComment = getStructure().getInnterFormStream() .getInputStreamAsString(); - logger.info("Inner Form Stream: " + innerFormComment); + logger.debug("Inner Form Stream: " + innerFormComment); // appendRawCommands(getStructure().getInnterFormStream().createOutputStream(), // getStructure().getInnterFormStream().getInputStreamAsString()); @@ -481,7 +481,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { .createOutputStream(), innerFormComment); // appendRawCommands(getStructure().getImageFormStream().createOutputStream(), // imgFormComment); - logger.info("Injected apereance stream to pdf"); + logger.debug("Injected apereance stream to pdf"); } @@ -490,21 +490,21 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { page.setMediaBox(new PDRectangle(properties.getPageWidth(), properties .getPageHeight())); getStructure().setPage(page); - logger.info("PDF page has been created"); + logger.debug("PDF page has been created"); } public void createAcroForm(PDDocument template) { PDAcroForm theAcroForm = new PDAcroForm(template); template.getDocumentCatalog().setAcroForm(theAcroForm); getStructure().setAcroForm(theAcroForm); - logger.info("Acro form page has been created"); + logger.debug("Acro form page has been created"); } public void createSignatureField(PDAcroForm acroForm) throws IOException { PDSignatureField sf = new PDSignatureField(acroForm); getStructure().setSignatureField(sf); - logger.info("Signature field has been created"); + logger.debug("Signature field has been created"); } public void createSignature(PDSignatureField pdSignatureField, PDPage page, @@ -517,7 +517,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { pdSignature.setByteRange(new int[] { 0, 0, 0, 0 }); pdSignature.setContents(new byte[4096]); getStructure().setPdSignature(pdSignature); - logger.info("PDSignatur has been created"); + logger.debug("PDSignatur has been created"); } public void createAcroFormDictionary(PDAcroForm acroForm, @@ -531,7 +531,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { acroFormDict.setString(COSName.DA, "/sylfaen 0 Tf 0 g"); getStructure().setAcroFormFields(acroFormFields); getStructure().setAcroFormDictionary(acroFormDict); - logger.info("AcroForm dictionary has been created"); + logger.debug("AcroForm dictionary has been created"); } public void createSignatureRectangle(PDSignatureField signatureField, @@ -563,11 +563,11 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { rect.setUpperRightY((float) upDst.getY()); rect.setLowerLeftY((float) llDst.getY()); rect.setLowerLeftX((float) llDst.getX()); - logger.info("rectangle of signature has been created: {}", + logger.debug("rectangle of signature has been created: {}", rect.toString()); signatureField.getWidget().setRectangle(rect); getStructure().setSignatureRectangle(rect); - logger.info("rectangle of signature has been created"); + logger.debug("rectangle of signature has been created"); } public void createAffineTransform(byte[] params) { @@ -575,14 +575,14 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { params[2], params[3], params[4], params[5]); // transform.rotate(90); getStructure().setAffineTransform(transform); - logger.info("Matrix has been added"); + logger.debug("Matrix has been added"); } public void createSignatureImage(PDDocument template, InputStream inputStream) throws IOException { PDJpeg img = new PDJpeg(template, inputStream); getStructure().setJpedImage(img); - logger.info("Visible Signature Image has been created"); + logger.debug("Visible Signature Image has been created"); // pdfStructure.setTemplate(template); inputStream.close(); @@ -601,20 +601,20 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { formrect.setLowerLeftY(translated[3]); getStructure().setFormaterRectangle(formrect); - logger.info("Formater rectangle has been created"); + logger.debug("Formater rectangle has been created"); } public void createHolderFormStream(PDDocument template) { PDStream holderForm = new PDStream(template); getStructure().setHolderFormStream(holderForm); - logger.info("Holder form Stream has been created"); + logger.debug("Holder form Stream has been created"); } public void createHolderFormResources() { PDResources holderFormResources = new PDResources(); getStructure().setHolderFormResources(holderFormResources); - logger.info("Holder form resources have been created"); + logger.debug("Holder form resources have been created"); } @@ -626,7 +626,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { holderForm.setBBox(formrect); holderForm.setFormType(1); getStructure().setHolderForm(holderForm); - logger.info("Holder form has been created"); + logger.debug("Holder form has been created"); } @@ -646,13 +646,13 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { signatureField.getWidget().setAppearance(appearance); getStructure().setAppearanceDictionary(appearance); - logger.info("PDF appereance Dictionary has been created"); + logger.debug("PDF appereance Dictionary has been created"); } public void createInnerFormResource() { getStructure().setInnerFormResources(innerFormResources); - logger.info("Resources of another form (inner form - it would be inside holder form) have been created"); + logger.debug("Resources of another form (inner form - it would be inside holder form) have been created"); } public void createInnerForm(PDResources innerFormResources, @@ -662,7 +662,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { innerForm.setBBox(formrect); innerForm.setFormType(1); getStructure().setInnerForm(innerForm); - logger.info("Another form (inner form - it would be inside holder form) have been created"); + logger.debug("Another form (inner form - it would be inside holder form) have been created"); } @@ -670,19 +670,19 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { PDResources holderFormResources) { String name = holderFormResources.addXObject(innerForm, "FRM"); getStructure().setInnerFormName(name); - logger.info("Alerady inserted inner form inside holder form"); + logger.debug("Alerady inserted inner form inside holder form"); } public void createImageFormStream(PDDocument template) { PDStream imageFormStream = new PDStream(template); getStructure().setImageFormStream(imageFormStream); - logger.info("Created image form Stream"); + logger.debug("Created image form Stream"); } public void createImageFormResources() { PDResources imageFormResources = new PDResources(); getStructure().setImageFormResources(imageFormResources); - logger.info("Created image form Resources"); + logger.debug("Created image form Resources"); } public void createImageForm(PDResources imageFormResources, @@ -716,7 +716,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { this.getStructure().setImageForm(imageForm); this.getStructure().setImageFormName(imageFormName); this.getStructure().setImageName(imageName); - logger.info("Created image form"); + logger.debug("Created image form"); } public void appendRawCommands(OutputStream os, String commands) @@ -727,7 +727,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { public void createVisualSignature(PDDocument template) { this.getStructure().setVisualSignature(template.getDocument()); - logger.info("Visible signature has been created"); + logger.debug("Visible signature has been created"); } @@ -739,7 +739,7 @@ public class PDFAsVisualSignatureBuilder extends PDVisibleSigBuilder { widgetDict.setItem(COSName.DR, holderFormResources.getCOSObject()); getStructure().setWidgetDictionary(widgetDict); - logger.info("WidgetDictionary has been crated"); + logger.debug("WidgetDictionary has been crated"); } public void closeTemplate(PDDocument template) throws IOException { diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java index 9ccf4eed..1b3cf688 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFAsVisualSignatureProperties.java @@ -40,7 +40,7 @@ public class PDFAsVisualSignatureProperties extends PDVisibleSigProperties { float posy = designer.getPageHeight() - pos.getY(); designer.coordinates(pos.getX(), posy); float[] form_rect = new float[] {0,0, main.getWidth() + 2, main.getHeight() + 2}; - logger.info("AP Rect: {} {} {} {}", form_rect[0], form_rect[1], form_rect[2], form_rect[3]); + logger.debug("AP Rect: {} {} {} {}", form_rect[0], form_rect[1], form_rect[2], form_rect[3]); designer.formaterRectangleParams(form_rect); //this.setPdVisibleSignature(designer); } catch (Throwable e) { diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxFont.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxFont.java index 62aaf5a8..b0c4b552 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxFont.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxFont.java @@ -125,7 +125,7 @@ public class PDFBoxFont { public PDFBoxFont(String fontDesc, ISettings settings) throws IOException { this.settings = settings; this.fontDesc = fontDesc; - logger.info("Creating Font: " + fontDesc); + logger.debug("Creating Font: " + fontDesc); this.setFont(fontDesc); } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java index 1c9ad953..1d8928aa 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PDFBoxTable.java @@ -504,22 +504,22 @@ public class PDFBoxTable { } public void dumpTable() { - logger.info("====================================================================="); - logger.info("Information about: " + this.table.getName()); - logger.info("\tDimensions: {} x {} (W x H)", this.tableWidth, + logger.debug("====================================================================="); + logger.debug("Information about: " + this.table.getName()); + logger.debug("\tDimensions: {} x {} (W x H)", this.tableWidth, this.tableHeight); - logger.info("\tPadding: {}", padding); - logger.info("\t================================"); - logger.info("\tRow Heights:"); + logger.debug("\tPadding: {}", padding); + logger.debug("\t================================"); + logger.debug("\tRow Heights:"); for (int i = 0; i < rowHeights.length; i++) { - logger.info("\t[{}] : {}", i, this.rowHeights[i]); + logger.debug("\t[{}] : {}", i, this.rowHeights[i]); } - logger.info("\t================================"); - logger.info("\tCol Widths:"); + logger.debug("\t================================"); + logger.debug("\tCol Widths:"); for (int i = 0; i < colWidths.length; i++) { - logger.info("\t[{}] : {}", i, this.colWidths[i]); + logger.debug("\t[{}] : {}", i, this.colWidths[i]); } - logger.info("====================================================================="); + logger.debug("====================================================================="); } public Table getOrigTable() { diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PdfBoxStamper.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PdfBoxStamper.java index 762f22e9..374c7fea 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PdfBoxStamper.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/pdfbox/PdfBoxStamper.java @@ -31,8 +31,7 @@ public class PdfBoxStamper implements IPDFStamper { } public void setSettings(ISettings settings) { - // TODO Auto-generated method stub - + // not needed currently } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java index 0796078f..75eee27f 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java @@ -36,39 +36,53 @@ import at.gv.egiz.pdfas.lib.impl.configuration.PlaceholderConfiguration; import at.gv.egiz.pdfas.lib.impl.configuration.SignatureProfileConfiguration; public class OperationStatus implements Serializable { - + /** * */ private static final long serialVersionUID = -2985007198666388528L; - - + private SignParameter signParamter; private PDFObject pdfObject = new PDFObject(this); - + private ISettings configuration; private PlaceholderConfiguration placeholderConfiguration = null; private GlobalConfiguration gloablConfiguration = null; - private Map<String, SignatureProfileConfiguration> signatureProfiles = - new HashMap<String, SignatureProfileConfiguration>(); + private Map<String, SignatureProfileConfiguration> signatureProfiles = new HashMap<String, SignatureProfileConfiguration>(); private TempFileHelper helper; private RequestedSignature requestedSignature; private Calendar signingDate; - + public OperationStatus(ISettings configuration, SignParameter signParameter) { this.configuration = configuration; this.signParamter = signParameter; helper = new TempFileHelper(configuration); } - + @Override protected void finalize() throws Throwable { + if (this.helper != null) { + try { + this.helper.clear(); + } catch (Throwable e) { + } + } super.finalize(); } - - - + // ======================================================================== + + public void clear() { + if (this.helper != null) { + try { + this.helper.clear(); + } catch (Throwable e) { + } + } + if(pdfObject != null) { + pdfObject.close(); + } + } public RequestedSignature getRequestedSignature() { return requestedSignature; @@ -79,34 +93,37 @@ public class OperationStatus implements Serializable { } public PlaceholderConfiguration getPlaceholderConfiguration() { - if(this.placeholderConfiguration == null) { - this.placeholderConfiguration = - new PlaceholderConfiguration(this.configuration); + if (this.placeholderConfiguration == null) { + this.placeholderConfiguration = new PlaceholderConfiguration( + this.configuration); } return this.placeholderConfiguration; } - + public GlobalConfiguration getGlobalConfiguration() { - if(this.gloablConfiguration == null) { - this.gloablConfiguration = - new GlobalConfiguration(this.configuration); + if (this.gloablConfiguration == null) { + this.gloablConfiguration = new GlobalConfiguration( + this.configuration); } return this.gloablConfiguration; } - - public SignatureProfileConfiguration getSignatureProfileConfiguration(String profileID) { - - SignatureProfileConfiguration signatureProfileConfiguration = signatureProfiles.get(profileID); - if(signatureProfileConfiguration == null) { - signatureProfileConfiguration = new SignatureProfileConfiguration(this.configuration, profileID); + + public SignatureProfileConfiguration getSignatureProfileConfiguration( + String profileID) { + + SignatureProfileConfiguration signatureProfileConfiguration = signatureProfiles + .get(profileID); + if (signatureProfileConfiguration == null) { + signatureProfileConfiguration = new SignatureProfileConfiguration( + this.configuration, profileID); signatureProfiles.put(profileID, signatureProfileConfiguration); } - + return signatureProfileConfiguration; } - + // ======================================================================== - + public PDFObject getPdfObject() { return pdfObject; } @@ -122,11 +139,11 @@ public class OperationStatus implements Serializable { public void setSignParamter(SignParameter signParamter) { this.signParamter = signParamter; } - + public TempFileHelper getTempFileHelper() { return this.helper; } - + public ISettings getSettings() { return this.configuration; } @@ -138,6 +155,5 @@ public class OperationStatus implements Serializable { public void setSigningDate(Calendar signingDate) { this.signingDate = signingDate; } - - + } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/SignatureCheckImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/SignatureCheckImpl.java index 2ce74e6a..bfb8ccdc 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/SignatureCheckImpl.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/SignatureCheckImpl.java @@ -43,4 +43,8 @@ public class SignatureCheckImpl implements SignatureCheck { return message; } + public void setMessage(String message) { + this.message = message; + } + } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java index 4fb883a3..0c37e637 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java @@ -23,6 +23,7 @@ ******************************************************************************/ package at.gv.egiz.pdfas.lib.impl.verify; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -44,20 +45,61 @@ public class VerifierDispatcher { "at.gv.egiz.pdfas.sigs.pkcs7detached.PKCS7DetachedVerifier", "at.gv.egiz.pdfas.sigs.pades.PAdESVerifier" }; + public static final String CONF_VERIFIER_LIST = "verifier.classes"; + public static final String CONF_VERIFIER_SEP = ";"; + public static final String CONF_VERIFIER = "default.verifier"; public Map<String, HashMap<String, IVerifyFilter>> filterMap = new HashMap<String, HashMap<String, IVerifyFilter>>(); + private String[] getClasses(ISettings settings) { + String confVerifiers = settings.getValue(CONF_VERIFIER_LIST); + String[] classes; + if (confVerifiers != null) { + classes = confVerifiers.split(CONF_VERIFIER_SEP); + } else { + classes = defaultClasses; + } + + List<String> filteredClasses = new ArrayList<String>(); + + for (int i = 0; i < classes.length; i++) { + String clsName = classes[i]; + try { + Class<?> cls = Class.forName(clsName); + filteredClasses.add(clsName); + } catch (Throwable e) { + logger.error("Cannot find Verifier class: " + clsName, e); + } + } + + String[] clsNames = new String[filteredClasses.size()]; + for (int i = 0; i < filteredClasses.size(); i++) { + clsNames[i] = filteredClasses.get(i); + } + + dumpVerifierClasses(clsNames); + + return clsNames; + } + + private void dumpVerifierClasses(String[] clsNames) { + for (int i = 0; i < clsNames.length; i++) { + String clsName = clsNames[i]; + logger.debug("Registering Signature Verifier: " + clsName); + } + } + public VerifierDispatcher(ISettings settings) { // TODO: add configuration parameter to set verifier - Map<String, String> verifierClasses = settings - .getValuesPrefix(CONF_VERIFIER); + //Map<String, String> verifierClasses = settings + // .getValuesPrefix(CONF_VERIFIER); String[] currentClasses = null; - if (verifierClasses == null || verifierClasses.isEmpty()) { - logger.info("No verifier configured using default"); - currentClasses = defaultClasses; - } else { + //if (verifierClasses == null || verifierClasses.isEmpty()) { + logger.info("Getting Verifier classes"); + currentClasses = getClasses(settings); + /*} else { currentClasses = new String[verifierClasses.values().size()]; Iterator<String> classIt = verifierClasses.values().iterator(); int j = 0; @@ -65,7 +107,7 @@ public class VerifierDispatcher { currentClasses[j] = classIt.next(); j++; } - } + }*/ try { for (int i = 0; i < currentClasses.length; i++) { String clsName = currentClasses[i]; diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/MOAConnector.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/MOAConnector.java index 71e7181a..9c5c720a 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/MOAConnector.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/MOAConnector.java @@ -55,6 +55,8 @@ import org.xml.sax.SAXException; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.PdfAsMOAException; +import at.gv.egiz.pdfas.common.exceptions.PdfAsWrappedIOException; +import at.gv.egiz.pdfas.common.settings.ISettings; import at.gv.egiz.pdfas.lib.api.Configuration; public class MOAConnector implements ISignatureConnector { @@ -95,9 +97,30 @@ public class MOAConnector implements ISignatureConnector { public MOAConnector(Configuration config) throws CertificateException, FileNotFoundException, IOException { - logger.info("Loading certificate: " + config.getValue(MOA_SIGN_CERTIFICATE)); - this.certificate = new X509Certificate(new FileInputStream(new File( - config.getValue(MOA_SIGN_CERTIFICATE)))); + if(config.getValue(MOA_SIGN_CERTIFICATE) == null) { + logger.error(MOA_SIGN_CERTIFICATE + " not configured for MOA connector"); + throw new PdfAsWrappedIOException(new PdfAsException("Please configure: " + MOA_SIGN_CERTIFICATE + " to use MOA connector")); + } + + if(!(config instanceof ISettings)) { + logger.error("Configuration is no instance of ISettings"); + throw new PdfAsWrappedIOException(new PdfAsException("Configuration is no instance of ISettings")); + } + + ISettings settings = (ISettings)config; + + String certificateValue = config.getValue(MOA_SIGN_CERTIFICATE); + + File certFile = new File(certificateValue); + if(!certFile.isAbsolute()) { + certificateValue = settings.getWorkingDirectory() + "/" + + config.getValue(MOA_SIGN_CERTIFICATE); + certFile = new File(certificateValue); + } + + logger.info("Loading certificate: " + certificateValue); + + this.certificate = new X509Certificate(new FileInputStream(certFile)); this.moaEndpoint = config.getValue(MOA_SIGN_URL); this.keyIdentifier = config.getValue(MOA_SIGN_KEY_ID); } diff --git a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java index 9d411d1e..2eb3b341 100644 --- a/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java +++ b/pdf-as-lib/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TablePos.java @@ -272,6 +272,7 @@ public class TablePos implements Serializable } case 'r': { float flval=Float.parseFloat(commandval); + // TODO: check rotation to be only multiples of 90 degrees if (flval<0) { throw new PdfAsException("Pos string (=" + pos_string + ") is invalid."); |