aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-lib/src/main/java/at
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2013-10-16 10:30:10 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2013-10-16 10:30:10 +0200
commit07cfc175c86eec0def3cd7376e0697317d3d7b26 (patch)
treec1336c67023b508a8a662ed1d9f42707295d0591 /pdf-as-lib/src/main/java/at
parent62434d4f7d4bf80b4c236c4153bffab703916ee3 (diff)
downloadpdf-as-4-07cfc175c86eec0def3cd7376e0697317d3d7b26.tar.gz
pdf-as-4-07cfc175c86eec0def3cd7376e0697317d3d7b26.tar.bz2
pdf-as-4-07cfc175c86eec0def3cd7376e0697317d3d7b26.zip
Legacy API changes
Diffstat (limited to 'pdf-as-lib/src/main/java/at')
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/SignaturePosition.java38
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java3
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java195
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java18
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignaturePositionImpl.java55
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java20
6 files changed, 229 insertions, 100 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/SignaturePosition.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/SignaturePosition.java
new file mode 100644
index 00000000..477d798f
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/SignaturePosition.java
@@ -0,0 +1,38 @@
+package at.gv.egiz.pdfas.lib.api;
+
+public interface SignaturePosition {
+ /**
+ * Returns the page on which the signature was placed.
+ *
+ * @return Returns the page on which the signature was placed.
+ */
+ public int getPage();
+
+ /**
+ * Returns the x position.
+ *
+ * @return Returns the x position.
+ */
+ public float getX();
+
+ /**
+ * Returns the y position.
+ *
+ * @return Returns the y position.
+ */
+ public float getY();
+
+ /**
+ * Returns the width of the signature.
+ *
+ * @return Returns the width of the signature.
+ */
+ public float getWidth();
+
+ /**
+ * Returns the height of the signature.
+ *
+ * @return Returns the height of the signature.
+ */
+ public float getHeight();
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java
index 03e48d73..d994c3e1 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/sign/SignResult.java
@@ -3,6 +3,7 @@ package at.gv.egiz.pdfas.lib.api.sign;
import java.security.cert.X509Certificate;
import at.gv.egiz.pdfas.lib.api.DataSink;
+import at.gv.egiz.pdfas.lib.api.SignaturePosition;
public interface SignResult {
/**
@@ -34,5 +35,5 @@ public interface SignResult {
* @return Returns the position where the signature is finally placed. May
* return null if no position information is available.
*/
- //public SignaturePosition getSignaturePosition();
+ public SignaturePosition getSignaturePosition();
}
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 c83d3bf7..6f74303c 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
@@ -1,17 +1,10 @@
package at.gv.egiz.pdfas.lib.impl;
-import iaik.cms.CMSException;
-import iaik.cms.CMSParsingException;
-import iaik.cms.SignedData;
-import iaik.cms.SignerInfo;
-import iaik.x509.X509Certificate;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
-import java.security.SignatureException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
@@ -25,13 +18,11 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import sun.misc.Regexp;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException;
import at.gv.egiz.pdfas.common.settings.ISettings;
import at.gv.egiz.pdfas.common.settings.Settings;
import at.gv.egiz.pdfas.common.settings.SignatureProfileSettings;
-import at.gv.egiz.pdfas.common.utils.StringUtils;
import at.gv.egiz.pdfas.lib.api.Configuration;
import at.gv.egiz.pdfas.lib.api.IConfigurationConstants;
import at.gv.egiz.pdfas.lib.api.PdfAs;
@@ -48,7 +39,6 @@ import at.gv.egiz.pdfas.lib.impl.signing.IPdfSigner;
import at.gv.egiz.pdfas.lib.impl.signing.PdfSignerFactory;
import at.gv.egiz.pdfas.lib.impl.signing.pdfbox.PdfboxSignerWrapper;
import at.gv.egiz.pdfas.lib.impl.signing.sig_interface.SignatureDataExtractor;
-import at.gv.egiz.pdfas.lib.impl.signing.sig_interface.SignatureDataInjector;
import at.gv.egiz.pdfas.lib.impl.stamping.IPDFStamper;
import at.gv.egiz.pdfas.lib.impl.stamping.IPDFVisualObject;
import at.gv.egiz.pdfas.lib.impl.stamping.StamperFactory;
@@ -103,8 +93,9 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
logger.info("Selected signature Profile: " + signatureProfileID);
- SignatureProfileConfiguration signatureProfileConfiguration = status
- .getSignatureProfileConfiguration(signatureProfileID);
+ // SignatureProfileConfiguration signatureProfileConfiguration =
+ // status
+ // .getSignatureProfileConfiguration(signatureProfileID);
// set Original PDF Document Data
status.getPdfObject().setOriginalDocument(
@@ -115,65 +106,62 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
// TODO: Do placeholder search
}
- if (requestedSignature.isVisual()) {
- logger.info("Creating visual siganture block");
- // ================================================================
- // SignBlockCreationStage (visual) -> create visual signature
- // block (logicaly)
- SignatureProfileSettings signatureProfileSettings = TableFactory
- .createProfile(signatureProfileID, settings);
-
- Table main = TableFactory.createSigTable(
- signatureProfileSettings, MAIN, settings,
- requestedSignature);
-
- IPDFStamper stamper = StamperFactory
- .createDefaultStamper(settings);
- IPDFVisualObject visualObject = stamper.createVisualPDFObject(
- status.getPdfObject(), main);
-
- // ================================================================
- // PositioningStage (visual) -> find position or use fixed
- // position
-
- String posString = status.getSignParamter()
- .getSignaturePosition();
-
- if (posString == null) {
- posString = signatureProfileConfiguration
- .getDefaultPositioning();
- }
-
- TablePos tablePos = null;
-
- if (posString == null) {
- tablePos = new TablePos();
- } else {
- tablePos = new TablePos(posString);
- }
-
- PDDocument originalDocument = PDDocument
- .load(new ByteArrayInputStream(status.getPdfObject()
- .getOriginalDocument()));
-
- PositioningInstruction positioningInstruction = Positioning
- .determineTablePositioning(tablePos, "",
- originalDocument, visualObject);
+ this.stampPdf(status);
- // ================================================================
- // StampingStage (visual) -> stamp logical signature block to
- // location (itext)
-
- byte[] incrementalUpdate = stamper.writeVisualObject(
- visualObject, positioningInstruction, status
- .getPdfObject().getOriginalDocument());
- status.getPdfObject().setStampedDocument(incrementalUpdate);
- } else {
- logger.info("No visual siganture block");
- // Stamped Object is equal to original
- status.getPdfObject().setStampedDocument(
- status.getPdfObject().getOriginalDocument());
- }
+ /*
+ * if (requestedSignature.isVisual()) {
+ * logger.info("Creating visual siganture block"); //
+ * ================================================================
+ * // SignBlockCreationStage (visual) -> create visual signature //
+ * block (logicaly) SignatureProfileSettings
+ * signatureProfileSettings = TableFactory
+ * .createProfile(signatureProfileID, settings);
+ *
+ * Table main = TableFactory.createSigTable(
+ * signatureProfileSettings, MAIN, settings, requestedSignature);
+ *
+ * IPDFStamper stamper = StamperFactory
+ * .createDefaultStamper(settings); IPDFVisualObject visualObject =
+ * stamper.createVisualPDFObject( status.getPdfObject(), main);
+ *
+ * //
+ * ================================================================
+ * // PositioningStage (visual) -> find position or use fixed //
+ * position
+ *
+ * String posString = status.getSignParamter()
+ * .getSignaturePosition();
+ *
+ * if (posString == null) { posString =
+ * signatureProfileConfiguration .getDefaultPositioning(); }
+ *
+ * TablePos tablePos = null;
+ *
+ * if (posString == null) { tablePos = new TablePos(); } else {
+ * tablePos = new TablePos(posString); }
+ *
+ * PDDocument originalDocument = PDDocument .load(new
+ * ByteArrayInputStream(status.getPdfObject()
+ * .getOriginalDocument()));
+ *
+ * PositioningInstruction positioningInstruction = Positioning
+ * .determineTablePositioning(tablePos, "", originalDocument,
+ * visualObject);
+ *
+ * //
+ * ================================================================
+ * // StampingStage (visual) -> stamp logical signature block to //
+ * location (itext)
+ *
+ * byte[] incrementalUpdate = stamper.writeVisualObject(
+ * visualObject, positioningInstruction, status
+ * .getPdfObject().getOriginalDocument());
+ * status.getPdfObject().setStampedDocument(incrementalUpdate); }
+ * else { logger.info("No visual siganture block"); // Stamped
+ * Object is equal to original
+ * status.getPdfObject().setStampedDocument(
+ * status.getPdfObject().getOriginalDocument()); }
+ */
// TODO: Create signature
IPdfSigner signer = PdfSignerFactory.createPdfSigner();
@@ -269,8 +257,8 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
result.addAll(results);
}
- return result;
}
+ return result;
} catch (IOException e) {
e.printStackTrace();
} catch (PdfAsException e) {
@@ -327,24 +315,25 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
try {
status.getRequestedSignature().setCertificate(
request.getCertificate());
-
+
// set Original PDF Document Data
status.getPdfObject().setOriginalDocument(
status.getSignParamter().getDataSource().getByteData());
-
+
// STAMPER!
stampPdf(status);
request.setNeedCertificate(false);
status.setSigningDate(Calendar.getInstance());
-
+
// GET Signature DATA
String pdfFilter = status.getSignParamter().getPlainSigner()
.getPDFFilter();
String pdfSubFilter = status.getSignParamter().getPlainSigner()
.getPDFSubFilter();
SignatureDataExtractor signatureDataExtractor = new SignatureDataExtractor(
- request.getCertificate(), pdfFilter, pdfSubFilter, status.getSigningDate());
+ request.getCertificate(), pdfFilter, pdfSubFilter,
+ status.getSigningDate());
IPdfSigner signer = PdfSignerFactory.createPdfSigner();
signer.signPDF(status.getPdfObject(),
@@ -362,23 +351,25 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
request.setNeedSignature(false);
// TODO: Inject signature byte[] into signedDocument
int offset = request.getSignatureData().length;
-
- for(int i = 0; i < request.getSignature().length; i++) {
- status.getPdfObject().getSignedDocument()[offset + i] = request.getSignature()[i];
+
+ for (int i = 0; i < request.getSignature().length; i++) {
+ status.getPdfObject().getSignedDocument()[offset + i] = request
+ .getSignature()[i];
}
/*
-
- String pdfFilter = status.getSignParamter().getPlainSigner()
- .getPDFFilter();
- String pdfSubFilter = status.getSignParamter().getPlainSigner()
- .getPDFSubFilter();
- SignatureDataInjector injector = new SignatureDataInjector(
- request.getCertificate(), pdfFilter, pdfSubFilter, status.getSigningDate(),
- request.getSignature(), request.getSignatureData());
-
- IPdfSigner signer = PdfSignerFactory.createPdfSigner();
- signer.signPDF(status.getPdfObject(),
- status.getRequestedSignature(), injector);*/
+ *
+ * String pdfFilter = status.getSignParamter().getPlainSigner()
+ * .getPDFFilter(); String pdfSubFilter =
+ * status.getSignParamter().getPlainSigner() .getPDFSubFilter();
+ * SignatureDataInjector injector = new SignatureDataInjector(
+ * request.getCertificate(), pdfFilter, pdfSubFilter,
+ * status.getSigningDate(), request.getSignature(),
+ * request.getSignatureData());
+ *
+ * IPdfSigner signer = PdfSignerFactory.createPdfSigner();
+ * signer.signPDF(status.getPdfObject(),
+ * status.getRequestedSignature(), injector);
+ */
request.setIsReady(true);
} else {
throw new PdfAsException("Invalid Status");
@@ -399,10 +390,10 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
if (!request.isReady()) {
throw new PdfAsException("Invalid Status");
}
-
+
try {
return createSignResult(status);
- } catch(IOException e) {
+ } catch (IOException e) {
throw new PdfAsException("Invalid Status", e);
}
}
@@ -464,6 +455,16 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
byte[] incrementalUpdate = stamper.writeVisualObject(visualObject,
positioningInstruction, status.getPdfObject()
.getOriginalDocument());
+
+ 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);
+
status.getPdfObject().setStampedDocument(incrementalUpdate);
} else {
logger.info("No visual siganture block");
@@ -473,7 +474,8 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
}
}
- private SignResult createSignResult(OperationStatus status) throws IOException {
+ private SignResult createSignResult(OperationStatus status)
+ throws IOException {
// ================================================================
// Create SignResult
SignResultImpl result = new SignResultImpl(status.getSignParamter()
@@ -485,6 +487,13 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants {
outputStream.close();
+ // result.setSignaturePosition(status.getRequestedSignature().);
+
+ result.setSignerCertificate(status.getRequestedSignature()
+ .getCertificate());
+ result.setSignaturePosition(status.getRequestedSignature()
+ .getSignaturePosition());
+
return result;
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java
index dcb27be9..28a2a33b 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignResultImpl.java
@@ -3,11 +3,14 @@ package at.gv.egiz.pdfas.lib.impl;
import java.security.cert.X509Certificate;
import at.gv.egiz.pdfas.lib.api.DataSink;
+import at.gv.egiz.pdfas.lib.api.SignaturePosition;
import at.gv.egiz.pdfas.lib.api.sign.SignResult;
public class SignResultImpl implements SignResult {
protected DataSink dataSink;
+ protected X509Certificate certificate;
+ protected SignaturePosition position;
public SignResultImpl(DataSink dataSink) {
this.dataSink = dataSink;
@@ -18,8 +21,19 @@ public class SignResultImpl implements SignResult {
}
public X509Certificate getSignerCertificate() {
- // TODO Auto-generated method stub
- return null;
+ return this.certificate;
+ }
+
+ public SignaturePosition getSignaturePosition() {
+ return this.position;
+ }
+
+ public void setSignerCertificate(X509Certificate certificate) {
+ this.certificate = certificate;
+ }
+
+ public void setSignaturePosition(SignaturePosition position) {
+ this.position = position;
}
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignaturePositionImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignaturePositionImpl.java
new file mode 100644
index 00000000..7ad8174b
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/SignaturePositionImpl.java
@@ -0,0 +1,55 @@
+package at.gv.egiz.pdfas.lib.impl;
+
+import at.gv.egiz.pdfas.lib.api.SignaturePosition;
+
+public class SignaturePositionImpl implements SignaturePosition {
+
+ protected int page;
+ protected float x;
+ protected float y;
+ protected float width;
+ protected float height;
+
+
+
+ public void setPage(int page) {
+ this.page = page;
+ }
+
+ public void setX(float x) {
+ this.x = x;
+ }
+
+ public void setY(float y) {
+ this.y = y;
+ }
+
+ public void setWidth(float width) {
+ this.width = width;
+ }
+
+ public void setHeight(float height) {
+ this.height = height;
+ }
+
+ public int getPage() {
+ return page;
+ }
+
+ public float getX() {
+ return x;
+ }
+
+ public float getY() {
+ return y;
+ }
+
+ public float getWidth() {
+ return width;
+ }
+
+ public float getHeight() {
+ return height;
+ }
+
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java
index a1820104..8bf56259 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/RequestedSignature.java
@@ -3,14 +3,16 @@ package at.gv.egiz.pdfas.lib.impl.status;
import iaik.x509.X509Certificate;
import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException;
+import at.gv.egiz.pdfas.lib.api.SignaturePosition;
import at.knowcenter.wag.egov.egiz.pdf.TablePos;
public class RequestedSignature {
private String signatureProfile;
- private TablePos signaturePosition;
+ private TablePos tablePosition;
private OperationStatus status;
private X509Certificate certificate;
+ private SignaturePosition signaturePosition = null;
//private IPlainSigner signer = null;
public RequestedSignature(OperationStatus status) throws PdfAsException {
@@ -30,9 +32,9 @@ public class RequestedSignature {
this.signatureProfile = profileID;
if(status.getSignParamter().getSignaturePosition() == null) {
- this.signaturePosition = new TablePos();
+ this.tablePosition = new TablePos();
} else {
- this.signaturePosition = new TablePos(status.getSignParamter().getSignaturePosition());
+ this.tablePosition = new TablePos(status.getSignParamter().getSignaturePosition());
}
}
@@ -41,7 +43,7 @@ public class RequestedSignature {
}
public TablePos getTablePos() {
- return this.signaturePosition;
+ return this.tablePosition;
}
public String getSignatureProfileID() {
@@ -55,5 +57,15 @@ public class RequestedSignature {
public void setCertificate(X509Certificate certificate) {
this.certificate = certificate;
}
+
+ public SignaturePosition getSignaturePosition() {
+ return signaturePosition;
+ }
+
+ public void setSignaturePosition(SignaturePosition signaturePosition) {
+ this.signaturePosition = signaturePosition;
+ }
+
+
}