summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:53:55 +0000
committertkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:53:55 +0000
commitfd63db00a873ba082029848041fe28392e496316 (patch)
tree221ce88a89c7264c8082e382b41a5ec7dd5bb93c
parent23ae1caefcf0cc99c2b90327afaff6376ecc552a (diff)
downloadpdf-over-fd63db00a873ba082029848041fe28392e496316.tar.gz
pdf-over-fd63db00a873ba082029848041fe28392e496316.tar.bz2
pdf-over-fd63db00a873ba082029848041fe28392e496316.zip
Changed SLRequest interface
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@27 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java9
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java2
-rw-r--r--pdf-over-signator/pom.xml4
-rw-r--r--pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java84
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSLRequest.java35
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas/src/main/java/at/asit/pdfover/signer/pdfas/PDFASSigner.java1
-rw-r--r--pom.xml5
7 files changed, 92 insertions, 48 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
index c9c079a8..ccb411be 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java
@@ -71,14 +71,7 @@ public class LocalBKUState extends State {
SLRequest request = this.state.signingState
.getSignatureRequest();
- String b64_data = new String(Base64.encodeBase64(request
- .getSignatureData().getByteArray()));
-
- String sl_request = request.getRequest()
- .replace(
- SLRequest.DATAOBJECT_STRING,
- "<sl:Base64Content>" + b64_data //$NON-NLS-1$
- + "</sl:Base64Content>"); //$NON-NLS-1$
+ String sl_request = request.getBase64Request();
HttpClient client = new HttpClient();
client.getParams().setParameter("http.useragent", //$NON-NLS-1$
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
index 9fc86f3b..af797756 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java
@@ -140,8 +140,6 @@ public class PrepareSigningState extends State {
// We got the Request set it into status and move on to next state ...
status.setSigningState(this.signingState);
- log.debug("SL REQUEST: " + this.signingState.getSignatureRequest().getRequest()); //$NON-NLS-1$
-
if(this.stateMachine.getStatus().getBKU() == BKUs.LOCAL) {
this.setNextState(new LocalBKUState(this.stateMachine));
} else if(this.stateMachine.getStatus().getBKU() == BKUs.MOBILE) {
diff --git a/pdf-over-signator/pom.xml b/pdf-over-signator/pom.xml
index a6cddab4..d8f7994d 100644
--- a/pdf-over-signator/pom.xml
+++ b/pdf-over-signator/pom.xml
@@ -14,5 +14,9 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </dependency>
</dependencies>
</project> \ No newline at end of file
diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java
index abc0ff30..c4be9dae 100644
--- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java
+++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java
@@ -15,28 +15,90 @@
*/
package at.asit.pdfover.signator;
+import org.apache.commons.codec.binary.Base64;
+
/**
* Security Layer Request
*/
-public interface SLRequest {
-
+public class SLRequest {
+
/**
- * The String Konstant to replace the SL DATAOBJECT
+ * The String constant to replace the SL DATAOBJECT
*/
public static final String DATAOBJECT_STRING = "##DATAOBJECT##";
-
+
+ /**
+ * The security layer request
+ */
+ private String request;
+
+ /**
+ * The document to be signed
+ */
+ private DocumentSource signatureData;
+
+ /**
+ * Set the SL request
+ * @param request the request to set
+ */
+ protected void setRequest(String request) {
+ this.request = request;
+ }
+
/**
- * The SL Request String
+ * The SL request String with the document encoded in base64
*
- * In this string the DATAOBJECT_STRING has to be replaced by the reference of the Signature Data
- * Examples are sl:Base64Content, sl:LocRefContent
- * @return
+ * This SL Request is always a detached signature request which contains a
+ * reference to the data object in base64 encoding.
+ *
+ * @return SL request String
+ */
+ public String getBase64Request() {
+ byte[] b64content = Base64.encodeBase64(getSignatureData().getByteArray());
+
+ String b64request = this.request.replace(
+ DATAOBJECT_STRING,
+ "<sl:Base64Content>" + b64content //$NON-NLS-1$
+ + "</sl:Base64Content>"); //$NON-NLS-1$
+
+ return b64request;
+ }
+
+ /**
+ * The SL request String with the document referenced as an URI
+ *
+ * This SL Request is always a detached signature request which contains a
+ * reference to the data object as an URI
+ * The URI has to be provided and should be a valid reference to
+ * the document provided by getSignatureData().
+ *
+ * @param uri The URI pointing to the signature data
+ * @return SL request String
*/
- public String getRequest();
-
+ public String getURIRequest(String uri) {
+ String urirequest = this.request.replace(
+ DATAOBJECT_STRING,
+ "<sl:LocRefContent>" + uri //$NON-NLS-1$
+ + "</sl:LocRefContent>"); //$NON-NLS-1$
+
+ return urirequest;
+ }
+
+ /**
+ * Set the signature data (document to be signed)
+ * @param signatureData the signatureData to set
+ */
+ protected void setSignatureData(DocumentSource signatureData) {
+ this.signatureData = signatureData;
+ }
+
/**
* Gets the signature data for this request
+ *
* @return The document source
*/
- public DocumentSource getSignatureData();
+ public DocumentSource getSignatureData()
+ {
+ return this.signatureData;
+ }
}
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 49cb1522..7267db85 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
@@ -26,45 +26,28 @@ import at.asit.pdfover.signator.SLRequest;
/**
* PDF - AS Security Layer Request implementation
*/
-public class PDFASSLRequest implements SLRequest {
+public class PDFASSLRequest extends 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, byte[] signData) {
- // Modifing SL Request ...
- this.request = slRequest.replace(PDFASSigner.LOC_REF, SLRequest.DATAOBJECT_STRING);
-
- if(!this.request.contains(DATAOBJECT_STRING)) {
+ if(!slRequest.contains(PDFASSigner.LOC_REF)) {
// TODO: throw Exception (Failed to prepare SL Request)
+ log.error("PDF-AS SL request doesn't contain " + PDFASSigner.LOC_REF);
+ log.debug("Request: " + slRequest);
}
-
- this.source = new ByteArrayDocumentSource(signData);
- }
-
- @Override
- public DocumentSource getSignatureData() {
- return this.source;
- }
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.SLRequest#getRequest()
- */
- @Override
- public String getRequest() {
- return this.request;
- }
+ // Modifing SL Request ...
+ setRequest(slRequest.replace(PDFASSigner.LOC_REF, SLRequest.DATAOBJECT_STRING));
+ setSignatureData(new ByteArrayDocumentSource(signData));
+ }
}
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 d1336d91..a2f34e9a 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
@@ -12,7 +12,6 @@ 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;
diff --git a/pom.xml b/pom.xml
index ed961c4a..c36f94e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -140,6 +140,11 @@
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
</dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ </dependency>
</dependencies>
</dependencyManagement>
</project> \ No newline at end of file