summaryrefslogtreecommitdiff
path: root/pdf-over/pdf-signer-pdf-as
diff options
context:
space:
mode:
authortkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:49:52 +0000
committertkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:49:52 +0000
commitc3d0c0ade67b5dfb9f56af109893275b4cf5a146 (patch)
tree6512d65bc8b4d1ccfe40d349237f4fa97a33713f /pdf-over/pdf-signer-pdf-as
parentb7d2f32fb8673f82602b7e937815c39a8df2193c (diff)
downloadmocca-c3d0c0ade67b5dfb9f56af109893275b4cf5a146.tar.gz
mocca-c3d0c0ade67b5dfb9f56af109893275b4cf5a146.tar.bz2
mocca-c3d0c0ade67b5dfb9f56af109893275b4cf5a146.zip
Start PDF-AS Wrapper Library
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@6 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over/pdf-signer-pdf-as')
-rw-r--r--pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/ByteArrayPdfAsDataSource.java36
-rw-r--r--pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASHelper.java73
-rw-r--r--pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSLRequest.java18
-rw-r--r--pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSignatureParameter.java25
-rw-r--r--pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSigner.java151
-rw-r--r--pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSigningState.java81
6 files changed, 384 insertions, 0 deletions
diff --git a/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/ByteArrayPdfAsDataSource.java b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/ByteArrayPdfAsDataSource.java
new file mode 100644
index 00000000..874a08e9
--- /dev/null
+++ b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/ByteArrayPdfAsDataSource.java
@@ -0,0 +1,36 @@
+package at.asit.pdfover.pdfsigner.pdfas;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import at.gv.egiz.pdfas.api.io.DataSource;
+
+public class ByteArrayPdfAsDataSource implements DataSource {
+
+ private byte[] data;
+
+ public ByteArrayPdfAsDataSource(byte[] data) {
+ this.data = data;
+ }
+
+ public InputStream createInputStream() {
+ return new ByteArrayInputStream(this.data);
+ }
+
+ public int getLength() {
+ return this.data.length;
+ }
+
+ public byte[] getAsByteArray() {
+ return this.data;
+ }
+
+ public String getMimeType() {
+ return "application/pdf";
+ }
+
+ public String getCharacterEncoding() {
+ return null;
+ }
+
+} \ No newline at end of file
diff --git a/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASHelper.java b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASHelper.java
new file mode 100644
index 00000000..1e14fc39
--- /dev/null
+++ b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASHelper.java
@@ -0,0 +1,73 @@
+package at.asit.pdfover.pdfsigner.pdfas;
+
+import at.asit.pdfover.pdfsigner.PDFSignatureException;
+import at.gv.egiz.pdfas.api.PdfAs;
+import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.api.internal.PdfAsInternal;
+
+/**
+ * Encapsulates PDF AS API Object to need just one initialization
+ * @author afitzek
+ */
+public class PDFASHelper {
+
+ /**
+ * PDF AS Object
+ */
+ private static PdfAs pdf_as_instance = null;
+
+ /**
+ * Internal Pdf AS Object
+ */
+ private static PdfAsInternal pdf_as_internal = null;
+
+ /**
+ * Creates PDF AS Object
+ * @return
+ * @throws PdfAsException
+ */
+ private static PdfAs CreatePdfAs() throws PdfAsException {
+ return new at.gv.egiz.pdfas.impl.api.PdfAsObject();
+ }
+
+ /**
+ * Creates a PDF AS Internal object
+ * @return
+ * @throws PdfAsException
+ */
+ private static PdfAsInternal CreatePdfAsInternal() throws PdfAsException {
+ return new at.gv.egiz.pdfas.impl.api.internal.PdfAsInternalObject();
+ }
+
+ /**
+ * Gets PDF AS Object
+ * @return
+ * @throws PDFSignatureException
+ */
+ public static synchronized PdfAs GetPdfAs() throws PDFSignatureException {
+ if(pdf_as_instance == null) {
+ try {
+ pdf_as_instance = CreatePdfAs();
+ } catch(PdfAsException e) {
+ throw new PDFSignatureException(e);
+ }
+ }
+ return pdf_as_instance;
+ }
+
+ /**
+ * Gets PDF AS Internal object
+ * @return
+ * @throws PDFSignatureException
+ */
+ public static synchronized PdfAsInternal GetPdfAsInternal() throws PDFSignatureException {
+ if(pdf_as_internal == null) {
+ try {
+ pdf_as_internal = CreatePdfAsInternal();
+ } catch(PdfAsException e) {
+ throw new PDFSignatureException(e);
+ }
+ }
+ return pdf_as_internal;
+ }
+}
diff --git a/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSLRequest.java b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSLRequest.java
new file mode 100644
index 00000000..a4b55c94
--- /dev/null
+++ b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSLRequest.java
@@ -0,0 +1,18 @@
+package at.asit.pdfover.pdfsigner.pdfas;
+
+import at.asit.pdfover.pdfsigner.DocumentSource;
+import at.asit.pdfover.pdfsigner.SLRequest;
+
+public class PDFASSLRequest implements SLRequest {
+
+ public PDFASSLRequest(String slRequest) {
+ /// Analyse Request ...
+ }
+
+ @Override
+ public DocumentSource GetSignatureData() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSignatureParameter.java b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSignatureParameter.java
new file mode 100644
index 00000000..518f54b7
--- /dev/null
+++ b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSignatureParameter.java
@@ -0,0 +1,25 @@
+package at.asit.pdfover.pdfsigner.pdfas;
+
+import at.asit.pdfover.pdfsigner.SignatureDimension;
+import at.asit.pdfover.pdfsigner.SignatureParameter;
+import at.gv.egiz.pdfas.api.sign.pos.SignaturePositioning;
+import at.gv.egiz.pdfas.api.io.DataSource;
+
+public class PDFASSignatureParameter extends SignatureParameter {
+
+ @Override
+ public SignatureDimension GetPlaceholderDimension() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public SignaturePositioning GetPDFASPositioning() {
+ // TODO: implement Signature creation
+ return new SignaturePositioning();
+ }
+
+ public DataSource GetPDFASDataSource() {
+ // TODO: implement Signature creation
+ return new ByteArrayPdfAsDataSource(null);
+ }
+}
diff --git a/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSigner.java b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSigner.java
new file mode 100644
index 00000000..f94f3fdf
--- /dev/null
+++ b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSigner.java
@@ -0,0 +1,151 @@
+package at.asit.pdfover.pdfsigner.pdfas;
+
+import at.asit.pdfover.pdfsigner.ByteArrayDocumentSource;
+import at.asit.pdfover.pdfsigner.PDFSignatureException;
+import at.asit.pdfover.pdfsigner.PDFSignerInterface;
+import at.asit.pdfover.pdfsigner.SignResult;
+import at.asit.pdfover.pdfsigner.SignResultImpl;
+import at.asit.pdfover.pdfsigner.SignatureParameter;
+import at.asit.pdfover.pdfsigner.SignaturePosition;
+import at.asit.pdfover.pdfsigner.SigningState;
+import at.gv.egiz.pdfas.api.PdfAs;
+import at.gv.egiz.pdfas.api.sign.SignParameters;
+import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation;
+import at.gv.egiz.pdfas.io.ByteArrayDataSink;
+import at.gv.egiz.pdfas.api.commons.Constants;
+import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.api.internal.LocalBKUParams;
+import at.gv.egiz.pdfas.api.internal.PdfAsInternal;
+
+/**
+ * PDF AS Signer Implemtation
+ *
+ * @author afitzek
+ */
+public class PDFASSigner implements PDFSignerInterface {
+
+ protected static final String PROFILE_ID = "";
+
+ protected static final String URL_TEMPLATE = "";
+
+ @Override
+ public SigningState Prepare(SignatureParameter parameter)
+ throws PDFSignatureException {
+ try {
+ PDFASSignatureParameter sign_para = null;
+
+ if (PDFASSignatureParameter.class.isInstance(parameter)) {
+ sign_para = PDFASSignatureParameter.class.cast(parameter);
+ }
+
+ if (sign_para == null) {
+ throw new PDFSignatureException("Incorrect SignatureParameter!");
+ }
+
+ PdfAs pdfas = PDFASHelper.GetPdfAs();
+
+ PDFASSigningState state = new PDFASSigningState();
+
+ SignParameters params = new SignParameters();
+ params.setSignaturePositioning(sign_para.GetPDFASPositioning());
+ params.setSignatureDevice(Constants.SIGNATURE_DEVICE_BKU);
+ params.setSignatureType(Constants.SIGNATURE_TYPE_BINARY);
+ params.setSignatureProfileId(PROFILE_ID);
+
+ if(parameter.GetCollimatingMark() != null) {
+ // TODO: Define CollimatingMark and use
+ params.setProfileOverrideValue("SIG_LABEL", "./images/signatur-logo_en.png");
+ }
+
+
+ params.setDocument(sign_para.GetPDFASDataSource());
+
+ state.setSignParameters(params);
+
+
+ PdfAsInternal pdfasInternal = PDFASHelper.GetPdfAsInternal();
+
+ // Prepares the document
+ SignatureDetailInformation sdi = pdfas.prepareSign(params);
+
+ state.setSignatureDetailInformation(sdi);
+
+ // Retrieve the SL Request
+ String slRequest = pdfasInternal.prepareLocalSignRequest(params,
+ false, URL_TEMPLATE, sdi);
+
+ PDFASSLRequest request = new PDFASSLRequest(slRequest);
+
+ state.SetSLSignatureRequest(request);
+
+ return state;
+ } catch (PdfAsException e) {
+ throw new PDFSignatureException(e);
+ }
+ }
+
+ @Override
+ public SignResult Sign(SigningState state) throws PDFSignatureException {
+ try {
+ PDFASSigningState sstate = null;
+
+ if (PDFASSigningState.class.isInstance(state)) {
+ sstate = PDFASSigningState.class.cast(state);
+ }
+
+ if (sstate == null) {
+ throw new PDFSignatureException("Incorrect SigningState!");
+ }
+
+ // Retrieve objects
+ PdfAs pdfas = PDFASHelper.GetPdfAs();
+
+ PdfAsInternal pdfasInternal = PDFASHelper.GetPdfAsInternal();
+
+ SignParameters params = sstate.getSignParameters();
+
+ // Prepare Output sink
+ ByteArrayDataSink data = new ByteArrayDataSink();
+ params.setOutput(data);
+
+ SignatureDetailInformation sdi = sstate
+ .getSignatureDetailInformation();
+
+ LocalBKUParams bkuParams = new LocalBKUParams(null, null, null);
+
+ // Perform signature
+ // TODO: NEED TO check GetSLSignatureResponse() Interface to retrieve SL Response ...
+ at.gv.egiz.pdfas.api.sign.SignResult signResult = pdfasInternal
+ .finishLocalSign(pdfas, params, sdi, bkuParams, false,
+ sstate.GetSLSignatureResponse().GetSLRespone());
+
+ // Preparing Result Response
+ SignResultImpl result = new SignResultImpl();
+
+ // Set Signer Certificate
+ result.SetSignerCertificate(signResult.getSignerCertificate());
+ at.gv.egiz.pdfas.api.sign.pos.SignaturePosition pdfasPos = signResult
+ .getSignaturePosition();
+
+ // Set Signature position
+ SignaturePosition pos = new SignaturePosition(pdfasPos.getX(),
+ pdfasPos.getY(), pdfasPos.getPage());
+ pos.SetAuto(sstate.getPDFAsSignatureParameter()
+ .GetSignaturePosition().GetAuto());
+ result.SetSignaturePosition(pos);
+
+ // Set signed Document
+ result.SetSignedDocument(new ByteArrayDocumentSource(data.getData()));
+
+ return result;
+ } catch (PdfAsException e) {
+ throw new PDFSignatureException(e);
+ }
+ }
+
+ @Override
+ public SignatureParameter GetParameter() {
+ return new PDFASSignatureParameter();
+ }
+
+}
diff --git a/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSigningState.java b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSigningState.java
new file mode 100644
index 00000000..9500f981
--- /dev/null
+++ b/pdf-over/pdf-signer-pdf-as/src/main/java/at/asit/pdfover/pdfsigner/pdfas/PDFASSigningState.java
@@ -0,0 +1,81 @@
+package at.asit.pdfover.pdfsigner.pdfas;
+
+import at.asit.pdfover.pdfsigner.SLRequest;
+import at.asit.pdfover.pdfsigner.SLResponse;
+import at.asit.pdfover.pdfsigner.SigningState;
+import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation;
+
+/**
+ * Signing State for PDFAS Wrapper
+ * @author afitzek
+ */
+public class PDFASSigningState implements SigningState {
+
+ protected SLRequest slrequest;
+
+ protected SLResponse slresponse;
+
+ @Override
+ public SLRequest GetSLSignatureRequest() {
+ return slrequest;
+ }
+
+ @Override
+ public void SetSLSignatureResponse(SLResponse value) {
+ this.slresponse = value;
+ }
+
+ /**
+ * Sets the SL Request
+ * @param request The SL Request
+ */
+ public void SetSLSignatureRequest(SLRequest request) {
+ this.slrequest = request;
+ }
+
+ /**
+ * Gets the SL Response
+ * @return The SL Repsonse object
+ */
+ public SLResponse GetSLSignatureResponse() {
+ return this.slresponse;
+ }
+
+
+ // ----------------------------------------
+ // PDF AS Specific stuff
+ // ----------------------------------------
+
+ protected SignatureDetailInformation SignatureDetailInformation;
+
+ protected at.gv.egiz.pdfas.api.sign.SignParameters SignParameters;
+
+ protected PDFASSignatureParameter PDFAsSignatureParameter;
+
+ public PDFASSignatureParameter getPDFAsSignatureParameter() {
+ return PDFAsSignatureParameter;
+ }
+
+ public void setPDFAsSignatureParameter(
+ PDFASSignatureParameter pDFAsSignatureParameter) {
+ PDFAsSignatureParameter = pDFAsSignatureParameter;
+ }
+
+ public at.gv.egiz.pdfas.api.sign.SignParameters getSignParameters() {
+ return SignParameters;
+ }
+
+ public void setSignParameters(
+ at.gv.egiz.pdfas.api.sign.SignParameters signParameters) {
+ SignParameters = signParameters;
+ }
+
+ public SignatureDetailInformation getSignatureDetailInformation() {
+ return SignatureDetailInformation;
+ }
+
+ public void setSignatureDetailInformation(
+ SignatureDetailInformation signatureDetailInformation) {
+ SignatureDetailInformation = signatureDetailInformation;
+ }
+}