summaryrefslogtreecommitdiff
path: root/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas
diff options
context:
space:
mode:
authortkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:53:41 +0000
committertkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:53:41 +0000
commit23ae1caefcf0cc99c2b90327afaff6376ecc552a (patch)
tree644167228a6b721760b1f024b3ddd94ede77c14e /pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas
parent7d6879d2f2ad32b79878567438bdb231cbc798d5 (diff)
downloadmocca-23ae1caefcf0cc99c2b90327afaff6376ecc552a.tar.gz
mocca-23ae1caefcf0cc99c2b90327afaff6376ecc552a.tar.bz2
mocca-23ae1caefcf0cc99c2b90327afaff6376ecc552a.zip
PDF-AS signature working with local BKU
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@26 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas')
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASHelper.java4
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java27
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java29
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigningState.java29
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java2
5 files changed, 77 insertions, 14 deletions
diff --git a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASHelper.java b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASHelper.java
index 00528762..80617989 100644
--- a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASHelper.java
+++ b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASHelper.java
@@ -16,6 +16,8 @@
package at.asit.pdfover.signer.pdfas;
//Imports
+import java.io.File;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.asit.pdfover.signator.SignatureException;
@@ -49,6 +51,8 @@ public class PDFASHelper {
* @throws PdfAsException
*/
private static PdfAs createPdfAs() throws PdfAsException {
+ File directory = new File (".");
+ System.setProperty("log4j.configuration", directory.getAbsolutePath()+"/log4j.properties");
return new at.gv.egiz.pdfas.impl.api.PdfAsObject();
}
diff --git a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java
index 02fccca0..49cb1522 100644
--- a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java
+++ b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java
@@ -19,6 +19,7 @@ package at.asit.pdfover.signer.pdfas;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.asit.pdfover.signator.ByteArrayDocumentSource;
import at.asit.pdfover.signator.DocumentSource;
import at.asit.pdfover.signator.SLRequest;
@@ -30,22 +31,40 @@ public class PDFASSLRequest implements SLRequest {
/**
* SFL4J Logger instance
**/
+ @SuppressWarnings("unused")
private static final Logger log = LoggerFactory.getLogger(PDFASSLRequest.class);
private String request;
+ private ByteArrayDocumentSource source;
+
/**
* Default constructor
* @param slRequest
+ * @param signData
*/
- public PDFASSLRequest(String slRequest) {
- this.request = slRequest;
+ public PDFASSLRequest(String slRequest, byte[] signData) {
+ // Modifing SL Request ...
+ this.request = slRequest.replace(PDFASSigner.LOC_REF, SLRequest.DATAOBJECT_STRING);
+
+ if(!this.request.contains(DATAOBJECT_STRING)) {
+ // TODO: throw Exception (Failed to prepare SL Request)
+ }
+
+ this.source = new ByteArrayDocumentSource(signData);
}
@Override
public DocumentSource getSignatureData() {
- // TODO Auto-generated method stub
- return null;
+ return this.source;
+ }
+
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SLRequest#getRequest()
+ */
+ @Override
+ public String getRequest() {
+ return this.request;
}
}
diff --git a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java
index cf93c96c..d1336d91 100644
--- a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java
+++ b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java
@@ -1,6 +1,7 @@
package at.asit.pdfover.signer.pdfas;
import at.asit.pdfover.signator.ByteArrayDocumentSource;
+import at.asit.pdfover.signator.SLResponse;
import at.asit.pdfover.signator.SignatureException;
import at.asit.pdfover.signator.Signer;
import at.asit.pdfover.signator.SignResult;
@@ -11,6 +12,7 @@ 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.framework.input.DataSource;
import at.gv.egiz.pdfas.io.ByteArrayDataSink;
import at.gv.egiz.pdfas.api.commons.Constants;
import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
@@ -32,6 +34,11 @@ public class PDFASSigner implements Signer {
*/
protected static final String URL_TEMPLATE = "http://pdfover.4.gv.at/template";
+ /**
+ * Location reference string
+ */
+ protected static final String LOC_REF = "<sl:LocRefContent>" + URL_TEMPLATE + "</sl:LocRefContent>";
+
@Override
public SigningState prepare(SignatureParameter parameter)
throws SignatureException {
@@ -56,10 +63,15 @@ public class PDFASSigner implements Signer {
params.setSignatureType(Constants.SIGNATURE_TYPE_BINARY);
params.setSignatureProfileId(PROFILE_ID);
+ params.setOutput(new ByteArrayDataSink());
if (parameter.getEmblem() != null) {
params.setProfileOverrideValue("SIG_LABEL", parameter
.getEmblem().getFileName());
}
+
+ // Prepare Output sink
+ state.setOutput(new ByteArrayDataSink());
+ params.setOutput(state.getOutput());
params.setDocument(sign_para.getPDFASDataSource());
@@ -76,9 +88,9 @@ public class PDFASSigner implements Signer {
String slRequest = pdfasInternal.prepareLocalSignRequest(params,
false, URL_TEMPLATE, sdi);
- //DataSource sig_data = sdi.getSignatureData();
+ at.gv.egiz.pdfas.api.io.DataSource sig_data = sdi.getSignatureData();
- PDFASSLRequest request = new PDFASSLRequest(slRequest);
+ PDFASSLRequest request = new PDFASSLRequest(slRequest, sig_data.getAsByteArray());
state.setSignatureRequest(request);
@@ -108,19 +120,18 @@ public class PDFASSigner implements Signer {
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);
+ SLResponse slResponse = sstate.getSignatureResponse();
+
+ LocalBKUParams bkuParams = new LocalBKUParams(slResponse.getServer(), slResponse.getUserAgent(), slResponse.getSignaturLayout());
// Perform signature
at.gv.egiz.pdfas.api.sign.SignResult signResult = pdfasInternal
.finishLocalSign(pdfas, params, sdi, bkuParams, false,
- sstate.getSignatureResponse().getSLRespone());
+ slResponse.getSLRespone());
// Preparing Result Response
SignResultImpl result = new SignResultImpl();
@@ -138,7 +149,7 @@ public class PDFASSigner implements Signer {
result.setSignaturePosition(pos);
// Set signed Document
- result.setSignedDocument(new ByteArrayDocumentSource(data.getData()));
+ result.setSignedDocument(new ByteArrayDocumentSource(((ByteArrayDataSink)sstate.getOutput()).getData()));
return result;
} catch (PdfAsException e) {
diff --git a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigningState.java b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigningState.java
index 1d52a27f..72e24747 100644
--- a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigningState.java
+++ b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigningState.java
@@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import at.asit.pdfover.signator.SLRequest;
import at.asit.pdfover.signator.SLResponse;
import at.asit.pdfover.signator.SigningState;
+import at.gv.egiz.pdfas.api.io.DataSink;
import at.gv.egiz.pdfas.api.sign.SignatureDetailInformation;
/**
@@ -39,6 +40,27 @@ public class PDFASSigningState implements SigningState {
protected SLRequest slrequest;
/**
+ * The PDF AS DataSink
+ */
+ protected DataSink output;
+
+ /**
+ * Gets the DataSink
+ * @return the datasink
+ */
+ public DataSink getOutput() {
+ return this.output;
+ }
+
+ /**
+ * Sets the datasing
+ * @param output the pdf as datasink
+ */
+ public void setOutput(DataSink output) {
+ this.output = output;
+ }
+
+ /**
* The Signature Layer response
*/
protected SLResponse slresponse;
@@ -69,6 +91,13 @@ public class PDFASSigningState implements SigningState {
return this.slresponse;
}
+ /* (non-Javadoc)
+ * @see at.asit.pdfover.signator.SigningState#hasSignatureResponse()
+ */
+ @Override
+ public boolean hasSignatureResponse() {
+ return this.getSignatureResponse() != null;
+ }
// ----------------------------------------
// PDF AS Specific stuff
diff --git a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java
index bd324e9f..4825785b 100644
--- a/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java
+++ b/pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PdfAsSignatureParameter.java
@@ -54,7 +54,7 @@ public class PdfAsSignatureParameter extends SignatureParameter {
*/
public DataSource getPDFASDataSource() {
// TODO: implement Signature creation
- return new ByteArrayPDFASDataSource(null);
+ return new ByteArrayPDFASDataSource(this.getInputDocument().getByteArray());
}
@Override