diff options
author | pdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2010-11-26 12:02:47 +0000 |
---|---|---|
committer | pdanner <pdanner@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c> | 2010-11-26 12:02:47 +0000 |
commit | 06b900642342afb680aab3b36fba9247e1e29aa9 (patch) | |
tree | b4d34d008b7d736c034caa81614a448c31af8fca /src/main/java/at/knowcenter/wag | |
parent | 1b337e50a9edb280aea49879f901613e1fe17b55 (diff) | |
download | pdf-as-3-06b900642342afb680aab3b36fba9247e1e29aa9.tar.gz pdf-as-3-06b900642342afb680aab3b36fba9247e1e29aa9.tar.bz2 pdf-as-3-06b900642342afb680aab3b36fba9247e1e29aa9.zip |
Placeholder-image handling
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@613 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag')
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java | 42 | ||||
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java | 28 |
2 files changed, 65 insertions, 5 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java index 57868d0..2c2c591 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -30,7 +30,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.api.analyze.NonTextObjectInfo;
+import at.gv.egiz.pdfas.api.commons.SignatureInformation;
import at.gv.egiz.pdfas.api.timestamp.TimeStamper;
+import at.gv.egiz.pdfas.api.xmldsig.ExtendedSignatureInformation;
+import at.gv.egiz.pdfas.api.xmldsig.XMLDsigData;
import at.gv.egiz.pdfas.commandline.CommandlineConnectorChooser;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.exceptions.framework.CorrectorException;
@@ -95,7 +98,8 @@ import com.lowagie.text.pdf.PdfReader; */
public abstract class PdfAS
{
-
+//23.11.2010 changed by exthex - added method: verifyExtendedSignatureHolders(List extended_signature_info, String connectorType, boolean returnHashInputData, Date verificationTime)
+
/**
* The current version of the pdf-as library. This version string is logged on every invocation
* of the api or the web application.
@@ -800,7 +804,7 @@ public abstract class PdfAS // (holder.signature_object.isTextual() ? "textual" : "binary"));
// logger_.debug(holder.signature_object.toString());
- SignatureResponse result = verify(holder, connectorType, returnHashInputData, verificationTime);
+ SignatureResponse result = verify(holder, connectorType, returnHashInputData, verificationTime, null);
results.add(result);
// logger_.debug();
@@ -815,6 +819,34 @@ public abstract class PdfAS return results;
}
+ /**
+ *
+ * @param extended_signature_info
+ * @param connectorType
+ * @param returnHashInputData
+ * @param verificationTime
+ * @return
+ * @throws PDFDocumentException
+ * @throws NormalizeException
+ * @throws SignatureException
+ * @throws ConnectorException
+ * @throws ConnectorFactoryException
+ */
+ public static List verifyExtendedSignatureHolders(List extended_signature_info, String connectorType, boolean returnHashInputData, Date verificationTime) throws PDFDocumentException, NormalizeException, SignatureException, ConnectorException, ConnectorFactoryException
+ {
+ List results = new ArrayList();
+ for (int i = 0; i < extended_signature_info.size(); i++)
+ {
+ ExtendedSignatureInformation sigInfo = (ExtendedSignatureInformation) extended_signature_info.get(i);
+ SignatureInformation si = sigInfo.getSignatureInformation();
+ SignatureHolder holder = (SignatureHolder) si.getInternalSignatureInformation();
+
+ SignatureResponse result = verify(holder, connectorType, returnHashInputData, verificationTime, sigInfo.getXmlDsigData());
+ results.add(result);
+ }
+ return results;
+ }
+
public static List verifySignatureHoldersWeb(List signature_holders,
VerifySessionInformation si, String loc_ref) throws PDFDocumentException, NormalizeException, SignatureException, ConnectorException
{
@@ -852,7 +884,7 @@ public abstract class PdfAS * @throws ConnectorException
* @throws ConnectorFactoryException
*/
- public static SignatureResponse verify(SignatureHolder signature_holder, String connectorType, boolean returnHashInputData, Date verificationTime) throws NormalizeException, PDFDocumentException, SignatureException, ConnectorException, ConnectorFactoryException
+ public static SignatureResponse verify(SignatureHolder signature_holder, String connectorType, boolean returnHashInputData, Date verificationTime, XMLDsigData dsig) throws NormalizeException, PDFDocumentException, SignatureException, ConnectorException, ConnectorFactoryException
{
// String text_to_be_verified = signature_holder.getSignedText();
// logger_.debug("verify text_to_be_verified"+text_to_be_verified);
@@ -894,7 +926,7 @@ public abstract class PdfAS cp.setVerificationTime(verificationTime);
Connector c = at.gv.egiz.pdfas.framework.ConnectorFactory.createConnector(connectorId, cp);
- return c.doVerify(sd, so);
+ return c.doVerify(sd, so, dsig);
}
public static SignatureResponse verifyWeb(SignatureHolder signature_holder, String connector, String loc_ref) throws NormalizeException, PDFDocumentException, SignatureException, ConnectorException
@@ -933,7 +965,7 @@ public abstract class PdfAS String profile = so_to_be_verified.getSignatureTypeDefinition().getType();
Connector c = ConnectorChooser.chooseWebConnectorForVerify(connector, so_to_be_verified.getKZ(), so.id, profile, loc_ref);
- return c.doVerify(sd, so);
+ return c.doVerify(sd, so, null);
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java index 4a80553..c34ee68 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java @@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateEncodingException;
@@ -42,6 +43,8 @@ import at.gv.egiz.pdfas.exceptions.pdf.KZSettingNotFoundException; import at.gv.egiz.pdfas.framework.input.PdfDataSource;
import at.gv.egiz.pdfas.framework.output.DataSink;
import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
+import at.gv.egiz.pdfas.placeholder.SignaturePlaceholderContext;
+import at.gv.egiz.pdfas.placeholder.SignaturePlaceholderData;
import at.gv.egiz.pdfas.utils.PDFASUtils;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
@@ -56,13 +59,17 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureTypes; import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
import at.knowcenter.wag.exactparser.ByteArrayUtils;
+import com.lowagie.text.BadElementException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
+import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;
+import com.lowagie.text.pdf.BadPdfFormatException;
import com.lowagie.text.pdf.PRStream;
import com.lowagie.text.pdf.PdfArray;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfDictionary;
+import com.lowagie.text.pdf.PdfImage;
import com.lowagie.text.pdf.PdfIndirectObject;
import com.lowagie.text.pdf.PdfIndirectReference;
import com.lowagie.text.pdf.PdfName;
@@ -87,6 +94,8 @@ import com.lowagie.text.pdf.PdfTemplate; */
public abstract class BinarySignature
{
+//23.11.2010 changed by exthex - added replacePlaceholder(PdfStamper stamper, int pageNr, String placeholderName) method
+
protected static Log logger = LogFactory.getLog(BinarySignature.class);
/**
* The tolerance area of the line break algorithm.
@@ -826,6 +835,13 @@ public abstract class BinarySignature {
throw new PDFDocumentException(224, "The provided page (=" + pi.getPage() + ") is out of range.");
}
+
+ if (SignaturePlaceholderContext.isSignaturePlaceholderDataSet() &&
+ SignaturePlaceholderContext.getSignaturePlaceholderData().getPlaceholderName() != null)
+ {
+ replacePlaceholder(stamper, pi.getPage(), SignaturePlaceholderContext.getSignaturePlaceholderData().getPlaceholderName());
+ }
+
PdfContentByte content = stamper.getOverContent(pi.getPage());
// content = StampContent einer PageStamp.
@@ -940,6 +956,18 @@ public abstract class BinarySignature throw new PresentableException(ErrorCode.CANNOT_WRITE_PDF, e);
}
}
+
+ private static void replacePlaceholder(PdfStamper stamper, int pageNr, String placeholderName) throws BadElementException, MalformedURLException, IOException, BadPdfFormatException {
+ Image img = Image.getInstance(SignaturePlaceholderData.class.getResource("empty.jpg"));
+ PdfImage pImg = new PdfImage(img, "Imwurscht", null);
+ PdfStamperImp stamperImp = (PdfStamperImp)stamper.getWriter();
+ PdfIndirectObject ind = stamperImp.addToBody(pImg);
+
+ PdfDictionary resources = stamper.getReader().getPageN(pageNr).getAsDict(PdfName.RESOURCES);
+ resources.getAsDict(PdfName.XOBJECT).put(new PdfName(placeholderName), ind.getIndirectReference());
+ stamperImp.markUsed(resources);
+ }
+
/**
* Creates the EGIZ Dictionary and adds it to the document.
|