aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-08-20 10:59:37 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2010-08-20 10:59:37 +0000
commita95ebceaf0f77a25c26f866dff60faa6b388526c (patch)
tree306312ff46ede4feca7cc87721af1542bd4180ae /src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java
parentc8481184208979098d9da7278ffd9f760a32ec9b (diff)
downloadpdf-as-3-a95ebceaf0f77a25c26f866dff60faa6b388526c.tar.gz
pdf-as-3-a95ebceaf0f77a25c26f866dff60faa6b388526c.tar.bz2
pdf-as-3-a95ebceaf0f77a25c26f866dff60faa6b388526c.zip
Internal error passed as RuntimeException instead of being ignored.
PdfAsFactory: Switch implemented that allows to skip provider registration. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@589 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java113
1 files changed, 88 insertions, 25 deletions
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 c85513c..f4c28c7 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
@@ -28,12 +28,12 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
+import java.security.Security;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.text.StrSubstitutor;
import org.apache.commons.logging.Log;
@@ -147,6 +147,8 @@ public class SettingsReader implements Serializable
* internal help file
*/
private static final String HELP_TEXT_PROP_RESOURCE = "/config/help_text.properties";
+
+ public static final boolean REGISTER_IAIK_PROVIDERS_ON_DEFAULT = true;
// /**
// * The web application path
@@ -319,7 +321,8 @@ public class SettingsReader implements Serializable
* This method returns an synchronized instance of this class. The settings
* file is read only once using this class. This method returns the instance
* holding the definitions of the default settings file. Default file:
- * {@link SettingsReader#CONFIG_FILE_DEFAULT_NAME}: "settings.txt"
+ * {@link SettingsReader#CONFIG_FILE_DEFAULT_NAME}: "settings.txt".
+ * Note: IAIK JCE and IAIK ECC security providers are automatically registered.
*
* @return an instance of the SettingsReader
* @throws SettingsException
@@ -335,14 +338,32 @@ public class SettingsReader implements Serializable
*
* <p>
* Subsequent calls to getInstance will return the new settings.
+ * Note: IAIK JCE and IAIK ECC security providers are automatically registered.
* </p>
*
* @throws SettingsException f.e.
*/
- public synchronized static void createInstance () throws SettingsException
+ public synchronized static void createInstance() throws SettingsException
+ {
+ instance_ = null;
+ getInstance();
+ }
+
+ /**
+ * Reloads the Settings file.
+ *
+ * <p>
+ * Subsequent calls to getInstance will return the new settings.
+ * </p>
+ * @param registerProvider <code>true</code>: automatically registers IAIK JCE and ECC Provider;
+ * <code>false</code>: providers will NOT be automatically registered, providers
+ * needed have to be registered by the API user
+ * @throws SettingsException f.e.
+ */
+ public synchronized static void createInstance(boolean registerProvider) throws SettingsException
{
instance_ = null;
- getInstance();
+ getInstance(null, registerProvider);
}
/**
@@ -361,33 +382,75 @@ public class SettingsReader implements Serializable
*
* @param settingsFile
* the settings file that should be load.
+ * @param registerProvider <code>true</code>: automatically registers IAIK JCE and ECC Provider;
+ * <code>false</code>: providers will NOT be automatically registered, providers
+ * needed have to be registered by the API user
* @return an instance of the SettingsReader
* @throws SettingsException
* if the settings file could not be read
*/
- private synchronized static SettingsReader getInstance(String settingsFile) throws SettingsException
+ private synchronized static SettingsReader getInstance(String settingsFile, boolean registerProvider) throws SettingsException
{
- if (instance_ == null)
- {
- int length = Utils.max(new int[] { RESOURCES_PATH.length(), TMP_PATH.length(), CONFIG_PATH.length(), CERT_PATH.length() });
-
- logger_.info(StringUtils.repeat("*", length + 25));
- logger_.info(" resources path = \"" + RESOURCES_PATH + "\"");
- logger_.info(" configuration path = \"" + CONFIG_PATH + "\"");
- logger_.info(" certstore path = \"" + CERT_PATH + "\"");
- logger_.info(" temporary path = \"" + TMP_PATH + "\"");
- logger_.debug(" file.encoding = \"" + System.getProperty("file.encoding") + "\"");
- logger_.info(StringUtils.repeat("*", length + 25));
-
- IAIK.addAsProvider();
- ECCProvider.addAsProvider();
- // Does not conform with PKIX, but is used by belgium citizen card
+ if (instance_ == null)
+ {
+ int length = Utils.max(new int[] { RESOURCES_PATH.length(), TMP_PATH.length(), CONFIG_PATH.length(), CERT_PATH.length() });
+
+ logger_.info(StringUtils.repeat("*", length + 25));
+ logger_.info(" resources path = \"" + RESOURCES_PATH + "\"");
+ logger_.info(" configuration path = \"" + CONFIG_PATH + "\"");
+ logger_.info(" certstore path = \"" + CERT_PATH + "\"");
+ logger_.info(" temporary path = \"" + TMP_PATH + "\"");
+ logger_.debug(" file.encoding = \"" + System.getProperty("file.encoding") + "\"");
+ logger_.info(StringUtils.repeat("*", length + 25));
+
+ if (registerProvider) {
+ IAIK.addAsProvider();
+ ECCProvider.addAsProvider();
+ } else {
+ if (Security.getProvider("IAIK") == null) {
+ logger_.debug("Default IAIK JCE provider not registered.");
+ } else {
+ logger_.debug("IAIK JCE provider already registered.");
+ }
+ if (Security.getProvider("IAIK_ECC") == null) {
+ logger_.debug("Default IAIK ECC provider not registered.");
+ } else {
+ logger_.debug("IAIK ECC provider already registered.");
+ }
+ }
+ // Does not conform with PKIX, but is used by belgium citizen card
// log.info("Registering RDN \"SERIALNUMBER\" as " + ObjectID.serialNumber + ".");
- RFC2253NameParser.register("SERIALNUMBER", ObjectID.serialNumber);
-
- instance_ = new SettingsReader(settingsFile);
- }
- return instance_;
+ RFC2253NameParser.register("SERIALNUMBER", ObjectID.serialNumber);
+
+ instance_ = new SettingsReader(settingsFile);
+ }
+ return instance_;
+ }
+
+ /**
+ * This method returns an synchronized instance of this class. The settings
+ * file is read only once using this class. This method returns the instance
+ * holding the definitions of the settingsFile. If the input param
+ * <code>settingsFile == null</code> the default settings file will be load.
+ * Default file: {@link SettingsReader#CONFIG_FILE_DEFAULT_NAME}:
+ * "settings.txt".
+ * Note: IAIK JCE and IAIK ECC security providers are automatically registered.
+ *
+ * If an instance of this class exist, the input param is ignored! The
+ * SettingsReader is singleton and therefore the first
+ * {@link SettingsReader#getInstance()}defines the settings file that has to
+ * be loaded. This means changes between a application lifecyle can not be
+ * done!
+ *
+ * @param settingsFile
+ * the settings file that should be load.
+ * @return an instance of the SettingsReader
+ * @throws SettingsException
+ * if the settings file could not be read
+ */
+ private static SettingsReader getInstance(String settingsFile) throws SettingsException
+ {
+ return getInstance(settingsFile, REGISTER_IAIK_PROVIDERS_ON_DEFAULT);
}
/**