diff options
-rw-r--r-- | src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java | 143 |
1 files changed, 115 insertions, 28 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java index 8de93c0..4f31d14 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -25,10 +25,11 @@ import java.util.Comparator; import java.util.List;
import java.util.Vector;
-import org.apache.log4j.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
-import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorFactoryException;
import at.knowcenter.wag.egov.egiz.exceptions.NormalizeException;
import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
@@ -48,10 +49,9 @@ import at.knowcenter.wag.egov.egiz.pdf.PDFSignatureObject; import at.knowcenter.wag.egov.egiz.pdf.PDFUtilities;
import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction;
import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder;
-import at.knowcenter.wag.egov.egiz.pdf.TextualSignatureHolder;
import at.knowcenter.wag.egov.egiz.pdf.TablePos;
import at.knowcenter.wag.egov.egiz.pdf.TextualSignature;
-import at.knowcenter.wag.egov.egiz.sig.Connector;
+import at.knowcenter.wag.egov.egiz.pdf.TextualSignatureHolder;
import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
import at.knowcenter.wag.egov.egiz.sig.SignatureData;
import at.knowcenter.wag.egov.egiz.sig.SignatureDataImpl;
@@ -59,9 +59,11 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureObject; import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypeDefinition;
import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
-import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUPostConnection;
+import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.DetachedMultipartBKUConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.EnvelopedBase64BKUConnector;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.connectors.moa.EnvelopingBase64MOAConnector;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
import at.knowcenter.wag.egov.egiz.tools.Normalizer;
import at.knowcenter.wag.exactparser.ParseDocument;
@@ -104,7 +106,7 @@ public abstract class PdfAS /**
* The logger definition.
*/
- private static final Logger logger_ = ConfigLogger.getLogger(PdfAS.class);
+ private static final Log log = LogFactory.getLog(PdfAS.class);
/**
* Tells, if strict PDF checking the PDF version is enabled.
@@ -184,7 +186,7 @@ public abstract class PdfAS }
catch (Exception e)
{
- logger_.debug("Error while parsing Document.", e);
+ log.debug("Error while parsing Document.", e);
throw new PDFDocumentException(201, e);
}
}
@@ -267,7 +269,7 @@ public abstract class PdfAS break;
}
{
- logger_.debug("Found holder: " + holder.getSignatureObject().getSignationType());
+ log.debug("Found holder: " + holder.getSignatureObject().getSignationType());
}
signature_holders.add(0, holder);
@@ -316,22 +318,22 @@ public abstract class PdfAS if (minimum_blocks.size() > 1)
{
- logger_.debug("There are still " + minimum_blocks.size() + " candidates:");
+ log.debug("There are still " + minimum_blocks.size() + " candidates:");
for (int i = 0; i < minimum_blocks.size(); i++)
{
FoundBlock fb = (FoundBlock) minimum_blocks.get(i);
- logger_.debug(" fb: " + fb.std.getType());
+ log.debug(" fb: " + fb.std.getType());
}
- logger_.debug("... checking for Semantic Equality.");
+ log.debug("... checking for Semantic Equality.");
}
boolean semantic_equality = checkForSemanticEquality(minimum_blocks);
if (minimum_blocks.size() > 1)
{
- logger_.debug("... Semantic Equality = " + semantic_equality);
+ log.debug("... Semantic Equality = " + semantic_equality);
}
if (!semantic_equality)
@@ -409,10 +411,10 @@ public abstract class PdfAS // int found_index = text.lastIndexOf(caption);
// we're searching for captions that start at the beginning of the line.
int found_index = text.lastIndexOf("\n" + caption) + 1;// text.lastIndexOf("\n"
- // + caption) + 1;
- // // the +1
- // text.lastIndexOf(caption)
- // + 1; //
+ // + caption) + 1;
+ // // the +1
+ // text.lastIndexOf(caption)
+ // + 1; //
// compensates the
// \n
if (found_index == 0)
@@ -420,7 +422,7 @@ public abstract class PdfAS // try without /n
found_index = text.lastIndexOf(caption);
}
- logger_.debug("found key:" + caption + " at index:" + found_index);
+ log.debug("found key:" + caption + " at index:" + found_index);
if (key.equals(SignatureTypes.SIG_ID))
{
if (found_index < 0 || found_index >= last_index)
@@ -809,8 +811,6 @@ public abstract class PdfAS try
{
- DetachedMultipartBKUConnector connector_impl = new DetachedMultipartBKUConnector("xxxprofile");
-
// FIXME this has to be made better
SignatureData sd = null;
if (so_to_be_verified.isBinary())
@@ -822,13 +822,17 @@ public abstract class PdfAS {
sd = new SignatureDataImpl(text_to_be_verified.getBytes("UTF-8"), "text/plain", "UTF-8");
}
-
+
SignSignatureObject so = new SignSignatureObject();
so.date = so_to_be_verified.getSignationDate();
so.signatureValue = so_to_be_verified.getSignationValue();
so.issuer = so_to_be_verified.getSignationIssuer();
so.x509Certificate = so_to_be_verified.getX509Cert().getX509Certificate();
so.id = so_to_be_verified.getSignationIds();
+ so.kz = so_to_be_verified.getKZ().toString();
+
+ String profile = so_to_be_verified.getSignatureTypeDefinition().getType();
+ Connector connector_impl = chooseConnector(profile, so_to_be_verified.getKZ(), so.getSigID(), connector);
// Connector connector_impl = ConnectorFactory.createConnector(connector);
return connector_impl.doVerify(sd, so);
@@ -869,20 +873,15 @@ public abstract class PdfAS try
{
- // TODO temporary workaround:
- DetachedMultipartBKUConnector connector_impl = new DetachedMultipartBKUConnector(signature_type);
- // Connector connector_impl = ConnectorFactory.createConnector(connector);
+ Connector connector_impl = chooseDetachedMultipartConnector(signature_type, connector);
+
SignSignatureObject signed_signature_object = connector_impl.doSign(data_to_sign);
return signed_signature_object;
}
- catch (SettingsException e)
+ catch (ConnectorFactoryException e)
{
throw new SignatureException(300, e);
}
- // catch (ConnectorFactoryException e)
- // {
- // throw new SignatureException(300, e);
- // }
}
/**
@@ -1332,4 +1331,92 @@ public abstract class PdfAS TablePos pos = new TablePos(pos_string);
return pos;
}
+
+ /**
+ *
+ * @param sig_kz
+ * @param sig_id
+ * @return Returns the chosen Connector.
+ * @throws ConnectorFactoryException
+ */
+ public static at.knowcenter.wag.egov.egiz.sig.connectors.Connector chooseConnector(
+ String profile,
+ PdfASID sig_kz, String sig_id, String sig_app) throws ConnectorFactoryException, ConnectorException
+ {
+ log.debug("chooseConnector:"); //$NON-NLS-1$
+
+ log.debug("sig_kz = " + sig_kz); //$NON-NLS-1$
+ log.debug("sig_id = " + sig_id); //$NON-NLS-1$
+ log.debug("sig_app = " + sig_app); //$NON-NLS-1$
+
+ if (sig_kz == null)
+ {
+ log.debug("sig_kz is null ==> alte Signatur"); //$NON-NLS-1$
+
+ return chooseEnvelopedBase64Connector(profile, sig_app);
+ }
+
+ {
+ log.debug("sig_kz is not null ==> one of the newer signatures");
+
+ if (sig_kz.getVersion().equals(SignatorFactory.VERSION_1_0_0))
+ {
+ log.debug("Version is 1.0.0 ==> Base64 Signatur eventuell Hotfix.");
+
+ return chooseEnvelopedBase64Connector(profile, sig_app);
+ }
+ if (sig_kz.getVersion().equals(SignatorFactory.VERSION_1_1_0))
+ {
+ log.debug("Version is 1.1.0 ==> Detached Multipart Signatur.");
+
+ return chooseDetachedMultipartConnector(profile, sig_app);
+ }
+ }
+
+ log.debug("chooseConnector."); //$NON-NLS-1$
+ return null;
+ }
+
+ protected static final String BKU = "bku"; //$NON-NLS-1$
+
+ protected static final String MOA = "moa"; //$NON-NLS-1$
+
+ protected static at.knowcenter.wag.egov.egiz.sig.connectors.Connector chooseEnvelopedBase64Connector(
+ String profile, String sig_app) throws ConnectorFactoryException, ConnectorException
+ {
+ if (sig_app.equals(BKU))
+ {
+ log.debug("sig_app is BKU ==> EnvelopedBase64BKUConnector"); //$NON-NLS-1$
+
+ return new EnvelopedBase64BKUConnector(profile);
+ }
+ if (sig_app.equals(MOA))
+ {
+ log.debug("sig_app is MOA ==> EnvelopedBase64MOAConnector"); //$NON-NLS-1$
+
+ return new EnvelopingBase64MOAConnector(profile);
+ }
+ throw new ConnectorFactoryException("Unknown sig_app '" + sig_app + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+
+ protected static at.knowcenter.wag.egov.egiz.sig.connectors.Connector chooseDetachedMultipartConnector(
+ String profile, String sig_app) throws ConnectorException, ConnectorFactoryException
+ {
+ if (sig_app.equals(BKU))
+ {
+ log.debug("sig_app is BKU ==> DetachedMultipartBKUConnector"); //$NON-NLS-1$
+
+ return new DetachedMultipartBKUConnector(profile);
+ }
+ if (sig_app.equals(MOA))
+ {
+ log.debug("sig_app is MOA ==> EnvelopedBase64MOAConnector"); //$NON-NLS-1$
+
+ return null;
+ }
+ throw new ConnectorFactoryException("Unknown sig_app '" + sig_app + "'."); //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+
}
|