From 782e41eee1f04f86bc895a95cd2d51353284987a Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 18:51:24 +0000 Subject: Refactoring git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@11 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- pdf-over-signator/.classpath | 10 ++ pdf-over-signator/.project | 23 ++++ .../.settings/org.eclipse.core.resources.prefs | 7 ++ .../.settings/org.eclipse.jdt.core.prefs | 98 +++++++++++++++++ .../.settings/org.eclipse.m2e.core.prefs | 5 + .../.settings/org.eclipse.mylyn.tasks.ui.prefs | 4 + pdf-over-signator/pom.xml | 18 ++++ .../pdfover/signator/ByteArrayDocumentSource.java | 39 +++++++ .../at/asit/pdfover/signator/DocumentSource.java | 27 +++++ .../main/java/at/asit/pdfover/signator/Emblem.java | 12 +++ .../java/at/asit/pdfover/signator/SLRequest.java | 12 +++ .../java/at/asit/pdfover/signator/SLResponse.java | 25 +++++ .../java/at/asit/pdfover/signator/SignResult.java | 27 +++++ .../at/asit/pdfover/signator/SignResultImpl.java | 52 +++++++++ .../java/at/asit/pdfover/signator/Signator.java | 58 ++++++++++ .../asit/pdfover/signator/SignatureDimension.java | 69 ++++++++++++ .../asit/pdfover/signator/SignatureException.java | 45 ++++++++ .../asit/pdfover/signator/SignatureParameter.java | 117 +++++++++++++++++++++ .../asit/pdfover/signator/SignaturePosition.java | 107 +++++++++++++++++++ .../main/java/at/asit/pdfover/signator/Signer.java | 33 ++++++ .../at/asit/pdfover/signator/SignerFactory.java | 15 +++ .../at/asit/pdfover/signator/SigningState.java | 19 ++++ 22 files changed, 822 insertions(+) create mode 100644 pdf-over-signator/.classpath create mode 100644 pdf-over-signator/.project create mode 100644 pdf-over-signator/.settings/org.eclipse.core.resources.prefs create mode 100644 pdf-over-signator/.settings/org.eclipse.jdt.core.prefs create mode 100644 pdf-over-signator/.settings/org.eclipse.m2e.core.prefs create mode 100644 pdf-over-signator/.settings/org.eclipse.mylyn.tasks.ui.prefs create mode 100644 pdf-over-signator/pom.xml create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/ByteArrayDocumentSource.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/Emblem.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignResult.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignResultImpl.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureDimension.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureException.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignaturePosition.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signer.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignerFactory.java create mode 100644 pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java (limited to 'pdf-over-signator') diff --git a/pdf-over-signator/.classpath b/pdf-over-signator/.classpath new file mode 100644 index 00000000..0f53f3e2 --- /dev/null +++ b/pdf-over-signator/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/pdf-over-signator/.project b/pdf-over-signator/.project new file mode 100644 index 00000000..e6d690af --- /dev/null +++ b/pdf-over-signator/.project @@ -0,0 +1,23 @@ + + + pdf-over-signator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/pdf-over-signator/.settings/org.eclipse.core.resources.prefs b/pdf-over-signator/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..7f5422a4 --- /dev/null +++ b/pdf-over-signator/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +#Thu Aug 02 13:12:39 CEST 2012 +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/pdf-over-signator/.settings/org.eclipse.jdt.core.prefs b/pdf-over-signator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..3e73d18e --- /dev/null +++ b/pdf-over-signator/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,98 @@ +#Fri Aug 03 18:09:51 CEST 2012 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.doc.comment.support=enabled +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning +org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected +org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=warning +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled +org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,NORMAL,LOW +org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX,NOTE diff --git a/pdf-over-signator/.settings/org.eclipse.m2e.core.prefs b/pdf-over-signator/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..031daaa1 --- /dev/null +++ b/pdf-over-signator/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Thu Aug 02 12:30:29 CEST 2012 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pdf-over-signator/.settings/org.eclipse.mylyn.tasks.ui.prefs b/pdf-over-signator/.settings/org.eclipse.mylyn.tasks.ui.prefs new file mode 100644 index 00000000..c50cb4e0 --- /dev/null +++ b/pdf-over-signator/.settings/org.eclipse.mylyn.tasks.ui.prefs @@ -0,0 +1,4 @@ +#Fri Aug 03 18:56:19 CEST 2012 +eclipse.preferences.version=1 +project.repository.kind=jira +project.repository.url=http\://jira.egovlabs.gv.at diff --git a/pdf-over-signator/pom.xml b/pdf-over-signator/pom.xml new file mode 100644 index 00000000..a6cddab4 --- /dev/null +++ b/pdf-over-signator/pom.xml @@ -0,0 +1,18 @@ + + 4.0.0 + + pdf-over + a-sit.at + 4.0.0-SNAPSHOT + .. + + pdf-over-signator + PDF-Over Signator + + + org.slf4j + slf4j-log4j12 + + + \ No newline at end of file diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/ByteArrayDocumentSource.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/ByteArrayDocumentSource.java new file mode 100644 index 00000000..812ddc88 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/ByteArrayDocumentSource.java @@ -0,0 +1,39 @@ +package at.asit.pdfover.signator; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +/** + * A DocumentSource using a byte[] to store the document content + */ +public class ByteArrayDocumentSource implements DocumentSource { + + /** + * Document content + */ + protected byte[] data; + + /** + * Constructor with byte[] content + * @param data the document content + */ + public ByteArrayDocumentSource(byte[] data) { + this.data = data; + } + + @Override + public InputStream getInputStream() { + return new ByteArrayInputStream(this.data); + } + + @Override + public int getLength() { + return this.data.length; + } + + @Override + public byte[] getByteArray() { + return this.data; + } + +} 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 new file mode 100644 index 00000000..8b444020 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/DocumentSource.java @@ -0,0 +1,27 @@ +package at.asit.pdfover.signator; + +import java.io.InputStream; + +/** + * A Document Source + */ +public interface DocumentSource { + + /** + * Gets Document as Input Stream + * @return InputStream of the document + */ + public InputStream getInputStream(); + + /** + * Get Length of document + * @return length of the document + */ + public int getLength(); + + /** + * Get Document as byte[] + * @return byte[] of the Document + */ + public byte[] getByteArray(); +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Emblem.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Emblem.java new file mode 100644 index 00000000..e86b7100 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Emblem.java @@ -0,0 +1,12 @@ +package at.asit.pdfover.signator; + +/** + * Provides a logo for a signature block + */ +public interface Emblem { + /** + * Return the file name of the Emblem + * @return the file name + */ + public String getFileName(); +} 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 new file mode 100644 index 00000000..9b393e46 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLRequest.java @@ -0,0 +1,12 @@ +package at.asit.pdfover.signator; + +/** + * Security Layer Request + */ +public interface SLRequest { + /** + * Gets the signature data for this request + * @return The document source + */ + public DocumentSource getSignatureData(); +} 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 new file mode 100644 index 00000000..88adc117 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SLResponse.java @@ -0,0 +1,25 @@ +package at.asit.pdfover.signator; + +/** + * Security Layer response + */ +public class SLResponse { + + private String response; + + /** + * Create a new Security Layer response + * @param response the SLResponse + */ + public SLResponse(String response) { + this.response = response; + } + + /** + * Get the Security Layer response text + * @return the Security Layer response text + */ + public String getSLRespone() { + return this.response; + } +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignResult.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignResult.java new file mode 100644 index 00000000..7a8d4d0d --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignResult.java @@ -0,0 +1,27 @@ +package at.asit.pdfover.signator; + +import java.security.cert.X509Certificate; + +/** + * Signature Result containing the signed document as document source + */ +public interface SignResult { + + /** + * Getter of the property signaturePosition + * @return Returns the signaturePosition. + */ + public SignaturePosition getSignaturePosition(); + + /** + * Gets the signed Document + * @return Returns the documentSource. + */ + public DocumentSource getSignedDocument(); + + /** + * Gets the signer certificate + * @return The signer x509 certificate + */ + public X509Certificate getSignerCertificate(); +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignResultImpl.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignResultImpl.java new file mode 100644 index 00000000..dc0986cf --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignResultImpl.java @@ -0,0 +1,52 @@ +package at.asit.pdfover.signator; + +import java.security.cert.X509Certificate; + +/** + * The result of a signature operation + */ +public class SignResultImpl implements SignResult { + + private SignaturePosition position; + private DocumentSource source; + private X509Certificate certificate; + + @Override + public SignaturePosition getSignaturePosition() { + return this.position; + } + + @Override + public DocumentSource getSignedDocument() { + return this.source; + } + + @Override + public X509Certificate getSignerCertificate() { + return this.certificate; + } + + /** + * Set the signer certificate + * @param x509Certificate the signer certificate + */ + public void setSignerCertificate(X509Certificate x509Certificate) { + this.certificate = x509Certificate; + } + + /** + * Set the signature position + * @param postion the signature position + */ + public void setSignaturePosition(SignaturePosition postion) { + this.position = postion; + } + + /** + * Set the signed document + * @param source DocumentSource containing the signed document + */ + public void setSignedDocument(DocumentSource source) { + this.source = source; + } +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java new file mode 100644 index 00000000..4ba0b981 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signator.java @@ -0,0 +1,58 @@ +package at.asit.pdfover.signator; + +import java.util.EnumMap; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * PDF Signator Interface + */ +public class Signator { + + private static Logger log = LoggerFactory.getLogger(Signator.class); + + /** + * List of available PDF signing libraries + */ + public enum Signers { + /** + * PDF-AS + */ + PDFAS + }; + + private static Map factoryMap; + + static { + factoryMap = new EnumMap(Signers.class); + + try { + Class pdfAsClass = Class.forName("at.asit.pdfover.signer.pdfas.PDFASSignerFactory"); + SignerFactory factory = (SignerFactory)pdfAsClass.newInstance(); + registerSigner(Signers.PDFAS, factory); + } catch (ClassNotFoundException e) { + log.error("PDF Signer Factory not found", e); + throw new RuntimeException("PDF Signer Factory not found", e); + } catch (InstantiationException e) { + log.error("PDF Signer Factory could not be instantiated", e); + throw new RuntimeException("PDF Signer Factory could not be instantiated", e); + } catch (IllegalAccessException e) { + log.error("PDF Signer Factory could not accessed", e); + throw new RuntimeException("PDF Signer Factory could not accessed", e); + } + } + + private static void registerSigner(Signers signer, SignerFactory factory) { + factoryMap.put(signer, factory); + } + + /** + * Gets a PDF Signer according to the chosen signer library + * @param signer the chosen Signer type + * @return the PDF Signer + */ + public static Signer getSigner(Signers signer) { + return factoryMap.get(signer).createSigner(); + } +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureDimension.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureDimension.java new file mode 100644 index 00000000..8d47cb19 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureDimension.java @@ -0,0 +1,69 @@ +package at.asit.pdfover.signator; + +/** + * The dimensions of the visible signature block + */ +public class SignatureDimension { + + /** + * The visible Signature block width + */ + protected int width; + + /** + * The visible Signature block height + */ + protected int height; + + /** + * Constructor + * @param width The width of the signature block + * @param height The height of the signature block + */ + public SignatureDimension(int width, int height) { + setDimension(width, height); + } + + /** + * Sets the the dimension of the signature block + * @param width The width + * @param height The height + */ + public void setDimension(int width, int height) + { + setWidth(width); + setHeight(height); + } + + /** + * Sets the width for the dimension + * @param width + */ + public void setWidth(int width) { + this.width = width; + } + + /** + * Gets the width of the visible Signature block + * @return the width + */ + public int getWidth() { + return this.width; + } + + /** + * Sets the height for the dimension + * @param height + */ + public void setHeight(int height) { + this.height = height; + } + + /** + * Gets the height of the visible Signature block + * @return the height + */ + public int getHeight() { + return this.height; + } +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureException.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureException.java new file mode 100644 index 00000000..d41ba24d --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureException.java @@ -0,0 +1,45 @@ +package at.asit.pdfover.signator; + +/** + * Base class for signature exceptions + */ +public class SignatureException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 711578398780816710L; + + + /** + * Empty constructor + */ + public SignatureException() { + super(); + } + + /** + * Constructor with causing exception + * @param cause the cause + */ + public SignatureException(Throwable cause) { + super(cause); + } + + /** + * Constructor with message + * @param msg the message + */ + public SignatureException(String msg) { + super(msg); + } + + /** + * Constructor with message and causing exception + * @param message the message + * @param cause the cause + */ + public SignatureException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java new file mode 100644 index 00000000..3fa9c7ce --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java @@ -0,0 +1,117 @@ +package at.asit.pdfover.signator; + +/** + * The Signature Parameter + */ +public abstract class SignatureParameter { + + /** + * The Signature Position + * @uml.property name="signaturePosition" + * @uml.associationEnd + */ + protected SignaturePosition signaturePosition = null; + + /** + * The signature Device + */ + protected String keyIdentifier = null; + + /** + * The input document + * @uml.property name="documentSource" + * @uml.associationEnd + */ + protected DocumentSource documentSource = null; + + /** + * holds the collimating mark + * @uml.property name="collimark" + * @uml.associationEnd + */ + protected Emblem emblem; + + /** + * Getter of the property signaturePosition + * @return Returns the signaturePosition. + */ + public SignaturePosition getSignaturePosition() { + return this.signaturePosition; + } + + /** + * Setter of the property signaturePosition + * @param signaturePosition The signaturePosition to set. + */ + public void setSignaturePosition(SignaturePosition signaturePosition) { + this.signaturePosition = signaturePosition; + } + + /** + * Getter of the property keyIdentifier + * @return Returns the keyIdentifier. + */ + public String getKeyIdentifier() { + return this.keyIdentifier; + } + + /** + * Setter of the property keyIdentifier + * @param keyIdentifier The keyIdentifier to set. + */ + public void setKeyIdentifier(String keyIdentifier) { + this.keyIdentifier = keyIdentifier; + } + + /** + * Getter of the property documentSource + * @return Returns the documentSource. + */ + public DocumentSource getInputDocument() { + return this.documentSource; + } + + /** + * Setter of the property documentSource + * @param inputDocument The documentSource to set. + */ + public void setInputDocument(DocumentSource inputDocument) { + this.documentSource = inputDocument; + } + + /** + * Gets the Dimension to display the Placeholder + * @return the placeholder dimensions + */ + public abstract SignatureDimension getPlaceholderDimension(); + + /** + * Gets the Emblem + * @return the Emblem + */ + public Emblem getEmblem() { + return this.emblem; + } + + /** + * Sets the Emblem + * @param emblem The new Emblem + */ + public void setEmblem(Emblem emblem) { + this.emblem = emblem; + } + + /** + * Sets generic properties + * @param key + * @param value + */ + public abstract void setProperty(String key, String value); + + /** + * Gets generic properties + * @param key + * @return associated value + */ + public abstract String getProperty(String key); +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignaturePosition.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignaturePosition.java new file mode 100644 index 00000000..59fa4864 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignaturePosition.java @@ -0,0 +1,107 @@ +package at.asit.pdfover.signator; + + +/** + * Represents the position of a visible signature block + */ +public class SignaturePosition { + /** + * The x value of the position + */ + protected float x = 0; + + /** + * The y value of the position + */ + protected float y = 0; + + /** + * The page value of the position + */ + protected int page = 0; + + /** + * Whether automatic positioning is used + */ + protected boolean autoPositioning; + + /** + * Default constructor + * No position given, hence automatic positioning will be used + */ + public SignaturePosition() { + this.autoPositioning = true; + } + + /** + * X - Y Constructor (Page = 0) + * @param x The x value of the position + * @param y The y value of the position + */ + public SignaturePosition(float x, float y) { + this.autoPositioning = false; + setPosition(x, y); + } + + /** + * Constructor + * @param x The x value of the signature position + * @param y The y value of the signature position + * @param page The page value of the signature position + */ + public SignaturePosition(float x, float y, int page) { + this.autoPositioning = false; + setPosition(x, y); + setPage(page); + } + + /** + * Sets new position + * @param x the new x value + * @param y the new y value + */ + public void setPosition(float x, float y) { + this.x = x; + this.y = y; + } + + /** + * Gets the X value of the position + * @return float the x value of the position + */ + public float getX() { + return this.x; + } + + /** + * Gets the Y value of the position + * @return float the y value of the position + */ + public float getY() { + return this.y; + } + + /** + * Sets Page value of position + * @param page the new page value + */ + public void setPage(int page) { + this.page = page; + } + + /** + * Gets the Page value of the position + * @return int the page value of the position + */ + public int getPage() { + return this.page; + } + + /** + * Gets whether automatic positioning is used + * @return true if the signature position is determined automatically + */ + public boolean useAutoPositioning() { + return this.autoPositioning; + } +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signer.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signer.java new file mode 100644 index 00000000..fd7bee09 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/Signer.java @@ -0,0 +1,33 @@ +package at.asit.pdfover.signator; + +/** + * PDF Signer base Class + * This class should be extended to support libraries such as PDF-AS or PADES. + */ +public interface Signer { + + /** + * Prepare a signature + * Defines signature parameters, the pdf library prepares the pdf document to sign and + * creates a Security Layer Request. + * @param parameter The signature parameters + * @return The signing state (contains the prepared document and the signature request + * @throws SignatureException + */ + public SigningState prepare(SignatureParameter parameter) throws SignatureException; + + /** + * Adds the signature to the document. + * The SL Response has to be set in the state + * @param state The signing state + * @return The signature Result + * @throws SignatureException + */ + public SignResult sign(SigningState state) throws SignatureException; + + /** + * Creates new signing profile + * @return The new Profile + */ + public SignatureParameter newParameter(); +} diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignerFactory.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignerFactory.java new file mode 100644 index 00000000..6c0b6487 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignerFactory.java @@ -0,0 +1,15 @@ +package at.asit.pdfover.signator; + +import at.asit.pdfover.signator.Signer; + +/** + * A Signer factory + * Creates Signer instances + */ +public abstract class SignerFactory { + /** + * Create a Signer + * @return the new Signer + */ + public abstract Signer createSigner(); +} 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 new file mode 100644 index 00000000..c1e82da3 --- /dev/null +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SigningState.java @@ -0,0 +1,19 @@ +package at.asit.pdfover.signator; + +/** + * The state of the pdf signing library + */ +public interface SigningState { + + /** + * Gets the Security Layer Request to create the signature + * @return The Signature Request + */ + public abstract SLRequest getSignatureRequest(); + + /** + * Sets the Security Layer Response to the Signature Request + * @param value The Signature Response + */ + public abstract void setSignatureResponse(SLResponse value); +} -- cgit v1.2.3