summaryrefslogtreecommitdiff
path: root/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java')
-rw-r--r--trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/ByteArrayPDFASDataSource.java42
-rw-r--r--trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASHelper.java73
-rw-r--r--trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java18
-rw-r--r--trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java151
-rw-r--r--trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSignerFactory.java12
-rw-r--r--trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigningState.java87
-rw-r--r--trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java37
7 files changed, 420 insertions, 0 deletions
diff --git a/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/ByteArrayPDFASDataSource.java b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/ByteArrayPDFASDataSource.java
new file mode 100644
index 00000000..0fa23192
--- /dev/null
+++ b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/ByteArrayPDFASDataSource.java
@@ -0,0 +1,42 @@
+package at.asit.pdfover.signer.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;
+ }
+
+ @Override
+ public InputStream createInputStream() {
+ return new ByteArrayInputStream(this.data);
+ }
+
+ @Override
+ public int getLength() {
+ return this.data.length;
+ }
+
+ @Override
+ public byte[] getAsByteArray() {
+ return this.data;
+ }
+
+ @Override
+ public String getMimeType() {
+ return "application/pdf";
+ }
+
+ @Override
+ public String getCharacterEncoding() {
+ //TODO
+ return null;
+ }
+
+} \ No newline at end of file
diff --git a/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASHelper.java b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASHelper.java
new file mode 100644
index 00000000..756478d3
--- /dev/null
+++ b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASHelper.java
@@ -0,0 +1,73 @@
+package at.asit.pdfover.signer.pdfas;
+
+import at.asit.pdfover.signator.SignatureException;
+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 pdfAs = null;
+
+ /**
+ * Internal Pdf AS Object
+ */
+ private static PdfAsInternal pdfAsInternal = 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 the PDF-AS Internal object
+ * @throws PdfAsException
+ */
+ private static PdfAsInternal createPdfAsInternal() throws PdfAsException {
+ return new at.gv.egiz.pdfas.impl.api.internal.PdfAsInternalObject();
+ }
+
+ /**
+ * Gets PDF-AS Object
+ * @return the PDF-AS Object
+ * @throws SignatureException
+ */
+ public static synchronized PdfAs getPdfAs() throws SignatureException {
+ if (pdfAs == null) {
+ try {
+ pdfAs = createPdfAs();
+ } catch(PdfAsException e) {
+ throw new SignatureException(e);
+ }
+ }
+ return pdfAs;
+ }
+
+ /**
+ * Gets PDF-AS Internal object
+ * @return the PDF-AS Internal object
+ * @throws SignatureException
+ */
+ public static synchronized PdfAsInternal getPdfAsInternal() throws SignatureException {
+ if(pdfAsInternal == null) {
+ try {
+ pdfAsInternal = createPdfAsInternal();
+ } catch(PdfAsException e) {
+ throw new SignatureException(e);
+ }
+ }
+ return pdfAsInternal;
+ }
+}
diff --git a/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java
new file mode 100644
index 00000000..7130f53a
--- /dev/null
+++ b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java
@@ -0,0 +1,18 @@
+package at.asit.pdfover.signer.pdfas;
+
+import at.asit.pdfover.signator.DocumentSource;
+import at.asit.pdfover.signator.SLRequest;
+
+public class PDFASSLRequest implements SLRequest {
+
+ public PDFASSLRequest(String slRequest) {
+ /// Analyze Request ...
+ }
+
+ @Override
+ public DocumentSource getSignatureData() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java
new file mode 100644
index 00000000..949bbce1
--- /dev/null
+++ b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java
@@ -0,0 +1,151 @@
+package at.asit.pdfover.signer.pdfas;
+
+import at.asit.pdfover.signator.ByteArrayDocumentSource;
+import at.asit.pdfover.signator.SignatureException;
+import at.asit.pdfover.signator.Signer;
+import at.asit.pdfover.signator.SignResult;
+import at.asit.pdfover.signator.SignResultImpl;
+import at.asit.pdfover.signator.SignatureParameter;
+import at.asit.pdfover.signator.SignaturePosition;
+import at.asit.pdfover.signator.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 Implementation
+ */
+public class PDFASSigner implements Signer {
+
+ /**
+ * The profile ID
+ */
+ protected static final String PROFILE_ID = "SIGNATURBLOCK_DE";
+
+ /**
+ * The template URL
+ */
+ protected static final String URL_TEMPLATE = "http://pdfover.4.gv.at/template";
+
+ @Override
+ public SigningState prepare(SignatureParameter parameter)
+ throws SignatureException {
+ try {
+ PdfAsSignatureParameter sign_para = null;
+
+ if (PdfAsSignatureParameter.class.isInstance(parameter)) {
+ sign_para = PdfAsSignatureParameter.class.cast(parameter);
+ }
+
+ if (sign_para == null) {
+ throw new SignatureException("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.getEmblem() != null) {
+ params.setProfileOverrideValue("SIG_LABEL", parameter
+ .getEmblem().getFileName());
+ }
+
+ 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.setSignatureRequest(request);
+
+ return state;
+ } catch (PdfAsException e) {
+ throw new SignatureException(e);
+ }
+ }
+
+ @Override
+ public SignResult sign(SigningState state) throws SignatureException {
+ try {
+ PDFASSigningState sstate = null;
+
+ if (PDFASSigningState.class.isInstance(state)) {
+ sstate = PDFASSigningState.class.cast(state);
+ }
+
+ if (sstate == null) {
+ throw new SignatureException("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
+ at.gv.egiz.pdfas.api.sign.SignResult signResult = pdfasInternal
+ .finishLocalSign(pdfas, params, sdi, bkuParams, false,
+ sstate.getSignatureResponse().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().useAutoPositioning());*/
+ result.setSignaturePosition(pos);
+
+ // Set signed Document
+ result.setSignedDocument(new ByteArrayDocumentSource(data.getData()));
+
+ return result;
+ } catch (PdfAsException e) {
+ throw new SignatureException(e);
+ }
+ }
+
+ @Override
+ public SignatureParameter newParameter() {
+ return new PdfAsSignatureParameter();
+ }
+}
diff --git a/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSignerFactory.java b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSignerFactory.java
new file mode 100644
index 00000000..eaf9637f
--- /dev/null
+++ b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSignerFactory.java
@@ -0,0 +1,12 @@
+package at.asit.pdfover.signer.pdfas;
+
+import at.asit.pdfover.signator.Signer;
+import at.asit.pdfover.signator.SignerFactory;
+
+public class PDFASSignerFactory extends SignerFactory {
+
+ @Override
+ public Signer createSigner() {
+ return new PDFASSigner();
+ }
+}
diff --git a/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigningState.java b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigningState.java
new file mode 100644
index 00000000..8b8216c6
--- /dev/null
+++ b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigningState.java
@@ -0,0 +1,87 @@
+package at.asit.pdfover.signer.pdfas;
+
+import at.asit.pdfover.signator.SLRequest;
+import at.asit.pdfover.signator.SLResponse;
+import at.asit.pdfover.signator.SigningState;
+import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation;
+
+/**
+ * Signing State for PDFAS Wrapper
+ * @author afitzek
+ */
+public class PDFASSigningState implements SigningState {
+
+ /**
+ * The Signature Layer request
+ */
+ protected SLRequest slrequest;
+
+ /**
+ * The Signature Layer response
+ */
+ protected SLResponse slresponse;
+
+ @Override
+ public SLRequest getSignatureRequest() {
+ return this.slrequest;
+ }
+
+ @Override
+ public void setSignatureResponse(SLResponse response) {
+ this.slresponse = response;
+ }
+
+ /**
+ * Sets the SL Request
+ * @param request The SL Request
+ */
+ public void setSignatureRequest(SLRequest request) {
+ this.slrequest = request;
+ }
+
+ /**
+ * Gets the SL Response
+ * @return The SL Repsonse object
+ */
+ public SLResponse getSignatureResponse() {
+ 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) {
+ this.pdfAsSignatureParameter = pdfAsSignatureParameter;
+ }
+
+ public at.gv.egiz.pdfas.api.sign.SignParameters getSignParameters() {
+ return signParameters;
+ }
+
+ public void setSignParameters(
+ at.gv.egiz.pdfas.api.sign.SignParameters signParameters) {
+ this.signParameters = signParameters;
+ }
+
+ public SignatureDetailInformation getSignatureDetailInformation() {
+ return signatureDetailInformation;
+ }
+
+ public void setSignatureDetailInformation(
+ SignatureDetailInformation signatureDetailInformation) {
+ this.signatureDetailInformation = signatureDetailInformation;
+ }
+}
diff --git a/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java
new file mode 100644
index 00000000..7332a13e
--- /dev/null
+++ b/trunk/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java
@@ -0,0 +1,37 @@
+package at.asit.pdfover.signer.pdfas;
+
+import at.asit.pdfover.signator.SignatureDimension;
+import at.asit.pdfover.signator.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);
+ }
+
+ @Override
+ public void setProperty(String key, String value) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getProperty(String key) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}