diff options
-rw-r--r-- | build.gradle | 2 | ||||
-rw-r--r-- | doc/PDFAS4_Dokumentation.docx | bin | 124317 -> 124326 bytes | |||
-rwxr-xr-x | doc/PDFAS4_Dokumentation.pdf | bin | 134396 -> 543664 bytes | |||
-rw-r--r-- | pdf-as-lib/src/configuration/cfg/advancedconfig.properties | 2 | ||||
-rw-r--r-- | pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java | 5 | ||||
-rw-r--r-- | pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java | 7 | ||||
-rw-r--r-- | pdf-as-lib/src/main/resources/config/config.zip | bin | 1276512 -> 1276508 bytes | |||
-rw-r--r-- | pdf-as-lib/src/main/resources/icm/sRGB Color Space Profile.icm | bin | 3144 -> 0 bytes | |||
-rw-r--r-- | pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java | 483 | ||||
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java | 7 | ||||
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java | 4 | ||||
-rw-r--r-- | pdf-as-web/src/main/webapp/index.jsp | 2 |
12 files changed, 279 insertions, 233 deletions
diff --git a/build.gradle b/build.gradle index 9c403ef2..06a24765 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ task wrapper(type: Wrapper) { allprojects { apply plugin: 'com.github.ben-manes.versions' repositories { mavenCentral() } - version = '4.1.1' + version = '4.1.2-SNAPSHOT' } configurations { diff --git a/doc/PDFAS4_Dokumentation.docx b/doc/PDFAS4_Dokumentation.docx Binary files differindex ad82ff57..5a1eb872 100644 --- a/doc/PDFAS4_Dokumentation.docx +++ b/doc/PDFAS4_Dokumentation.docx diff --git a/doc/PDFAS4_Dokumentation.pdf b/doc/PDFAS4_Dokumentation.pdf Binary files differindex 5b470b6d..510102d3 100755 --- a/doc/PDFAS4_Dokumentation.pdf +++ b/doc/PDFAS4_Dokumentation.pdf diff --git a/pdf-as-lib/src/configuration/cfg/advancedconfig.properties b/pdf-as-lib/src/configuration/cfg/advancedconfig.properties index b128d978..5fd8b5cb 100644 --- a/pdf-as-lib/src/configuration/cfg/advancedconfig.properties +++ b/pdf-as-lib/src/configuration/cfg/advancedconfig.properties @@ -105,6 +105,6 @@ default.verifier.01=at.gv.egiz.pdfas.sigs.pades.PAdESVerifier #Enable background color detection
#sigblock.placement.bgcolor.detection.enabled=true
-#sigblock.placement.debug.file=/home/cmaierhofer/temp/debugImg.png
+#sigblock.placement.debug.file=/home/user/temp/debugImg.png
#runtime.backend=PDFBOX_2_BACKEND
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java index 364acb44..f8f71f2f 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java @@ -52,6 +52,9 @@ public interface IConfigurationConstants { public static final String DEFAULT_SIGNATURE_PROFILE = SIG_OBJECT + SEPERATOR + TYPE + SEPERATOR + DEFAULT; public static final String CONFIG_BKU_URL = "bku.sign.url"; + + /*Protect PDF content*/ + public static final String DEFAULT_CONFIG_PROTECT_PDF=DEFAULT+SEPERATOR+"protectPDF"; /** * MOA SS Signing Key Identifier @@ -106,6 +109,8 @@ public interface IConfigurationConstants { public static final String SIG_PLACEMENT_DEBUG_OUTPUT = "sigblock.placement.debug.file"; + + /** * PADES Constants */ diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java index f2864a07..d04f6878 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/configuration/GlobalConfiguration.java @@ -39,5 +39,12 @@ public class GlobalConfiguration extends SpecificBaseConfiguration } return null; } + + public String getDefaultProtection() { + if(this.configuration.hasValue(DEFAULT_CONFIG_PROTECT_PDF)) { + return this.configuration.getValue(DEFAULT_CONFIG_PROTECT_PDF); + } + return null; + } } diff --git a/pdf-as-lib/src/main/resources/config/config.zip b/pdf-as-lib/src/main/resources/config/config.zip Binary files differindex fc0a409d..57e7df54 100644 --- a/pdf-as-lib/src/main/resources/config/config.zip +++ b/pdf-as-lib/src/main/resources/config/config.zip diff --git a/pdf-as-lib/src/main/resources/icm/sRGB Color Space Profile.icm b/pdf-as-lib/src/main/resources/icm/sRGB Color Space Profile.icm Binary files differdeleted file mode 100644 index 7f9d18d0..00000000 --- a/pdf-as-lib/src/main/resources/icm/sRGB Color Space Profile.icm +++ /dev/null diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java index df201f3e..090986a5 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/signing/pdfbox2/PADESPDFBOXSigner.java @@ -3,19 +3,19 @@ * PDF-AS has been contracted by the E-Government Innovation Center EGIZ, a * joint initiative of the Federal Chancellery Austria and Graz University of * Technology. - * + * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. - * + * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works @@ -54,6 +54,9 @@ import org.apache.pdfbox.pdmodel.common.PDNumberTreeNode; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureElement; import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureTreeRoot; +import org.apache.pdfbox.pdmodel.encryption.AccessPermission; +import org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy; +import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent; import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; @@ -186,14 +189,15 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { SignatureProfileSettings signatureProfileSettings = TableFactory .createProfile(requestedSignature.getSignatureProfileID(), pdfObject.getStatus().getSettings()); - /* - * Check if input document is PDF-A conform - * - if (signatureProfileSettings.isPDFA()) { - // TODO: run preflight parser - runPDFAPreflight(pdfObject.getOriginalDocument()); - } - */ + + //Check if input document is PDF-A conform + if (signatureProfileSettings.isPDFA()) { + DataSource origDoc = pdfObject.getOriginalDocument(); + InputStream stream = origDoc.getInputStream(); + //Run PreflightParser for checking conformity// + //runPDFAPreflight(origDoc); + } + ValueResolver resolver = new ValueResolver(requestedSignature, pdfObject.getStatus()); String signerName = resolver.resolve("SIG_SUBJECT", signatureProfileSettings.getValue("SIG_SUBJECT"), @@ -343,7 +347,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { // replace placeholder URL fileUrl = PADESPDFBOXSigner.class.getResource("/placeholder/empty.jpg"); - + PDImageXObject img = PDImageXObject.createFromFile(fileUrl.getPath(), doc); img.getCOSObject().setNeedToBeUpdated(true); @@ -365,43 +369,43 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { } if (signatureProfileSettings.isPDFA() || signatureProfileSettings.isPDFA3()) { - PDDocumentCatalog root = doc.getDocumentCatalog(); - COSBase base = root.getCOSObject().getItem(COSName.OUTPUT_INTENTS); - if (base == null) { - InputStream colorProfile = null; - try { - colorProfile = PDDocumentCatalog.class - .getResourceAsStream("/icm/sRGB Color Space Profile.icm"); - - try { - PDOutputIntent oi = new PDOutputIntent(doc, colorProfile); - oi.setInfo("sRGB IEC61966-2.1"); - oi.setOutputCondition("sRGB IEC61966-2.1"); - oi.setOutputConditionIdentifier("sRGB IEC61966-2.1"); - oi.setRegistryName("http://www.color.org"); - - root.addOutputIntent(oi); - root.getCOSObject().setNeedToBeUpdated(true); - logger.info("added Output Intent"); - } catch (Throwable e) { - e.printStackTrace(); - throw new PdfAsException("Failed to add Output Intent", e); - } - } finally { - IOUtils.closeQuietly(colorProfile); - } - } - } - - options.setPage(positioningInstruction.getPage()); - - options.setVisualSignature(properties.getVisibleSignature()); - } + PDDocumentCatalog root = doc.getDocumentCatalog(); + COSBase base = root.getCOSObject().getItem(COSName.OUTPUT_INTENTS); + + InputStream colorProfile = null; + colorProfile = this.getClass().getResourceAsStream("/icm/sRGB.icm"); + //Set output intents for PDF/A conformity// + try { + PDOutputIntent intent = new PDOutputIntent(doc, colorProfile); + + intent.setInfo("sRGB IEC61966-2.1"); + intent.setOutputCondition("sRGB IEC61966-2.1"); + intent.setOutputConditionIdentifier("sRGB IEC61966-2.1"); + intent.setRegistryName("http://www.color.org"); + List<PDOutputIntent> oi = new ArrayList<PDOutputIntent>(); + oi.add(intent); + root.setOutputIntents(oi); + root.getCOSObject().setNeedToBeUpdated(true); + + logger.info("added Output Intent"); + } catch (Throwable e) { + e.printStackTrace(); + throw new PdfAsException("Failed to add Output Intent", e); + } + finally { + IOUtils.closeQuietly(colorProfile); + } + } + options.setPage(positioningInstruction.getPage()); + options.setVisualSignature(properties.getVisibleSignature()); + } visualSignatureDocumentGuard = options.getVisualSignature(); doc.addSignature(signature, signer, options); + + String sigFieldName = signatureProfileSettings.getSignFieldValue(); if (sigFieldName == null) { @@ -595,247 +599,272 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { } } - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - - synchronized (doc) { - doc.saveIncremental(bos); - byte[] outputDocument = bos.toByteArray(); + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + /*/ Check if document should be protected*/ + + synchronized (doc) { + doc.saveIncremental(bos); + byte[] outputDocument = bos.toByteArray(); + doc.save(bos); + pdfObject.setSignedDocument(outputDocument); + - /* + } + /* Check if resulting pdf is PDF-A conform */ - //if (signatureProfileSettings.isPDFA()) { - // // TODO: run preflight parser - // runPDFAPreflight(outputDocument); - //} + if (signatureProfileSettings.isPDFA()) { + runPDFAPreflight(new ByteArrayDataSource(pdfObject.getSignedDocument())); + } - pdfObject.setSignedDocument(outputDocument); - } - - } finally { - if (options != null) { - if (options.getVisualSignature() != null) { - options.getVisualSignature().close(); - } - } - } + /*Check if doc has to be protected*/ + /* if (requestedSignature.getStatus().getSettings().hasValue(DEFAULT_CONFIG_PROTECT_PDF)) { + if (IConfigurationConstants.TRUE.equalsIgnoreCase(requestedSignature.getStatus().getSettings().getValue(IConfigurationConstants.DEFAULT_CONFIG_PROTECT_PDF))) + { //Protect document before setting output + //Policies for docs + AccessPermission ap = doc.getCurrentAccessPermission(); + ap.setReadOnly(); + ap.setCanModify(false); + ap.setCanExtractForAccessibility(false); + doc = new PDDocument(doc.getDocument(),null,ap); + logger.info("Added Protection Parameters"); + } + } +*/ - System.gc(); - } catch (IOException e) { - logger.warn(MessageResolver.resolveMessage("error.pdf.sig.01"), e); - throw new PdfAsException("error.pdf.sig.01", e); - } finally { - if (doc != null) { - try { - doc.close(); - } catch (IOException e) { - logger.debug("Failed to close COS Doc!", e); - // Ignore - } - } + + } catch (IOException e1) { + e1.printStackTrace(); + } + + finally { + if (options != null) { + if (options.getVisualSignature() != null) { + options.getVisualSignature().close(); + } + } + } + + System.gc(); + } catch (IOException e) { + logger.warn(MessageResolver.resolveMessage("error.pdf.sig.01"), e); + throw new PdfAsException("error.pdf.sig.01", e); + } finally { + if (doc != null) { + try { + doc.close(); + } catch (IOException e) { + logger.debug("Failed to close COS Doc!", e); + // Ignore + } + } logger.debug("Signature done!"); } } - private void runPDFAPreflight(final byte[] signedDocument) throws PdfAsException { - runPDFAPreflight(new ByteArrayDataSource(signedDocument)); - } - - private void runPDFAPreflight(final DataSource signedDocument) throws PdfAsException { - PreflightDocument document = null; - ValidationResult result = null; - try { - PreflightParser parser = new PreflightParser(signedDocument); - parser.parse(Format.PDF_A1B); - parser.parse(); - document = parser.getPreflightDocument(); - document.validate(); + /** + * Check via PreFlightParser if PDF-Document is a valid PDFA1 + * @param signedDocument: signed Document + * @throws PdfAsException + */ + private void runPDFAPreflight(final DataSource signedDocument) throws PdfAsException { + PreflightDocument document = null; + ValidationResult result = null; + try { + PreflightParser parser = new PreflightParser(signedDocument); + // + // parser.parse(Format.PDF_A1B); + parser.parse(); + document = parser.getPreflightDocument(); + document.validate(); + + document.close(); + result = document.getResult(); + logger.info("PDF-A Validation Result: " + result.isValid()); + + if (result.getErrorsList().size() > 0) { + logger.error("The following validation errors occured for PDF-A validation"); + } - document.close(); - result = document.getResult(); + for (ValidationResult.ValidationError ve : result.getErrorsList()) { + logger.error("\t" + ve.getErrorCode() + ": " + ve.getDetails()); + } - if(result.getErrorsList().size() > 0) { - logger.error("The following validation errors occured for PDF-A validation"); - } + if (!result.isValid()) { + logger.info("The file is not a valid PDF-A document"); + } - for (ValidationResult.ValidationError ve : result.getErrorsList()) - { - logger.error("\t" + ve.getErrorCode() + ": " + ve.getDetails()); - } + } catch (SyntaxValidationException e) { + logger.error("The file is syntactically invalid.", e); + throw new PdfAsException("Resulting PDF Document is syntactically invalid."); + } catch (ValidationException e) { + logger.error("The file is not a valid PDF-A document.", e); + } catch (IOException e) { + logger.error("An IOException (" + e.getMessage() + + ") occurred, while validating the PDF-A conformance", e); + throw new PdfAsException("Failed validating PDF Document IOException."); + } catch (RuntimeException e) { + logger.debug("An RuntimeException (" + e.getMessage() + + ") occurred, while validating the PDF-A conformance", e); + throw new PdfAsException("Failed validating PDF Document RuntimeException."); + } finally { + if (document != null) { + IOUtils.closeQuietly((Closeable) document); + } + } + } - if(!result.isValid()) { - throw new PdfAsException("The file is not a valid PDF-A document"); - } + @Override + public PDFObject buildPDFObject(OperationStatus operationStatus) { + return new PDFBOXObject(operationStatus); + } - } catch (SyntaxValidationException e) { - logger.error("The file is syntactically invalid.", e); - throw new PdfAsException("Resulting PDF Document is syntactically invalid."); - } catch (ValidationException e) { - logger.error("The file is not a valid PDF-A document.", e); - throw new PdfAsException("The file is not a valid PDF-A document"); - } catch (IOException e) { - logger.error("An IOException (" + e.getMessage() - + ") occurred, while validating the PDF-A conformance", e); - throw new PdfAsException("Failed validating PDF Document IOException."); - } catch (RuntimeException e) { - logger.debug("An RuntimeException (" + e.getMessage() - + ") occurred, while validating the PDF-A conformance", e); - throw new PdfAsException("Failed validating PDF Document RuntimeException."); - } finally { - if (document != null) { - IOUtils.closeQuietly((Closeable)document); - } - } - } + @Override + public PDFASSignatureInterface buildSignaturInterface(IPlainSigner signer, SignParameter parameters, + RequestedSignature requestedSignature) { + return new PdfboxSignerWrapper(signer, parameters, requestedSignature); + } - @Override - public PDFObject buildPDFObject(OperationStatus operationStatus) { - return new PDFBOXObject(operationStatus); - } + @Override + public PDFASSignatureExtractor buildBlindSignaturInterface(X509Certificate certificate, String filter, + String subfilter, Calendar date) { + return new SignatureDataExtractor(certificate, filter, subfilter, date); + } - @Override - public PDFASSignatureInterface buildSignaturInterface(IPlainSigner signer, SignParameter parameters, - RequestedSignature requestedSignature) { - return new PdfboxSignerWrapper(signer, parameters, requestedSignature); - } + @Override + public void checkPDFPermissions(PDFObject genericPdfObject) throws PdfAsException { + if (!(genericPdfObject instanceof PDFBOXObject)) { + // tODO: + throw new PdfAsException(); + } - @Override - public PDFASSignatureExtractor buildBlindSignaturInterface(X509Certificate certificate, String filter, - String subfilter, Calendar date) { - return new SignatureDataExtractor(certificate, filter, subfilter, date); - } + PDFBOXObject pdfObject = (PDFBOXObject) genericPdfObject; + PdfBoxUtils.checkPDFPermissions(pdfObject.getDocument()); + } - @Override - public void checkPDFPermissions(PDFObject genericPdfObject) throws PdfAsException { - if (!(genericPdfObject instanceof PDFBOXObject)) { - // tODO: - throw new PdfAsException(); - } + @Override + public byte[] rewritePlainSignature(byte[] plainSignature) { + String signature = new COSString(plainSignature).toHexString(); + byte[] pdfSignature = signature.getBytes(); + return pdfSignature; + } - PDFBOXObject pdfObject = (PDFBOXObject) genericPdfObject; - PdfBoxUtils.checkPDFPermissions(pdfObject.getDocument()); - } + @Override + public Image generateVisibleSignaturePreview(SignParameter parameter, java.security.cert.X509Certificate cert, + int resolution, OperationStatus status, RequestedSignature requestedSignature) throws PDFASError { + try { + PDFBOXObject pdfObject = (PDFBOXObject) status.getPdfObject(); - @Override - public byte[] rewritePlainSignature(byte[] plainSignature) { - String signature = new COSString(plainSignature).toHexString(); - byte[] pdfSignature = signature.getBytes(); - return pdfSignature; - } + PDDocument origDoc = new PDDocument(); - @Override - public Image generateVisibleSignaturePreview(SignParameter parameter, java.security.cert.X509Certificate cert, - int resolution, OperationStatus status, RequestedSignature requestedSignature) throws PDFASError { - try { - PDFBOXObject pdfObject = (PDFBOXObject) status.getPdfObject(); - PDDocument origDoc = new PDDocument(); - origDoc.addPage(new PDPage(PDRectangle.A4)); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - origDoc.save(baos); - baos.close(); + origDoc.addPage(new PDPage(PDRectangle.A4)); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + origDoc.save(baos); + baos.close(); - pdfObject.setOriginalDocument(new ByteArrayDataSource(baos.toByteArray())); + pdfObject.setOriginalDocument(new ByteArrayDataSource(baos.toByteArray())); - SignatureProfileSettings signatureProfileSettings = TableFactory - .createProfile(requestedSignature.getSignatureProfileID(), pdfObject.getStatus().getSettings()); + SignatureProfileSettings signatureProfileSettings = TableFactory + .createProfile(requestedSignature.getSignatureProfileID(), pdfObject.getStatus().getSettings()); - // create Table describtion - Table main = TableFactory.createSigTable(signatureProfileSettings, MAIN, pdfObject.getStatus(), - requestedSignature); + // create Table describtion + Table main = TableFactory.createSigTable(signatureProfileSettings, MAIN, pdfObject.getStatus(), + requestedSignature); - IPDFStamper stamper = StamperFactory.createDefaultStamper(pdfObject.getStatus().getSettings() ); + IPDFStamper stamper = StamperFactory.createDefaultStamper(pdfObject.getStatus().getSettings()); - IPDFVisualObject visualObject = stamper.createVisualPDFObject(pdfObject, main); + IPDFVisualObject visualObject = stamper.createVisualPDFObject(pdfObject, main); - SignatureProfileConfiguration signatureProfileConfiguration = pdfObject.getStatus() - .getSignatureProfileConfiguration(requestedSignature.getSignatureProfileID()); + SignatureProfileConfiguration signatureProfileConfiguration = pdfObject.getStatus() + .getSignatureProfileConfiguration(requestedSignature.getSignatureProfileID()); - String signaturePosString = signatureProfileConfiguration.getDefaultPositioning(); - PositioningInstruction positioningInstruction = null; - if (signaturePosString != null) { - positioningInstruction = Positioning.determineTablePositioning(new TablePos(signaturePosString), "", - origDoc, visualObject, pdfObject.getStatus().getSettings()); - } else { - positioningInstruction = Positioning.determineTablePositioning(new TablePos(), "", origDoc, - visualObject, pdfObject.getStatus().getSettings()); - } + String signaturePosString = signatureProfileConfiguration.getDefaultPositioning(); + PositioningInstruction positioningInstruction = null; + if (signaturePosString != null) { + positioningInstruction = Positioning.determineTablePositioning(new TablePos(signaturePosString), "", + origDoc, visualObject, pdfObject.getStatus().getSettings()); + } else { + positioningInstruction = Positioning.determineTablePositioning(new TablePos(), "", origDoc, + visualObject, pdfObject.getStatus().getSettings()); + } - origDoc.close(); + origDoc.close(); - SignaturePositionImpl position = new SignaturePositionImpl(); - position.setX(positioningInstruction.getX()); - position.setY(positioningInstruction.getY()); - position.setPage(positioningInstruction.getPage()); - position.setHeight(visualObject.getHeight()); - position.setWidth(visualObject.getWidth()); + SignaturePositionImpl position = new SignaturePositionImpl(); + position.setX(positioningInstruction.getX()); + position.setY(positioningInstruction.getY()); + position.setPage(positioningInstruction.getPage()); + position.setHeight(visualObject.getHeight()); + position.setWidth(visualObject.getWidth()); - requestedSignature.setSignaturePosition(position); + requestedSignature.setSignaturePosition(position); - PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties( - pdfObject.getStatus().getSettings(), pdfObject, (PdfBoxVisualObject) visualObject, - positioningInstruction, signatureProfileSettings); + PDFAsVisualSignatureProperties properties = new PDFAsVisualSignatureProperties( + pdfObject.getStatus().getSettings(), pdfObject, (PdfBoxVisualObject) visualObject, + positioningInstruction, signatureProfileSettings); - properties.buildSignature(); - PDDocument visualDoc; - synchronized (PDDocument.class) { - visualDoc = PDDocument.load(properties.getVisibleSignature()); - } - // PDPageable pageable = new PDPageable(visualDoc); + properties.buildSignature(); + PDDocument visualDoc; + synchronized (PDDocument.class) { + visualDoc = PDDocument.load(properties.getVisibleSignature()); + } + // PDPageable pageable = new PDPageable(visualDoc); - PDPage firstPage = visualDoc.getDocumentCatalog().getPages().get(0); + PDPage firstPage = visualDoc.getDocumentCatalog().getPages().get(0); - float stdRes = 72; - float targetRes = resolution; - float factor = targetRes / stdRes; + float stdRes = 72; + float targetRes = resolution; + float factor = targetRes / stdRes; - int targetPageNumber = 0;//TODO: is this always the case - PDFRenderer pdfRenderer = new PDFRenderer(visualDoc); - BufferedImage outputImage = pdfRenderer.renderImageWithDPI(targetPageNumber, targetRes, ImageType.ARGB); + int targetPageNumber = 0;//TODO: is this always the case + PDFRenderer pdfRenderer = new PDFRenderer(visualDoc); + BufferedImage outputImage = pdfRenderer.renderImageWithDPI(targetPageNumber, targetRes, ImageType.ARGB); - //BufferedImage outputImage = firstPage.convertToImage(BufferedImage.TYPE_4BYTE_ABGR, (int) targetRes); + //BufferedImage outputImage = firstPage.convertToImage(BufferedImage.TYPE_4BYTE_ABGR, (int) targetRes); - BufferedImage cutOut = new BufferedImage((int) (position.getWidth() * factor), - (int) (position.getHeight() * factor), BufferedImage.TYPE_4BYTE_ABGR); + BufferedImage cutOut = new BufferedImage((int) (position.getWidth() * factor), + (int) (position.getHeight() * factor), BufferedImage.TYPE_4BYTE_ABGR); - Graphics2D graphics = (Graphics2D) cutOut.getGraphics(); + Graphics2D graphics = (Graphics2D) cutOut.getGraphics(); - graphics.drawImage(outputImage, 0, 0, cutOut.getWidth(), cutOut.getHeight(), (int) (1 * factor), - (int) (outputImage.getHeight() - ((position.getHeight() + 1) * factor)), - (int) ((1 + position.getWidth()) * factor), (int) (outputImage.getHeight() - - ((position.getHeight() + 1) * factor) + (position.getHeight() * factor)), - null); - return cutOut; - } catch (PdfAsException e) { - logger.warn("PDF-AS Exception", e); - throw ErrorExtractor.searchPdfAsError(e, status); - } catch (Throwable e) { - logger.warn("Unexpected Throwable Exception", e); - throw ErrorExtractor.searchPdfAsError(e, status); - } - } + graphics.drawImage(outputImage, 0, 0, cutOut.getWidth(), cutOut.getHeight(), (int) (1 * factor), + (int) (outputImage.getHeight() - ((position.getHeight() + 1) * factor)), + (int) ((1 + position.getWidth()) * factor), (int) (outputImage.getHeight() + - ((position.getHeight() + 1) * factor) + (position.getHeight() * factor)), + null); + return cutOut; + } catch (PdfAsException e) { + logger.warn("PDF-AS Exception", e); + throw ErrorExtractor.searchPdfAsError(e, status); + } catch (Throwable e) { + logger.warn("Unexpected Throwable Exception", e); + throw ErrorExtractor.searchPdfAsError(e, status); + } + } - private String getPDFAVersion(PDDocument doc) { + private String getPDFAVersion(PDDocument doc) { try { PDDocumentCatalog cat = doc.getDocumentCatalog(); PDMetadata metadata = cat.getMetadata(); - if(metadata != null) { + if (metadata != null) { DomXmpParser xmpParser = new DomXmpParser(); XMPMetadata xmpMetadata = xmpParser.parse(metadata.exportXMPMetadata()); - if(xmpMetadata != null) { + if (xmpMetadata != null) { PDFAIdentificationSchema pdfaIdentificationSchema = xmpMetadata.getPDFIdentificationSchema(); if (pdfaIdentificationSchema != null) { Integer pdfaversion = pdfaIdentificationSchema.getPart(); String conformance = pdfaIdentificationSchema.getConformance(); logger.info("Detected PDF/A Version: {} - {}", pdfaversion, conformance); - if(pdfaversion != null) { + if (pdfaversion != null) { return String.valueOf(pdfaversion); } } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java index b986d175..4ec8021d 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ExternSignServlet.java @@ -363,7 +363,12 @@ public class ExternSignServlet extends HttpServlet { throw new PdfAsWebException("Invalid connector mobilebku is not supported"); } } - + if(connector.equals("onlinebku")) { + if(WebConfiguration.getOnlineBKUURL() == null) { + throw new PdfAsWebException("Invalid connector bku is not supported"); + } + } + PdfAsHelper.setStatisticEvent(request, response, statisticEvent); PdfAsHelper.startSignature(request, response, getServletContext(), pdfData, connector, diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java index 89cb3039..e8ac3658 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/UIEntryPointServlet.java @@ -142,14 +142,14 @@ public class UIEntryPointServlet extends HttpServlet { } if (connector.equals(Connector.ONLINEBKU)) { - if (WebConfiguration.getLocalBKUURL() == null) { + if (WebConfiguration.getOnlineBKUURL() == null) { throw new PdfAsWebException( "Invalid connector onlinebku is not supported"); } } if (connector.equals(Connector.MOBILEBKU)) { - if (WebConfiguration.getLocalBKUURL() == null) { + if (WebConfiguration.getHandyBKUURL() == null) { throw new PdfAsWebException( "Invalid connector mobilebku is not supported"); } diff --git a/pdf-as-web/src/main/webapp/index.jsp b/pdf-as-web/src/main/webapp/index.jsp index ae3ef88d..bc20936e 100644 --- a/pdf-as-web/src/main/webapp/index.jsp +++ b/pdf-as-web/src/main/webapp/index.jsp @@ -21,7 +21,7 @@ <% if (WebConfiguration.getLocalBKUURL() != null) { %> - <img src="assets/img/onlineBKU.png" /> <button type="submit" + <img src="assets/img/localBKU.png" /> <button type="submit" value="bku" name="connector" id="bku">Lokale BKU </button> <% |