From 3d982813b34f6f230baf4a467cdc37ec92a77595 Mon Sep 17 00:00:00 2001 From: netconomy Date: Fri, 17 Aug 2007 06:10:56 +0000 Subject: Performance git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@167 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../commandline/CommandlineConnectorChooser.java | 167 +++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java (limited to 'src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java') diff --git a/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java b/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java new file mode 100644 index 0000000..2bc6a58 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java @@ -0,0 +1,167 @@ +/** + * + */ +package at.gv.egiz.pdfas.commandline; + +import at.gv.egiz.pdfas.framework.ConnectorFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import at.knowcenter.wag.egov.egiz.PdfASID; +import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; +import at.knowcenter.wag.egov.egiz.framework.SignatorFactory; +import at.knowcenter.wag.egov.egiz.sig.sigid.HotfixIdFormatter; + +/** + * Encapsulates the logic of choosing the correct connector for the commandline + * that can later be created using the ConnectorFactory. + * + * @author wprinz + */ +public class CommandlineConnectorChooser +{ + /** + * The log. + */ + private static Log log = LogFactory.getLog(CommandlineConnectorChooser.class); + + protected static final String BKU = "bku"; //$NON-NLS-1$ + + protected static final String MOA = "moa"; //$NON-NLS-1$ + + public static boolean needsSigId (String connectorId) + { + return !ConnectorFactory.isMOA(connectorId); + } + + public static String chooseCommandlineConnectorForSign(String connectorType) throws ConnectorException + { + log.debug("Choosing Connector for commandline signation..."); + + log.debug("connector type = " + connectorType); + + if (connectorType.equals(BKU)) + { + log.debug("sig_app is BKU ==> DetachedMultipartBKUConnector"); //$NON-NLS-1$ + + return ConnectorFactory.DETACHED_MULTIPART_BKU_CONNECTOR; + } + if (connectorType.equals(MOA)) + { + // TODO MOA detached signing is not allowed at the commandline + log.warn("Detached MOA is not supported on the commandline. -> choosing Base64 temporarily."); + return ConnectorFactory.ENVELOPING_BASE64_MOA_CONNECTOR; + } + + throw new ConnectorException(300, "Unknown connector type '" + connectorType + "' specified."); + } + + public static String chooseCommandlineConnectorForVerify(String connectorType, PdfASID sig_kz, String sig_id, String profile) throws ConnectorException + { + log.debug("Choosing Connector for Commandline verification..."); + + log.debug("connector type = " + connectorType); + log.debug("sig_kz = " + sig_kz); //$NON-NLS-1$ + log.debug("sig_id = " + sig_id); //$NON-NLS-1$ + + if (sig_kz == null) + { + log.debug("sig_kz is null -> chose an old enveloped base64 connector"); //$NON-NLS-1$ + + return chooseEnvelopingBase64ConnectorOld(connectorType); + } + + 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 (old or Hotfix)."); + + if (sig_id == null) + { + log.debug("sig_id is null, which means that it is a MOA signature -> choose a hotfix base64 connector (thus it is moa - it doesn't matter)."); + + return chooseEnvelopingBase64ConnectorHotfix(connectorType); + } + + String[] sig_id_parts = sig_id.split("@"); + if (sig_id_parts.length == 2) + { + log.debug("sig_id has 2 @-separated parts -> choosing old base64 connector"); + + return chooseEnvelopingBase64ConnectorOld(connectorType); + } + if (sig_id_parts[0].equals(HotfixIdFormatter.SIG_ID_PREFIX)) + { + log.debug("sig_id prefix is hotfix -> choosing hotfix base64 connector"); + + return chooseEnvelopingBase64ConnectorHotfix(connectorType); + } + + throw new ConnectorException(300, "The SIG_KZ version is 1.0.0, but SIG_ID is neither MOA nor Old base64 nor Hotfix base64 ???'"); + } + if (sig_kz.getVersion().equals(SignatorFactory.VERSION_1_1_0)) + { + log.debug("Version is 1.1.0 -> chose a detached connector."); + + return chooseDetachedMultipartConnector(connectorType); + } + + throw new ConnectorException(310, "The SIG_KZ version '" + sig_kz.getVersion() + "' is unknown."); + } + + protected static String chooseEnvelopingBase64ConnectorOld(String sig_app) throws ConnectorException + { + if (sig_app.equals(BKU)) + { + log.debug("sig_app is BKU ==> OldEnvelopingBase64BKUConnector"); //$NON-NLS-1$ + + return ConnectorFactory.OLD_ENVELOPING_BASE64_BKU_CONNECTOR; + } + if (sig_app.equals(MOA)) + { + log.debug("sig_app is MOA ==> EnvelopingBase64MOAConnector"); //$NON-NLS-1$ + + return ConnectorFactory.ENVELOPING_BASE64_MOA_CONNECTOR; + } + throw new ConnectorException(310, "Unknown sig_app '" + sig_app + "'."); //$NON-NLS-1$ //$NON-NLS-2$ + + } + + protected static String chooseEnvelopingBase64ConnectorHotfix(String sig_app) throws ConnectorException + { + if (sig_app.equals(BKU)) + { + log.debug("sig_app is BKU ==> EnvelopingBase64BKUConnector"); //$NON-NLS-1$ + + return ConnectorFactory.ENVELOPING_BASE64_BKU_CONNECTOR; + } + if (sig_app.equals(MOA)) + { + log.debug("sig_app is MOA ==> EnvelopingBase64MOAConnector"); //$NON-NLS-1$ + + return ConnectorFactory.ENVELOPING_BASE64_MOA_CONNECTOR; + } + throw new ConnectorException(310, "Unknown sig_app '" + sig_app + "'."); //$NON-NLS-1$ //$NON-NLS-2$ + } + + protected static String chooseDetachedMultipartConnector(String sig_app) throws ConnectorException + { + if (sig_app.equals(BKU)) + { + log.debug("sig_app is BKU ==> DetachedMultipartBKUConnector"); //$NON-NLS-1$ + + return ConnectorFactory.DETACHED_MULTIPART_BKU_CONNECTOR; + } + if (sig_app.equals(MOA)) + { + log.debug("sig_app is MOA ==> DetachedMOAConnector"); //$NON-NLS-1$ + + String msg = "A Detached signature cannot be verified with the MOA connector (yet)."; //$NON-NLS-1$ + log.error(msg); + throw new ConnectorException(370, msg); + } + throw new ConnectorException(310, "Unknown sig_app '" + sig_app + "'."); //$NON-NLS-1$ //$NON-NLS-2$ + } +} -- cgit v1.2.3