summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Abraham <andreas.abraham@egiz.gv.at>2019-12-02 12:54:22 +0100
committerAndreas Abraham <andreas.abraham@egiz.gv.at>2019-12-02 12:54:22 +0100
commit44256e68fc579cb804d56d1fb5525c6c29d8c38b (patch)
treecbb173b3db8b2c1c3b8fb46f9aef3f7360c92742
parenteb8993049ab6341152daa0f2e6a0650be38e8843 (diff)
downloadpdf-over-44256e68fc579cb804d56d1fb5525c6c29d8c38b.tar.gz
pdf-over-44256e68fc579cb804d56d1fb5525c6c29d8c38b.tar.bz2
pdf-over-44256e68fc579cb804d56d1fb5525c6c29d8c38b.zip
signature placeholder (pdf signature annotation) implemented
-rw-r--r--pdf-over-gui/pom.xml5
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java5
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java64
-rw-r--r--pdf-over-gui/src/main/resources/cfg/PDFASConfig.zipbin971912 -> 971868 bytes
-rw-r--r--pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java26
5 files changed, 77 insertions, 23 deletions
diff --git a/pdf-over-gui/pom.xml b/pdf-over-gui/pom.xml
index 94de3e50..a35bc9ac 100644
--- a/pdf-over-gui/pom.xml
+++ b/pdf-over-gui/pom.xml
@@ -61,6 +61,11 @@
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.10</version>
+ </dependency>
</dependencies>
<dependencyManagement>
<dependencies>
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java
index f1ee6165..162fbd15 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java
@@ -44,6 +44,11 @@ public class Constants {
// Has to be set before (implicitly) initializing Display
Display.setAppName(APP_NAME);
}
+
+ /**
+ *
+ */
+ public static final String SIGNATURE_FIELD_NAME_CONF = "signature_field_name";
/** Current display - used for Colors */
private static Display display = Display.getCurrent();
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java
index 9e9d0700..c3681dd8 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java
@@ -18,7 +18,9 @@ package at.asit.pdfover.gui.workflow.states;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;
@@ -46,6 +48,10 @@ import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignatureFieldsExtractor;
import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignaturePlaceholderExtractor;
//import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.configuration.PropertiesConfigurationLayout;
+
/**
* Selects the data source for the signature process.
@@ -64,7 +70,8 @@ public class OpenState extends State {
**/
private static final Logger log = LoggerFactory
.getLogger(OpenState.class);
-
+ private static final String advancedConfig = Constants.CONFIG_DIRECTORY + File.separator + "/cfg/advancedconfig.properties"; //$NON-NLS-1$
+
private DataSourceSelectComposite selectionComposite = null;
private DataSourceSelectComposite getSelectionComposite() {
@@ -140,25 +147,8 @@ public class OpenState extends State {
System.out.println("ok pressed"); //$NON-NLS-1$
getStateMachine().getStatus().setSearchForPlaceholderSignature(true);
- //TODO configure and skip placing
- //TODO fix this
- try {
- String cfgPath = Constants.CONFIG_DIRECTORY + File.separator + "/cfg/advancedconfig.properties"; //$NON-NLS-1$
- FileInputStream in = new FileInputStream(cfgPath);
- Properties props = new Properties();
- props.load(in);
- in.close();
-
- FileOutputStream out = new FileOutputStream(cfgPath); //$NON-NLS-1$
- props.setProperty("signature_field_name", fields.get(res)); //$NON-NLS-1$ //$NON-NLS-2$
- props.store(out, null);
- out.close();
-
- } catch (Exception e) {
- System.err.println(e.getMessage());
- System.err.println(e.getStackTrace());
- }
-
+
+ addPlaceholderSelectionToConfig(fields.get(res));
this.setNextState(new BKUSelectionState(getStateMachine()));
return;
@@ -196,6 +186,40 @@ public class OpenState extends State {
this.setNextState(new PositioningState(getStateMachine()));
}
+
+ /**
+ * The selected placeholder is added to the configuration file
+ * @param selection
+ */
+ @SuppressWarnings("static-method")
+ private void addPlaceholderSelectionToConfig(String selection) {
+ try {
+ FileInputStream in = new FileInputStream(advancedConfig);
+// Properties props = new Properties();
+// props.load(in);
+// in.close();
+//
+//
+//
+// FileOutputStream out = new FileOutputStream(advancedConfig);
+// props.setProperty(Constants.SIGNATURE_FIELD_NAME_CONF, selection); //$NON-NLS-1$
+//
+// props.store(out, null);
+// out.close();
+
+
+ PropertiesConfiguration config = new PropertiesConfiguration();
+ PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(config);
+ layout.load(new InputStreamReader(new FileInputStream(advancedConfig)));
+
+ config.setProperty(Constants.SIGNATURE_FIELD_NAME_CONF, selection);
+ layout.save(new FileWriter(advancedConfig, false));
+
+ } catch (Exception e) {
+ log.error(e.getMessage(), e.getStackTrace());
+ }
+
+ }
/**
* Open the input document selection dialog
diff --git a/pdf-over-gui/src/main/resources/cfg/PDFASConfig.zip b/pdf-over-gui/src/main/resources/cfg/PDFASConfig.zip
index dad6f8a9..4c25ca9d 100644
--- a/pdf-over-gui/src/main/resources/cfg/PDFASConfig.zip
+++ b/pdf-over-gui/src/main/resources/cfg/PDFASConfig.zip
Binary files differ
diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
index abab10bf..c7dba85f 100644
--- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
+++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java
@@ -61,7 +61,10 @@ public class PdfAs4Signer implements Signer {
String sigProfile = sign_para.getPdfAsSignatureProfileId();
String sigEmblem = (sign_para.getEmblem() == null ? null : sign_para.getEmblem().getFileName());
String sigNote = sign_para.getProperty("SIG_NOTE");
-
+ String sigPos = null;
+ if (sign_para.getSignaturePosition() != null) {
+ sigPos = sign_para.getPdfAsSignaturePosition();
+ }
PdfAs pdfas = PdfAs4Helper.getPdfAs();
Configuration config = pdfas.getConfiguration();
if (sigEmblem != null && !sigEmblem.trim().isEmpty()) {
@@ -76,6 +79,9 @@ public class PdfAs4Signer implements Signer {
ByteArrayOutputStream output = new ByteArrayOutputStream();
DataSource input = new ByteArrayDataSource(parameter.getInputDocument().getByteArray());
SignParameter param = PdfAsFactory.createSignParameter(config, input, output);
+ if (sigPos != null) {
+ param.setSignaturePosition(sigPos);
+ }
param.setSignatureProfileId(sigProfile);
String id = UUID.randomUUID().toString();
param.setTransactionId(id);
@@ -128,10 +134,24 @@ public class PdfAs4Signer implements Signer {
pdfas.sign(param);
SignResultImpl result = new SignResultImpl();
+
+ if (param.getSignaturePosition() != null) {
+ TablePos tp = new TablePos(param.getSignaturePosition());
+ SignaturePosition sp;
+ if (tp.isXauto() && tp.isYauto())
+ sp = new SignaturePosition();
+ else if (tp.isPauto())
+ sp = new SignaturePosition(tp.getPosX(), tp.getPosY());
+ else
+ sp = new SignaturePosition(tp.getPosX(), tp.getPosY(), tp.getPage());
+ result.setSignaturePosition(sp);
+ }
+
result.setSignedDocument(new ByteArrayDocumentSource(sstate.getOutput().toByteArray()));
return result;
- }
- catch (PDFASError e) {
+ } catch (PdfAsException e) {
+ throw new SignatureException(e);
+ } catch (PDFASError e) {
throw new SignatureException(e);
}
}