aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pdf-as-cli/src/main/resources/logback.xml16
-rw-r--r--pdf-as-common/build.gradle2
-rw-r--r--pdf-as-lib/build.gradle2
-rw-r--r--pdf-as-lib/src/configuration/cfg/logback.xml16
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/preprocessor/PreProcessor.java28
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java62
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/DebugPreProcessor.java69
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/PreProcessorCompare.java25
-rw-r--r--pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/PreProcessorLoader.java44
-rw-r--r--pdf-as-lib/src/main/resources/META-INF/services/at.gv.egiz.pdfas.lib.api.preprocessor.PreProcessor1
-rw-r--r--pdf-as-moa/build.gradle1
-rw-r--r--pdf-as-tests/build.gradle1
-rw-r--r--pdf-as-web/build.gradle2
13 files changed, 259 insertions, 10 deletions
diff --git a/pdf-as-cli/src/main/resources/logback.xml b/pdf-as-cli/src/main/resources/logback.xml
new file mode 100644
index 00000000..102931af
--- /dev/null
+++ b/pdf-as-cli/src/main/resources/logback.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>%date{ISO8601} [%thread] %-5level %class - %msg%n</Pattern>
+ </layout>
+ </appender>
+
+ <logger name="at.gv.egiz" level="DEBUG"/>
+ <logger name="at.knowcenter" level="INFO"/>
+
+ <root level="DEBUG">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration> \ No newline at end of file
diff --git a/pdf-as-common/build.gradle b/pdf-as-common/build.gradle
index 63335233..a2e1ee13 100644
--- a/pdf-as-common/build.gradle
+++ b/pdf-as-common/build.gradle
@@ -17,7 +17,7 @@ task releases(type: Copy) {
}
dependencies {
- compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.5'
+ compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '1.8.5'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
diff --git a/pdf-as-lib/build.gradle b/pdf-as-lib/build.gradle
index e82bbc7b..5d2b8689 100644
--- a/pdf-as-lib/build.gradle
+++ b/pdf-as-lib/build.gradle
@@ -66,7 +66,7 @@ dependencies {
compile files('libs/iaik_eccelerate.jar')
compile files('libs/iaik_jce_full.jar')
compile files('libs/iaik_cms.jar')
- compile group: 'log4j', name: 'log4j', version: '1.2.17'
+ compile 'ch.qos.logback:logback-classic:1.1.2'
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
compile group: 'com.google.zxing', name: 'core', version: '3.1.0'
compile group: 'com.google.zxing', name: 'javase', version: '3.1.0'
diff --git a/pdf-as-lib/src/configuration/cfg/logback.xml b/pdf-as-lib/src/configuration/cfg/logback.xml
new file mode 100644
index 00000000..3665f8f0
--- /dev/null
+++ b/pdf-as-lib/src/configuration/cfg/logback.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>%date{ISO8601} [%thread] %-5level %class - %msg%n</Pattern>
+ </layout>
+ </appender>
+
+ <logger name="at.gv.egiz" level="INFO"/>
+ <logger name="at.knowcenter" level="INFO"/>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration> \ No newline at end of file
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/preprocessor/PreProcessor.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/preprocessor/PreProcessor.java
index a70d31d7..1621843a 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/preprocessor/PreProcessor.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/preprocessor/PreProcessor.java
@@ -1,6 +1,7 @@
package at.gv.egiz.pdfas.lib.api.preprocessor;
import at.gv.egiz.pdfas.common.exceptions.PDFASError;
+import at.gv.egiz.pdfas.lib.api.Configuration;
import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter;
@@ -10,7 +11,15 @@ import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter;
public interface PreProcessor {
/**
- * Sign.
+ * Initialize this instance. This Method is called once when the
+ * PreProcessor is constructed!
+ *
+ * @param configuration the configuration
+ */
+ public void initialize(Configuration configuration);
+
+ /**
+ * Sign. This Method is called once for each sign call.
*
* @param parameter the parameter
* @throws PDFASError the PDFAS error
@@ -18,7 +27,7 @@ public interface PreProcessor {
public void sign(SignParameter parameter) throws PDFASError;
/**
- * Verify.
+ * Verify. This Method is called once for each verify call.
*
* @param parameter the parameter
* @throws PDFASError the PDFAS error
@@ -27,9 +36,20 @@ public interface PreProcessor {
/**
- * Registration position.
- *
+ * The Position in which the PreProcessor should be registered.
+ * Lowest positions will be executed first.
+ *
+ * Negative values mean that PDF-AS chooses where to register the PreProcessor
+ * This should be used if the PreProcessor has no dependencies.
+ *
* @return the int
*/
public int registrationPosition();
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName();
}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
index a94f63ad..85a11d0d 100644
--- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/PdfAsImpl.java
@@ -34,6 +34,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Iterator;
import java.util.List;
import org.apache.commons.io.IOUtils;
@@ -61,6 +62,7 @@ import at.gv.egiz.pdfas.lib.api.Configuration;
import at.gv.egiz.pdfas.lib.api.IConfigurationConstants;
import at.gv.egiz.pdfas.lib.api.PdfAs;
import at.gv.egiz.pdfas.lib.api.StatusRequest;
+import at.gv.egiz.pdfas.lib.api.preprocessor.PreProcessor;
import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
import at.gv.egiz.pdfas.lib.api.sign.SignResult;
import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter;
@@ -68,6 +70,7 @@ import at.gv.egiz.pdfas.lib.api.verify.VerifyResult;
import at.gv.egiz.pdfas.lib.impl.configuration.ConfigurationImpl;
import at.gv.egiz.pdfas.lib.impl.configuration.SignatureProfileConfiguration;
import at.gv.egiz.pdfas.lib.impl.positioning.Positioning;
+import at.gv.egiz.pdfas.lib.impl.preprocessor.PreProcessorLoader;
import at.gv.egiz.pdfas.lib.impl.signing.IPdfSigner;
import at.gv.egiz.pdfas.lib.impl.signing.PdfSignerFactory;
import at.gv.egiz.pdfas.lib.impl.signing.pdfbox.PdfboxSignerWrapper;
@@ -155,6 +158,9 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants,
throw new PdfAsSettingsException("Invalid settings object!");
}
+ // execute pre Processors
+ signPreProcessing(parameter);
+
ISettings settings = (ISettings) parameter.getConfiguration();
status = new OperationStatus(settings, parameter);
@@ -217,6 +223,9 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants,
verifyVerifyParameter(parameter);
+ // execute pre Processors
+ verifyPreProcessing(parameter);
+
int signatureToVerify = parameter.getWhichSignature();
int currentSignature = 0;
PDDocument doc = null;
@@ -369,6 +378,9 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants,
throw new PdfAsSettingsException("Invalid settings object!");
}
+ // execute pre Processors
+ signPreProcessing(parameter);
+
ISettings settings = (ISettings) parameter.getConfiguration();
OperationStatus status = new OperationStatus(settings, parameter);
@@ -502,6 +514,56 @@ public class PdfAsImpl implements PdfAs, IConfigurationConstants,
}
}
+ private void listPreProcessors(List<PreProcessor> preProcessors) {
+ logger.debug("--------------");
+ logger.debug("Listing PreProcessors:");
+
+ Iterator<PreProcessor> preProcessorsIterator = preProcessors.iterator();
+ int idx = 0;
+ while(preProcessorsIterator.hasNext()) {
+ PreProcessor preProcessor = preProcessorsIterator.next();
+ logger.debug("{}: {} [{}]", idx, preProcessor.getName(), preProcessor.getClass().getName());
+ idx++;
+ }
+ logger.debug("--------------");
+ }
+
+ private void verifyPreProcessing(VerifyParameter parameter) throws PDFASError {
+ List<PreProcessor> preProcessors = PreProcessorLoader.getPreProcessors(parameter.getConfiguration());
+
+ listPreProcessors(preProcessors);
+
+ logger.debug("executing PreProcessors for verifing:");
+ Iterator<PreProcessor> preProcessorsIterator = preProcessors.iterator();
+
+ while(preProcessorsIterator.hasNext()) {
+ PreProcessor preProcessor = preProcessorsIterator.next();
+ logger.debug("executing: {} [{}]", preProcessor.getName(), preProcessor.getClass().getName());
+ preProcessor.verify(parameter);
+ logger.debug("done executing: {} [{}]", preProcessor.getName(), preProcessor.getClass().getName());
+ }
+
+ logger.debug("executing PreProcessors for verifing done");
+ }
+
+ private void signPreProcessing(SignParameter parameter) throws PDFASError {
+ List<PreProcessor> preProcessors = PreProcessorLoader.getPreProcessors(parameter.getConfiguration());
+
+ listPreProcessors(preProcessors);
+
+ logger.debug("executing PreProcessors for signing:");
+ Iterator<PreProcessor> preProcessorsIterator = preProcessors.iterator();
+
+ while(preProcessorsIterator.hasNext()) {
+ PreProcessor preProcessor = preProcessorsIterator.next();
+ logger.debug("executing: {} [{}]", preProcessor.getName(), preProcessor.getClass().getName());
+ preProcessor.sign(parameter);
+ logger.debug("done executing: {} [{}]", preProcessor.getName(), preProcessor.getClass().getName());
+ }
+
+ logger.debug("executing PreProcessors for signing done");
+ }
+
private SignResult createSignResult(OperationStatus status)
throws IOException {
// ================================================================
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/DebugPreProcessor.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/DebugPreProcessor.java
new file mode 100644
index 00000000..1a262aca
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/DebugPreProcessor.java
@@ -0,0 +1,69 @@
+package at.gv.egiz.pdfas.lib.impl.preprocessor;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.egiz.pdfas.common.exceptions.PDFASError;
+import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.preprocessor.PreProcessor;
+import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter;
+
+public class DebugPreProcessor implements PreProcessor {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(DebugPreProcessor.class);
+
+ private static final String NAME = "Debug PreProcessor";
+
+ @Override
+ public void initialize(Configuration configuration) {
+ logger.debug("Initializing {}", getName());
+ }
+
+ private void listPPArguments(Map<String, String> map) {
+ if(map != null) {
+ logger.debug("pre processor arguments:");
+ Iterator<Entry<String, String>> entryIt = map.entrySet().iterator();
+ while(entryIt.hasNext()) {
+ Entry<String, String> entry = entryIt.next();
+ logger.debug(" {} => {}", entry.getKey(), entry.getValue());
+ }
+ } else {
+ logger.debug("No pre processor arguments");
+ }
+ }
+
+ @Override
+ public void sign(SignParameter parameter) throws PDFASError {
+ logger.debug("preprocessor signing ...");
+
+ listPPArguments(parameter.getPreprocessorArguments());
+
+ logger.debug("preprocessor signing done");
+ }
+
+ @Override
+ public void verify(VerifyParameter parameter) throws PDFASError {
+ logger.debug("preprocessor verifing ...");
+
+ listPPArguments(parameter.getPreprocessorArguments());
+
+ logger.debug("preprocessor verifing done");
+ }
+
+ @Override
+ public int registrationPosition() {
+ return -1;
+ }
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/PreProcessorCompare.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/PreProcessorCompare.java
new file mode 100644
index 00000000..ef716403
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/PreProcessorCompare.java
@@ -0,0 +1,25 @@
+package at.gv.egiz.pdfas.lib.impl.preprocessor;
+
+import java.util.Comparator;
+
+import at.gv.egiz.pdfas.lib.api.preprocessor.PreProcessor;
+
+public class PreProcessorCompare implements Comparator<PreProcessor> {
+
+ @Override
+ public int compare(PreProcessor o1, PreProcessor o2) {
+ if(o1.registrationPosition() < 0 && o2.registrationPosition() < 0) {
+ // equal
+ return 0;
+ } else if(o1.registrationPosition() < 0) {
+ // o2 vor o1
+ return 1;
+ } else if(o2.registrationPosition() < 0) {
+ // o1 vor o2
+ return -1;
+ } else {
+ return Integer.compare(o1.registrationPosition(), o2.registrationPosition());
+ }
+ }
+
+}
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/PreProcessorLoader.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/PreProcessorLoader.java
new file mode 100644
index 00000000..91218c82
--- /dev/null
+++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/preprocessor/PreProcessorLoader.java
@@ -0,0 +1,44 @@
+package at.gv.egiz.pdfas.lib.impl.preprocessor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ServiceLoader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.egiz.pdfas.lib.api.Configuration;
+import at.gv.egiz.pdfas.lib.api.preprocessor.PreProcessor;
+
+public class PreProcessorLoader {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(PreProcessorLoader.class);
+
+ private static ServiceLoader<PreProcessor> preProcessorLoader = ServiceLoader.load(PreProcessor.class);
+
+ public static List<PreProcessor> getPreProcessors(Configuration configuration) {
+ logger.debug("building PreProcessors");
+
+ List<PreProcessor> processors = new ArrayList<PreProcessor>();
+ Iterator<PreProcessor> processorIterator = preProcessorLoader.iterator();
+
+ while(processorIterator.hasNext()) {
+ PreProcessor preProcessor = processorIterator.next();
+ logger.debug("Loading " + preProcessor.getName() + " [" + preProcessor.getClass().getName() + "]");
+ preProcessor.initialize(configuration);
+ logger.debug("Initialized " + preProcessor.getName());
+ processors.add(preProcessor);
+ logger.debug("Preprocessor added " + preProcessor.getName());
+ }
+
+ logger.debug("PreProcessors constructed");
+
+ Collections.sort(processors, new PreProcessorCompare());
+
+ logger.debug("PreProcessors sorted");
+ return processors;
+ }
+}
diff --git a/pdf-as-lib/src/main/resources/META-INF/services/at.gv.egiz.pdfas.lib.api.preprocessor.PreProcessor b/pdf-as-lib/src/main/resources/META-INF/services/at.gv.egiz.pdfas.lib.api.preprocessor.PreProcessor
new file mode 100644
index 00000000..d9d2cd96
--- /dev/null
+++ b/pdf-as-lib/src/main/resources/META-INF/services/at.gv.egiz.pdfas.lib.api.preprocessor.PreProcessor
@@ -0,0 +1 @@
+at.gv.egiz.pdfas.lib.impl.preprocessor.DebugPreProcessor \ No newline at end of file
diff --git a/pdf-as-moa/build.gradle b/pdf-as-moa/build.gradle
index c00c456b..0ae64724 100644
--- a/pdf-as-moa/build.gradle
+++ b/pdf-as-moa/build.gradle
@@ -46,7 +46,6 @@ repositories {
dependencies {
compile project (':pdf-as-lib')
- compile group: 'log4j', name: 'log4j', version: '1.2.17'
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
testCompile group: 'junit', name: 'junit', version: '4.+'
ws group: 'org.apache.cxf', name: 'cxf-tools', version: cxfVersion
diff --git a/pdf-as-tests/build.gradle b/pdf-as-tests/build.gradle
index 6d964735..4877f404 100644
--- a/pdf-as-tests/build.gradle
+++ b/pdf-as-tests/build.gradle
@@ -19,7 +19,6 @@ dependencies {
testCompile project (':pdf-as-moa')
compile project (':signature-standards:sigs-pkcs7detached')
compile project (':signature-standards:sigs-pades')
- compile group: 'log4j', name: 'log4j', version: '1.2.17'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.7'
testCompile group: 'junit', name: 'junit', version: '4.+'
testCompile group: 'org.apache.pdfbox', name: 'preflight', version: '1.8.7'
diff --git a/pdf-as-web/build.gradle b/pdf-as-web/build.gradle
index d854a365..15fe8b3d 100644
--- a/pdf-as-web/build.gradle
+++ b/pdf-as-web/build.gradle
@@ -21,8 +21,6 @@ dependencies {
compile project (':signature-standards:sigs-pkcs7detached')
compile project (':signature-standards:sigs-pades')
compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1'
- compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.7'
- compile 'org.slf4j:slf4j-log4j12:1.7.7'
compile group: 'opensymphony', name: 'sitemesh', version: '2.4.2'
compile "commons-codec:commons-codec:1.9"
compile 'org.apache.commons:commons-lang3:3.3.2'