diff options
Diffstat (limited to 'pdf-over-signator/src/main/java')
5 files changed, 152 insertions, 4 deletions
diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java index 931fab41..bed9461e 100644 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java @@ -15,6 +15,7 @@ */ package at.asit.pdfover.signator; +import java.io.IOException; import java.io.InputStream; /** @@ -25,8 +26,9 @@ public interface DocumentSource { /** * Gets Document as Input Stream * @return InputStream of the document + * @throws IOException */ - public InputStream getInputStream(); + public InputStream getInputStream() throws IOException; /** * Get Length of document diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/PDFFileDocumentSource.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/PDFFileDocumentSource.java new file mode 100644 index 00000000..04fab03a --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/PDFFileDocumentSource.java @@ -0,0 +1,90 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.signator; + +// Imports +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class PDFFileDocumentSource implements DocumentSource { + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(PDFFileDocumentSource.class); + + private File file; + + private byte[] data = null; + + private int len = 0; + + /** + * Default constructor + * @param file + */ + public PDFFileDocumentSource(File file) { + this.file = file; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.signator.DocumentSource#getInputStream() + */ + @Override + public InputStream getInputStream() throws IOException { + return new FileInputStream(this.file); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.signator.DocumentSource#getLength() + */ + @Override + public int getLength() { + if(this.file.length() > Integer.MAX_VALUE) { + // TODO: Handle error somehow or use long ... + } + this.len = (int) this.file.length(); + return this.len; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.signator.DocumentSource#getByteArray() + */ + @Override + public byte[] getByteArray() { + if(this.data == null) { + try { + InputStream stream = this.getInputStream(); + this.data = new byte[this.getLength()]; + stream.read(this.data); + stream.close(); + } catch(IOException ex) { + log.error("Failed to read file!", ex); + } + } + return this.data; + } + +} 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 508c42c9..abc0ff30 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 @@ -19,6 +19,21 @@ package at.asit.pdfover.signator; * Security Layer Request */ public interface SLRequest { + + /** + * The String Konstant to replace the SL DATAOBJECT + */ + public static final String DATAOBJECT_STRING = "##DATAOBJECT##"; + + /** + * The SL Request String + * + * In this string the DATAOBJECT_STRING has to be replaced by the reference of the Signature Data + * Examples are sl:Base64Content, sl:LocRefContent + * @return + */ + public String getRequest(); + /** * Gets the signature data for this request * @return The document source diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java index 98328c07..84b5242f 100644 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java @@ -27,16 +27,51 @@ public class SLResponse { /** * SFL4J Logger instance **/ + @SuppressWarnings("unused") private static Logger log = LoggerFactory.getLogger(Signator.class); private String response; + private String server; + + /** + * Gets the server string + * @return the server + */ + public String getServer() { + return this.server; + } + + /** + * Gets the user Agent string + * @return the user Agent + */ + public String getUserAgent() { + return this.userAgent; + } + + /** + * Gets the signature Layout value + * @return the signature Layout + */ + public String getSignaturLayout() { + return this.signaturLayout; + } + + private String userAgent; + private String signaturLayout; /** * Create a new Security Layer response * @param response the SLResponse + * @param server the server + * @param userAgent the user Agent + * @param signaturLayout the signature Layout */ - public SLResponse(String response) { + public SLResponse(String response, String server, String userAgent, String signaturLayout) { this.response = response; + this.server = server; + this.userAgent = userAgent; + this.signaturLayout = signaturLayout; } /** diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java index 02543d7a..93facb86 100644 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java @@ -24,11 +24,17 @@ public interface SigningState { * Gets the Security Layer Request to create the signature * @return The Signature Request */ - public abstract SLRequest getSignatureRequest(); + public SLRequest getSignatureRequest(); /** * Sets the Security Layer Response to the Signature Request * @param value The Signature Response */ - public abstract void setSignatureResponse(SLResponse value); + public void setSignatureResponse(SLResponse value); + + /** + * Has the state a SignatureResponse set ? + * @return true if a SLResponse is set + */ + public boolean hasSignatureResponse(); } |