From e49eb5e433767386a09732f5942b6425098b511b Mon Sep 17 00:00:00 2001 From: emusic Date: Wed, 21 Mar 2018 13:06:24 +0100 Subject: changes regarding protection, bug fix, thread safe --- .../src/main/java/at/gv/egiz/pdfas/cli/Main.java | 8 +- .../configuration/cfg/advancedconfig.properties | 1 + .../pdfas/lib/api/IConfigurationConstants.java | 10 +- .../impl/configuration/GlobalConfiguration.java | 22 --- .../lib/impl/placeholder/PlaceholderFilter.java | 1 + .../java/at/gv/egiz/sl/util/SLMarschaller.java | 78 +++++---- pdf-as-lib/src/main/resources/config/config.zip | Bin 1276508 -> 1276636 bytes .../lib/impl/pdfbox2/positioning/Positioning.java | 5 + .../impl/signing/pdfbox2/PADESPDFBOXSigner.java | 174 ++++++--------------- .../pdfas/web/helper/PdfAsParameterExtractor.java | 13 +- .../egiz/pdfas/web/servlets/ExternSignServlet.java | 11 ++ 11 files changed, 137 insertions(+), 186 deletions(-) diff --git a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java index f6df73d5..f3e1d2c8 100644 --- a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java +++ b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java @@ -26,6 +26,8 @@ package at.gv.egiz.pdfas.cli; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.nio.charset.StandardCharsets; +import java.security.SecureRandom; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; @@ -457,18 +459,20 @@ public class Main { if(configuration.hasValue(DEFAULT_CONFIG_PROTECT_PDF) && IConfigurationConstants.TRUE.equalsIgnoreCase(configuration.getValue(DEFAULT_CONFIG_PROTECT_PDF))) { + SecureRandom random = new SecureRandom(); + byte seed[] = random.generateSeed(50); + String ownerPassword = new String(seed, StandardCharsets.UTF_8); PDDocument document = PDDocument.load(outputPdfFile); AccessPermission accessPermission = new AccessPermission(); accessPermission.setCanExtractContent(false); accessPermission.setCanExtractForAccessibility(true); - StandardProtectionPolicy spp = new StandardProtectionPolicy("1234","",accessPermission); + StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPassword,"",accessPermission); spp.setEncryptionKeyLength(128); spp.setPermissions(accessPermission); document.protect(spp); document.save(outputPdfFile); document.close(); //accessPermission.setCanModify(false); - // accessPermission.setReadOnly(); logger.info("Added Protection Parameters"); } } diff --git a/pdf-as-lib/src/configuration/cfg/advancedconfig.properties b/pdf-as-lib/src/configuration/cfg/advancedconfig.properties index 726deba8..858b652f 100644 --- a/pdf-as-lib/src/configuration/cfg/advancedconfig.properties +++ b/pdf-as-lib/src/configuration/cfg/advancedconfig.properties @@ -110,3 +110,4 @@ default.verifier.01=at.gv.egiz.pdfas.sigs.pades.PAdESVerifier # Protect PDF files from copying and extractiong content # Set values to be true|false|unchanged +default.protectPDF = true 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 713948ba..3c560142 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 @@ -54,7 +54,7 @@ public interface IConfigurationConstants { public static final String CONFIG_BKU_URL = "bku.sign.url"; /*Protect PDF content*/ - public static final String DEFAULT_CONFIG_PROTECT_PDF=DEFAULT+SEPERATOR+"protectPDF"; + public static final String DEFAULT_CONFIG_PROTECT_PDF = DEFAULT+SEPERATOR+"protectPDF"; /** * MOA SS Signing Key Identifier @@ -114,12 +114,4 @@ public interface IConfigurationConstants { public static final String SIG_PADES_FORCE_FLAG= SIG_OBJECT + SEPERATOR+"PAdESCompatibility"; public static final String SIG_PADES_INTELL_FLAG = SIG_OBJECT + SEPERATOR+"CheckPAdESCompatibility"; - - /** - * Protect PDF file from copying content and extracting - */ - - public static final String DEFAULT_CONFIG_PROTECT_COPY_PDF = DEFAULT_CONFIG_PROTECT_PDF + SEPERATOR + "accessCopy"; - public static final String DEFAULT_CONFIG_PROTECT_EXTRACT_PDF = DEFAULT_CONFIG_PROTECT_PDF + SEPERATOR + "canModify"; - } 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 a40c336d..a677676d 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 @@ -41,26 +41,4 @@ 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; - } - - public String getDefaultCopyProtection() { - if(this.configuration.hasValue(DEFAULT_CONFIG_PROTECT_COPY_PDF)) { - return this.configuration.getValue(DEFAULT_CONFIG_PROTECT_COPY_PDF); - } - return null; - } - - public String getDefaultExtractProtection() { - if(this.configuration.hasValue(DEFAULT_CONFIG_PROTECT_EXTRACT_PDF)) { - return this.configuration.getValue(DEFAULT_CONFIG_PROTECT_EXTRACT_PDF); - } - return null; - } - - } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java index 9906fd6a..4b1a5a49 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/placeholder/PlaceholderFilter.java @@ -44,6 +44,7 @@ public class PlaceholderFilter implements IConfigurationConstants, .getPlaceholderExtractor(); String placeholderID = settings.getValue(PLACEHOLDER_ID); String placeholderModeString = settings.getValue(PLACEHOLDER_MODE); + int placeholderMode = PLACEHOLDER_MATCH_MODE_MODERATE; if (placeholderModeString != null) { try { diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java index 8e84b491..8b9991fd 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/sl/util/SLMarschaller.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 @@ -40,20 +40,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SLMarschaller { - private static Marshaller marshaller = null; - private static Unmarshaller unmarshaller = null; + + private static JAXBContext context = null; private static final Logger logger = LoggerFactory .getLogger(SLMarschaller.class); - + static { try { - JAXBContext context = JAXBContext.newInstance("at.gv.egiz.sl.schema"); - marshaller = context.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); - - unmarshaller = context.createUnmarshaller(); + context = JAXBContext.newInstance("at.gv.egiz.sl.schema"); } catch (JAXBException e) { logger.error("Error in creating JAXBContext", e); throw new RuntimeException( @@ -61,17 +56,19 @@ public class SLMarschaller { } } - public static void marshal(Object obj, OutputStream os) throws JAXBException { + public static synchronized void marshal(Object obj, OutputStream os) throws JAXBException { + Marshaller marshaller = createMarshaller(); marshaller.marshal(obj, os); } - public static String marshalToString(Object obj) throws JAXBException { + public static synchronized String marshalToString(Object obj) throws JAXBException { + Marshaller marshaller = createMarshaller(); StringWriter sw = new StringWriter(); marshaller.marshal(obj, sw); return sw.toString(); } - - public static Object unmarshal(InputStream is) throws JAXBException { + + public static synchronized Object unmarshal(InputStream is) throws JAXBException { XMLInputFactory xif = null; try { xif = XMLInputFactory.newFactory(); @@ -79,19 +76,20 @@ public class SLMarschaller { // Fallback for old STAX implementations xif = XMLInputFactory.newInstance(); } - xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); - xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); - XMLStreamReader xmlStreamReader; + xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); + xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); + XMLStreamReader xmlStreamReader; try { xmlStreamReader = xif.createXMLStreamReader(is); + Unmarshaller unmarshaller = createUnmarshaller(); return unmarshaller.unmarshal(xmlStreamReader); } catch (XMLStreamException e) { throw new JAXBException(e); } - + } - - public static Object unmarshalFromString(String message) throws JAXBException { + + public static synchronized Object unmarshalFromString(String message) throws JAXBException { StringReader sr = new StringReader(message); XMLInputFactory xif = null; try { @@ -100,15 +98,41 @@ public class SLMarschaller { // Fallback for old STAX implementations xif = XMLInputFactory.newInstance(); } - - xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); - xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); - XMLStreamReader xmlStreamReader; + + xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); + xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); + XMLStreamReader xmlStreamReader; try { xmlStreamReader = xif.createXMLStreamReader(sr); + Unmarshaller unmarshaller = createUnmarshaller(); return unmarshaller.unmarshal(xmlStreamReader); } catch (XMLStreamException e) { throw new JAXBException(e); } } -} + + private static synchronized Marshaller createMarshaller() { + try { + Marshaller marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); + return marshaller; + } + catch (JAXBException e) { + logger.error("Error in creating Marshaller", e); + throw new RuntimeException( + "There was a problem creating a Marshaller object for formatting the object to XML."); + } + } + + private static synchronized Unmarshaller createUnmarshaller() { + try { + return context.createUnmarshaller(); + } + catch (JAXBException e) { + logger.error("Error in creating Unmarshaller", e); + throw new RuntimeException( + "There was a problem creating a Unmarshaller object for formatting the object to XML."); + } + } +} \ No newline at end of file diff --git a/pdf-as-lib/src/main/resources/config/config.zip b/pdf-as-lib/src/main/resources/config/config.zip index 57e7df54..9544e91f 100644 Binary files a/pdf-as-lib/src/main/resources/config/config.zip and b/pdf-as-lib/src/main/resources/config/config.zip differ diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/positioning/Positioning.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/positioning/Positioning.java index ea35eb44..680abe6d 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/positioning/Positioning.java +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/positioning/Positioning.java @@ -177,6 +177,11 @@ public class Positioning { // + page+ // ") cannot be parsed."); } + + if (page < doc_pages) { + page = page - 1; + } + } PDPage pdPage = pdfDataSource.getPage(page-1); 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 a7b1655f..4f229874 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 @@ -23,68 +23,10 @@ ******************************************************************************/ package at.gv.egiz.pdfas.lib.impl.signing.pdfbox2; -import at.gv.egiz.pdfas.lib.api.Configuration; -import iaik.x509.X509Certificate; - -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.image.BufferedImage; -import java.io.*; -import java.net.URL; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.pdfbox.cos.COSArray; -import org.apache.pdfbox.cos.COSBase; -import org.apache.pdfbox.cos.COSDictionary; -import org.apache.pdfbox.cos.COSDocument; -import org.apache.pdfbox.cos.COSInteger; -import org.apache.pdfbox.cos.COSName; -import org.apache.pdfbox.cos.COSString; -import org.apache.pdfbox.pdfwriter.COSWriter; -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.pdmodel.PDDocumentCatalog; -import org.apache.pdfbox.pdmodel.PDPage; -import org.apache.pdfbox.pdmodel.PDResources; -import org.apache.pdfbox.pdmodel.common.PDMetadata; -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; -import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface; -import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureOptions; -import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; -import org.apache.pdfbox.pdmodel.interactive.form.PDField; -import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField; -import org.apache.pdfbox.preflight.Format; -import org.apache.pdfbox.preflight.PreflightDocument; -import org.apache.pdfbox.preflight.ValidationResult; -import org.apache.pdfbox.preflight.exception.SyntaxValidationException; -import org.apache.pdfbox.preflight.exception.ValidationException; -import org.apache.pdfbox.preflight.parser.PreflightParser; -import org.apache.pdfbox.rendering.ImageType; -import org.apache.pdfbox.rendering.PDFRenderer; -import org.apache.xmpbox.XMPMetadata; -import org.apache.xmpbox.schema.PDFAIdentificationSchema; -import org.apache.xmpbox.xml.DomXmpParser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.messages.MessageResolver; import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings; -import at.gv.egiz.pdfas.common.utils.StreamUtils; -import at.gv.egiz.pdfas.common.utils.TempFileHelper; import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource; import at.gv.egiz.pdfas.lib.api.IConfigurationConstants; import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; @@ -113,7 +55,50 @@ import at.gv.egiz.pdfas.lib.impl.status.RequestedSignature; import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction; import at.knowcenter.wag.egov.egiz.pdf.TablePos; import at.knowcenter.wag.egov.egiz.table.Table; +import iaik.x509.X509Certificate; +import org.apache.commons.io.IOUtils; +import org.apache.pdfbox.cos.*; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDDocumentCatalog; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDResources; +import org.apache.pdfbox.pdmodel.common.PDMetadata; +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.graphics.color.PDOutputIntent; +import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; +import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; +import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureOptions; +import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; +import org.apache.pdfbox.pdmodel.interactive.form.PDField; +import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField; +import org.apache.pdfbox.preflight.PreflightDocument; +import org.apache.pdfbox.preflight.ValidationResult; +import org.apache.pdfbox.preflight.exception.SyntaxValidationException; +import org.apache.pdfbox.preflight.exception.ValidationException; +import org.apache.pdfbox.preflight.parser.PreflightParser; +import org.apache.pdfbox.rendering.ImageType; +import org.apache.pdfbox.rendering.PDFRenderer; +import org.apache.xmpbox.XMPMetadata; +import org.apache.xmpbox.schema.PDFAIdentificationSchema; +import org.apache.xmpbox.xml.DomXmpParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import javax.activation.DataSource; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { @@ -313,6 +298,7 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { // handle rotated page int targetPageNumber = positioningInstruction.getPage(); logger.debug("Target Page: " + targetPageNumber); + //umjesto -1 da probamo -2 PDPage targetPage = doc.getPages().get(targetPageNumber - 1); int rot = targetPage.getRotation(); logger.debug("Page rotation: " + rot); @@ -618,68 +604,9 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { runPDFAPreflight(new ByteArrayDataSource(pdfObject.getSignedDocument())); } - /*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"); - } - } -*/ /*Check if doc has to be protected*/ - if (requestedSignature.getStatus().getSettings().hasValue(DEFAULT_CONFIG_PROTECT_COPY_PDF)) - { - AccessPermission ap = doc.getCurrentAccessPermission(); - - if (IConfigurationConstants.TRUE.equalsIgnoreCase(requestedSignature.getStatus().getSettings().getValue(IConfigurationConstants.DEFAULT_CONFIG_PROTECT_COPY_PDF))) - { - try { - if (doc.isEncrypted()) { //remove the security before adding protections - //doc.decrypt(""); - doc.setAllSecurityToBeRemoved(true); - } - String ownerPassword = ""; - String userPassword = ""; - ap.setCanExtractContent(false); - ap.setCanModify(false); - ap.setCanPrint(false); - ap.setReadOnly(); - ap.setCanExtractForAccessibility(false); - StandardProtectionPolicy policy = new StandardProtectionPolicy(ownerPassword,userPassword,ap); - doc.protect(policy); - - //doc = new PDDocument(doc.getDocument(),null,ap); - logger.info("Added Protection Parameters"); - - - AccessPermission ap_new = doc.getCurrentAccessPermission(); - - - Boolean canextract = ap_new.canExtractContent(); - Boolean bool = ap_new.isReadOnly(); - } - catch (Exception e) - { - logger.info("Error message" + e.getMessage()); - } - } - else if (IConfigurationConstants.FALSE.equalsIgnoreCase(requestedSignature.getStatus().getSettings().getValue(IConfigurationConstants.DEFAULT_CONFIG_PROTECT_COPY_PDF))) - { - /*ap.setCanExtractContent(true); - doc = new PDDocument(doc.getDocument(),null,ap); - logger.info("Added Protection Parameters");*/ - } - - } - } catch (IOException e1) { e1.printStackTrace(); @@ -703,12 +630,6 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { doc.close(); - AccessPermission ap_new = doc.getCurrentAccessPermission(); - - - Boolean canextract = ap_new.canExtractContent(); - Boolean bool = ap_new.isReadOnly(); - String test = ""; } catch (IOException e) { logger.debug("Failed to close COS Doc!", e); // Ignore @@ -718,6 +639,13 @@ public class PADESPDFBOXSigner implements IPdfSigner, IConfigurationConstants { logger.debug("Signature done!"); } + + + AccessPermission ap_new = doc.getCurrentAccessPermission(); + Boolean canextract = ap_new.canExtractContent(); + Boolean bool = ap_new.isReadOnly(); + String test = ""; + } /** diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java index 8a58d364..29b7eb21 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsParameterExtractor.java @@ -71,8 +71,10 @@ public class PdfAsParameterExtractor { public static final String PARAM_PREPROCESSOR_PREFIX = "pp:"; public static final String PARAM_OVERWRITE_PREFIX = "ov:"; public static final String PARAM_QRCODE_CONTENT = "qrcontent"; - - + public static final String PARAM_PLACEHOLDERID = "placeholder_id"; + + + public static String getConnector(HttpServletRequest request) { String connector = (String)request.getAttribute(PARAM_CONNECTOR); if(connector != null) { @@ -85,7 +87,12 @@ public class PdfAsParameterExtractor { String qrcodeContent = (String)request.getAttribute(PARAM_QRCODE_CONTENT); return qrcodeContent; } - + + public static String getPlaceholderId(HttpServletRequest request) { + String placeholderId = (String)request.getAttribute(PARAM_PLACEHOLDERID); + return placeholderId; + } + public static String getTransactionId(HttpServletRequest request) { String transactionId = (String)request.getAttribute(PARAM_TRANSACTION_ID); return transactionId; 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 4ec8021d..07fb7d65 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 @@ -171,6 +171,9 @@ public class ExternSignServlet extends HttpServlet { try { byte[] filecontent = null; + + + // checks if the request actually contains upload file if (!ServletFileUpload.isMultipartContent(request)) { // No Uploaded data! @@ -181,6 +184,12 @@ public class ExternSignServlet extends HttpServlet { throw new PdfAsWebException("No Signature data defined!"); } } else { + + + //takes placeholder id if exist + //if(request.getParameter("placeholder_id")!=null && !request.getParameter("placeholder_id").isEmpty()){ + // String placeholder_id = request.getParameter("placeholder_id"); + //} // configures upload settings DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(WebConfiguration.getFilesizeThreshold()); @@ -335,6 +344,8 @@ public class ExternSignServlet extends HttpServlet { String locale = PdfAsParameterExtractor.getLocale(request); PdfAsHelper.setLocale(request, response, locale); + + String placeholder_id = PdfAsParameterExtractor.getPlaceholderId(request); String filename = PdfAsParameterExtractor.getFilename(request); if(filename != null) { -- cgit v1.2.3