From 784b2b91ee43310810dd7893f6f0ac404adba185 Mon Sep 17 00:00:00 2001 From: knowcenter Date: Mon, 16 Jul 2007 15:28:00 +0000 Subject: BKU and MOA signing templates versioning implemented. See config.paramter file for changes/options git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@127 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../wag/egov/egiz/cfg/SettingsReader.java | 1 + .../knowcenter/wag/egov/egiz/commandline/Main.java | 8 ++-- .../wag/egov/egiz/pdf/BinarySignature.java | 1 + .../wag/egov/egiz/sig/ConnectorFactory.java | 28 +++++++++++-- .../egov/egiz/sig/connectors/ConnectorChooser.java | 47 +++++++++++++++++----- .../sig/connectors/bku/DetachedBKUConnector.java | 2 +- .../connectors/moa/DetachedLocRefMOAConnector.java | 4 +- .../egov/egiz/sig/sigid/DetachedIdFormatter.java | 26 +++++++++++- .../sig/sigid/DetachedLocRefMOAIdFormatter.java | 17 +++++++- 9 files changed, 110 insertions(+), 24 deletions(-) (limited to 'src/main/java/at/knowcenter/wag/egov') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java index a884140..96286ad 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java @@ -303,6 +303,7 @@ public class SettingsReader implements Settings, Serializable // load properties from current package! // properties_.load(getClass().getResourceAsStream(settingsFile_)); Enumeration prop_keys = properties_.propertyNames(); + while (prop_keys.hasMoreElements()) { String key = (String) prop_keys.nextElement(); diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java index 73ee69a..989bbd4 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java @@ -152,7 +152,7 @@ public abstract class Main SettingsReader.initializeForCommandLine(); PropertyConfigurator.configure(SettingsReader.CONFIG_PATH + "log4j.properties"); - + try { // printUsage(System.out); @@ -170,7 +170,7 @@ public abstract class Main String input = null; String output = null; - + // for (int i = 0; i < args.length; i++) // { // logger_.debug("arg[" + i + "] = " + args[i]); @@ -470,13 +470,15 @@ public abstract class Main } } - + PdfASID algorithm = translateSignatureModeToPdfASID(signature_mode); // TODO MOA detached signing is not allowed at the commandline logger_.debug("Suggested sign algorithm = " + algorithm); if (connector.equals("moa")) { + // TODO: possible new implementation of moa where is commandline call supported + // it should be checked in config file is it allowed to use MOA detached from command line. String msg = "Hinweis: Der MOA Detached Connector ist für die Kommandozeile nicht geeignet. Die Signatur wird daher im alten Base64 enveloping Format ausgeführt."; System.out.println(msg); logger_.warn(msg); diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java index 52d1d9f..fb93fbd 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java @@ -374,6 +374,7 @@ public abstract class BinarySignature { // byte[] digest = buildDigest(data, ods); String raw_text = CodingHelper.encodeBase64(data);// digest); // data); + return raw_text; } diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/ConnectorFactory.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/ConnectorFactory.java index d75b915..6ce7b03 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/ConnectorFactory.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/ConnectorFactory.java @@ -49,6 +49,8 @@ public abstract class ConnectorFactory *

*/ protected static final String CONNECTOR_INFORMATION_FIELD_NAME = "CONNECTOR_INFORMATION"; + + protected static final String MOA_SIG_ID_VISIBLE_KEY = "moa.sign.id.active"; /** * The list of available Connector implementations. @@ -320,9 +322,27 @@ public abstract class ConnectorFactory */ public static boolean needsSIG_ID(String connector) { - // all modernn detached signatures have the SIG_ID field. - return true; - //return !connector.equals("moa"); + boolean return_result = true; + + if(connector.contains("moa")) + { + String moa_sig_id_visible = null; + + try + { + moa_sig_id_visible = SettingsReader.getInstance().getValueFromKey(MOA_SIG_ID_VISIBLE_KEY); + + if(!moa_sig_id_visible.equals("true"))// || moa_sig_id_visible == null) + return_result = false; + } + catch (SettingsException e) + { + String log_message = "Can not load signature settings. Cause:\n" + e.getMessage(); + logger_.error(log_message); + throw new RuntimeException(e); + } + } + + return return_result; } - } diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/ConnectorChooser.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/ConnectorChooser.java index 4dcd1b5..4c63ebf 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/ConnectorChooser.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/ConnectorChooser.java @@ -7,7 +7,10 @@ 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.cfg.SettingsReader; import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException; +import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException; +import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; import at.knowcenter.wag.egov.egiz.framework.SignatorFactory; import at.knowcenter.wag.egov.egiz.sig.connectors.bku.EnvelopedBase64BKUConnector; import at.knowcenter.wag.egov.egiz.sig.connectors.bku.LocRefDetachedBKUConnector; @@ -28,15 +31,19 @@ public final class ConnectorChooser /** * The log. */ - private static Log log = LogFactory.getLog(ConnectorChooser.class); + private static Log log = LogFactory.getLog(ConnectorChooser.class); + private static final String MOA_CMD_LINE_SUPPORTED_KEY = "moa.sign.cmd.detached"; + /* + * Called when we try to connect BKU over Web interface + */ public static LocalConnector chooseLocalConnectorForSign(String connector, String profile, String loc_ref_url) throws ConnectorException { log.debug("Choosing LocalConnector for signation..."); log.debug("connector type = " + connector); - + if (!connector.equals("bku")) { log.error("Currently only the BKU connector is fully implemented."); @@ -63,23 +70,43 @@ public final class ConnectorChooser } public static Connector chooseCommandlineConnectorForSign(String connector, - String profile) throws ConnectorException + String profile) throws ConnectorException, SettingNotFoundException { log.debug("Choosing Connector for commandline signation..."); log.debug("connector type = " + connector); if (connector.equals(BKU)) - { - log.debug("sig_app is BKU ==> MultipartDetachedBKUConnector"); //$NON-NLS-1$ - + { + log.debug("sig_app is BKU ==> MultipartDetachedBKUConnector"); //$NON-NLS-1 + return new MultipartDetachedBKUConnector(profile); } + if (connector.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 new EnvelopingBase64MOAConnector(profile); + { + try { + String cmd_supported = SettingsReader.getInstance().getValueFromKey(MOA_CMD_LINE_SUPPORTED_KEY); + + if(cmd_supported.equals("true")) + { + //TODO: replace hardcoded constants!!! + return new DetachedLocRefMOAConnector(profile, "formdata:fileupload"); + } + else + { + // TODO MOA detached signing is not allowed at the commandline + log.warn("Detached MOA is not supported on the commandline. -> choosing Base64 temporarily."); + + return new EnvelopingBase64MOAConnector(profile); + } + + } catch (SettingsException e) { + e.printStackTrace(); + } + //if() + //return new DetachedLocRefMOAConnector(profile, "formdata:fileupload"); + //return new EnvelopingBase64MOAConnector(profile); } throw new ConnectorException(300, "Unknown connector type '" + connector + "' specified."); diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java index 9713a4a..4895dd8 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java @@ -450,7 +450,7 @@ public class DetachedBKUConnector implements Connector, LocalConnector /** * The configuration key of the sign request template. */ - protected static final String SIGN_REQUEST_TEMPLATE_KEY = "bku.sign.request.detached"; //$NON-NLS-1$ + protected static final String SIGN_REQUEST_TEMPLATE_KEY = "bku.sign.request.template"; //$NON-NLS-1$ /** * The configuration key of the sign URL. diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java index 98d381a..eca728f 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java @@ -37,7 +37,7 @@ public class DetachedLocRefMOAConnector implements Connector /** * The SIG_ID prefix. */ - public static final String SIG_ID_PREFIX = "etsi-bku-detached@"; //$NON-NLS-1$ + //public static final String SIG_ID_PREFIX = "etsi-bku-detached@"; //$NON-NLS-1$ /** * The log. @@ -316,7 +316,7 @@ public class DetachedLocRefMOAConnector implements Connector /** * The configuration key of the sign request template. */ - protected static final String SIGN_REQUEST_TEMPLATE_KEY = "moa.sign.request.detached"; //$NON-NLS-1$ + protected static final String SIGN_REQUEST_TEMPLATE_KEY = "moa.sign.request.template"; //$NON-NLS-1$ /** * The configuration key of the sign URL. diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedIdFormatter.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedIdFormatter.java index 25e4504..f951b47 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedIdFormatter.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedIdFormatter.java @@ -6,16 +6,21 @@ package at.knowcenter.wag.egov.egiz.sig.sigid; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; +import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; + /** * @author wprinz * */ public class DetachedIdFormatter implements IdFormatter { + // last change: erno & arian; 16.07.2007 13:17 + public static final String DEFAULT_BKU_SIG_ID = "default.bku.signature.id"; /** * The SIG_ID prefix. */ - public static final String SIG_ID_PREFIX = "etsi-bku-detached"; //$NON-NLS-1$ + public static String SIG_ID_PREFIX = null; /** * The log. @@ -27,6 +32,10 @@ public class DetachedIdFormatter implements IdFormatter */ public String formatIds(String[] ids) { + // if SIG_ID_PREFIX null is, call read the config file and set the value from it + if(SIG_ID_PREFIX == null) + setPrefixId(); + // ids algorithm: String join = ""; //$NON-NLS-1$ String base = null; @@ -54,5 +63,18 @@ public class DetachedIdFormatter implements IdFormatter String final_ids = SIG_ID_PREFIX + "@" + idstr; return final_ids; } - + + /* + * Read configuration from file and set it to global variable + */ + public void setPrefixId() + { + try + { + SIG_ID_PREFIX = SettingsReader.getInstance().getValueFromKey(DEFAULT_BKU_SIG_ID); + } catch (SettingsException e) + { + e.printStackTrace(); + } + } } diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedLocRefMOAIdFormatter.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedLocRefMOAIdFormatter.java index f1060fb..5cfd4fb 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedLocRefMOAIdFormatter.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/sigid/DetachedLocRefMOAIdFormatter.java @@ -3,6 +3,9 @@ */ package at.knowcenter.wag.egov.egiz.sig.sigid; +import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; +import at.knowcenter.wag.egov.egiz.exceptions.SettingsException; + /** * @author wprinz * @@ -12,14 +15,24 @@ public class DetachedLocRefMOAIdFormatter implements IdFormatter /** * The SIG_ID prefix. */ - public static final String SIG_ID_PREFIX = "etsi-moa-detached"; //$NON-NLS-1$ + public static final String MOA_SIG_ID_KEY = "default.moa.signature.id"; /** * @see at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter#formatIds(java.lang.String[]) */ public String formatIds(String[] ids) { - return SIG_ID_PREFIX; + String sig_id_prefix = null; + + try + { + sig_id_prefix = SettingsReader.getInstance().getValueFromKey(MOA_SIG_ID_KEY); + } catch (SettingsException e) + { + e.printStackTrace(); + } + + return sig_id_prefix; } } -- cgit v1.2.3