From 11dd7f9d647b1ac8af91dc8aab82743a74a1cbaf Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Wed, 8 Oct 2014 17:58:35 +0200 Subject: Verifier System updated --- .../gv/egiz/pdfas/lib/impl/verify/IVerifier.java | 3 +++ .../pdfas/lib/impl/verify/IntegrityVerifier.java | 8 +++++- .../pdfas/lib/impl/verify/VerifierDispatcher.java | 30 +++++++++++++++++----- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/IVerifier.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/IVerifier.java index 7badb9be..ab39f060 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/IVerifier.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/IVerifier.java @@ -5,6 +5,7 @@ import java.util.List; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.lib.api.Configuration; +import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter.SignatureVerificationLevel; import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; public interface IVerifier { @@ -12,4 +13,6 @@ public interface IVerifier { byte[] signatureContent, Date verificationTime) throws PdfAsException; public void setConfiguration(Configuration config); + + public SignatureVerificationLevel getLevel(); } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/IntegrityVerifier.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/IntegrityVerifier.java index 01604a6b..bb0f3268 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/IntegrityVerifier.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/IntegrityVerifier.java @@ -19,12 +19,13 @@ import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.common.exceptions.PdfAsException; import at.gv.egiz.pdfas.common.exceptions.PdfAsSignatureException; import at.gv.egiz.pdfas.lib.api.Configuration; +import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter.SignatureVerificationLevel; import at.gv.egiz.pdfas.lib.api.verify.VerifyResult; public class IntegrityVerifier implements IVerifier { private static final Logger logger = LoggerFactory - .getLogger(FullVerifier.class); + .getLogger(IntegrityVerifier.class); public List verify(byte[] signature, byte[] signatureContent, Date verificationTime) throws PdfAsException { @@ -92,4 +93,9 @@ public class IntegrityVerifier implements IVerifier { public void setConfiguration(Configuration config) { } + + @Override + public SignatureVerificationLevel getLevel() { + return SignatureVerificationLevel.INTEGRITY_ONLY_VERIFICATION; + } } diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java index 6851865b..56ac41a6 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/verify/VerifierDispatcher.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.ServiceLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,6 +54,21 @@ public class VerifierDispatcher { public Map> filterMap = new HashMap>(); + private static List verifiers = new ArrayList(); + + private static ServiceLoader verfierLoader = ServiceLoader + .load(IVerifier.class); + + static { + for (IVerifier verfier : verfierLoader) { + verifiers.add(verfier); + } + + for (IVerifier verfier : verifiers) { + logger.info("Registered Verifier: " + verfier.getClass().getName()); + } + } + private String[] getClasses(ISettings settings) { String confVerifiers = settings.getValue(CONF_VERIFIER_LIST); String[] classes; @@ -140,7 +156,7 @@ public class VerifierDispatcher { } } } catch (Throwable e) { - e.printStackTrace(); + logger.error("Failed to create Verifing dispatcher", e); } } @@ -154,12 +170,12 @@ public class VerifierDispatcher { return filters.get(subfilter); } - public IVerifier getVerifierByLevel(SignatureVerificationLevel level) { - switch (level) { - case INTEGRITY_ONLY_VERIFICATION: - return new IntegrityVerifier(); - default: - return new FullVerifier(); + public IVerifier getVerifierByLevel(SignatureVerificationLevel level) throws PdfAsException { + for (IVerifier verifier : verifiers) { + if(verifier.getLevel().equals(level)) { + return verifier; + } } + throw new PdfAsException("No Verifier with level " + level.toString() + " available!"); } } -- cgit v1.2.3