aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/cfg
diff options
context:
space:
mode:
authortknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2008-06-09 15:27:50 +0000
committertknall <tknall@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2008-06-09 15:27:50 +0000
commiteb68e29e371ef3e944f682239e6f3f92cb084697 (patch)
tree39ef4547a7efe4e929886b3d2ca01bb037cb2ce4 /src/main/java/at/knowcenter/wag/egov/egiz/cfg
parentdef55a4c6f4a26b8ddbf2a9e892e36a67d9380f1 (diff)
downloadpdf-as-3-eb68e29e371ef3e944f682239e6f3f92cb084697.tar.gz
pdf-as-3-eb68e29e371ef3e944f682239e6f3f92cb084697.tar.bz2
pdf-as-3-eb68e29e371ef3e944f682239e6f3f92cb084697.zip
Web-Application: Configuration may be declared via system property "pdf-as.work-dir" or via Servlet-Init-Parameter "work-dir".
Bug fixed in RetrieveSignatureDataServlet: Response header didn't contain a content length attribute. The ITS Mac BKU rejects those requests. Workaround for ITS Mac BKU integrated. A redirect via response does only work if the response contains a valid SL request (e.g. a NullOperationRequest). API: The configuration folder may be omitted at instantiating the api. Configuration may be set via system property "pdf-as.work-dir". If no configuration is given at all, the current user's home directory is searched for a folder "PDF-AS". If not found a default configuration is created. If the configuration is explicitely given than the temporary folder is located within the given directory otherwise within the user's temporary directory. Declaring the configuration folder, replacements for system properties like "${catalina.base}/conf/pdfas" may be used. Web-Application: Session is now being invalidated after download of the signed pdf file. Web-Application: Every hardcoded context "pdf-as" has been replaced. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@277 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/cfg')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java165
1 files changed, 120 insertions, 45 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 1fa3ad6..231da06 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
@@ -33,12 +33,18 @@ import java.util.Properties;
import java.util.Vector;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.text.StrSubstitutor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import at.gv.egiz.pdfas.api.commons.Constants;
+import at.gv.egiz.pdfas.api.exceptions.ConfigUtilsException;
+import at.gv.egiz.pdfas.utils.ConfigUtils;
+import at.gv.egiz.pdfas.web.helper.TempDirHelper;
import at.knowcenter.wag.egov.egiz.PdfAS;
import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException;
import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
+import at.knowcenter.wag.egov.egiz.pdf.Utils;
/**
* The SettingsReader reads the <code>settings.txt</code> file. The
@@ -186,6 +192,11 @@ public class SettingsReader implements Serializable
* </p>
*/
public static String RESOURCES_PATH = null;
+
+ /**
+ * The path for temporary files.
+ */
+ public static String TMP_PATH = null;
/**
* The path of the configuration directory.
@@ -197,11 +208,6 @@ public class SettingsReader implements Serializable
*/
public static String CERT_PATH = null;
- /**
- * The name of the directory, where temporary files are stored.
- */
- protected static String TEMP_DIR_NAME = "pdfastmp";
-
// /**
// * The application config path for the command line tool
// */
@@ -386,6 +392,14 @@ public class SettingsReader implements Serializable
{
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_.info(StringUtils.repeat("*", length + 25));
instance_ = new SettingsReader(settingsFile);
}
return instance_;
@@ -631,11 +645,11 @@ public class SettingsReader implements Serializable
/**
* Assembles the File of the temporary directory without checking if it really
* exists.
+ * @see TempDirHelper#assembleTemporaryDirectoryFile()
*/
protected static File assembleTemporaryDirectoryFile()
{
- File temp_dir = new File(RESOURCES_PATH + TEMP_DIR_NAME);
- return temp_dir;
+ return TempDirHelper.assembleTemporaryDirectoryFile();
}
/**
@@ -646,15 +660,11 @@ public class SettingsReader implements Serializable
* </p>
*
* @return Returns the directory where temporary files should be stored.
+ * @see TempDirHelper#getTemporaryDirectory()
*/
public static File getTemporaryDirectory()
{
- File temp_dir = assembleTemporaryDirectoryFile();
- if (!temp_dir.exists())
- {
- temp_dir.mkdirs();
- }
- return temp_dir;
+ return TempDirHelper.getTemporaryDirectory();
}
/**
@@ -664,38 +674,109 @@ public class SettingsReader implements Serializable
* This should be used to clear temporary files when the application shuts
* down.
* </p>
+ * @see TempDirHelper#clearTemporaryDirectory()
*/
public static void clearTemporaryDirectory()
{
- File temp_dir = assembleTemporaryDirectoryFile();
- logger_.debug("Clearing temporary directory: " + temp_dir);
-
- if (!temp_dir.exists())
- {
- return;
- }
-
- File[] files = temp_dir.listFiles();
- for (int i = 0; i < files.length; i++)
- {
- // added by tknall: do not try to remove svn-metadata
- if (files[i].getName().endsWith(".svn")) {
- continue;
- }
- logger_.debug(" Clearing temporary file: " + files[i]);
- boolean delete_success = files[i].delete();
- if (!delete_success)
- {
- logger_.error("Couldn't delete the temporary file: " + files[i]);
+ TempDirHelper.clearTemporaryDirectory();
+ }
+
+ private static String assertFileSeparator(String path) {
+ if (path == null) {
+ throw new NullPointerException("Path must not be null.");
+ }
+ if (path.endsWith(File.separator) || path.endsWith("/") || path.endsWith("\\")) {
+ return path;
+ } else {
+ return (path + File.separator);
+ }
+ }
+
+ public static synchronized void initialize(String configdir, String tmpdir) {
+
+ boolean defaultConfigDeployed = false;
+ // resolve work directory
+ // configuration explicitely given ?
+ if (configdir == null) {
+
+ // configuration via system property ?
+ logger_.debug("No configuration directory given. Looking for system property \"" + Constants.CONFIG_SYSTEM_PROPERTY + "\".");
+ configdir = System.getProperty(Constants.CONFIG_SYSTEM_PROPERTY);
+ if (configdir == null) {
+
+ // configuration via user's home directory ?
+ logger_.debug("System property not set. Trying to locate configuration within the user's home directory.");
+ String userHome = System.getProperty("user.home");
+ if (userHome == null || userHome.length() == 0) {
+ throw new RuntimeException("Unable to resolve user's home directory.");
+ }
+ configdir = assertFileSeparator(userHome) + Constants.USERHOME_CONFIG_FOLDER;
+ try {
+ defaultConfigDeployed = ConfigUtils.deployDefaultConfiguration(configdir, false);
+ } catch (ConfigUtilsException e) {
+ throw new RuntimeException(e);
+ }
+ if (defaultConfigDeployed) {
+ logger_.info("** Default configuration successfully deployed to the current user's home. **");
+ } else {
+ logger_.debug("Default configuration NOT deployed because to the current user's home because it already exists.");
+ }
+ } else {
+ logger_.debug("Configuration set by system property.");
+ }
+ } else {
+ logger_.debug("Configuration path explicitely set.");
+ }
+ File configdirFile = new File(StrSubstitutor.replaceSystemProperties(configdir));
+ try {
+ configdir = assertFileSeparator(configdirFile.getCanonicalPath());
+ } catch (IOException e) {
+ configdir = assertFileSeparator(configdirFile.getPath());
}
- }
+ if (!configdirFile.isDirectory())
+ {
+ throw new IllegalArgumentException("The config directory \"" + configdir + "\" does not exist or is not a directory.");
+ }
+
+ // resolve temporary dir
+ if (tmpdir == null) {
+ logger_.debug("Temporary directory not explicitely set. Looking for user's temp directory.");
+ tmpdir = System.getProperty("java.io.tmpdir");
+ if (tmpdir == null) {
+ logger_.debug("Unable to resolve user's temporary directory. Assuming temporary directory located within config dir.");
+ tmpdir = configdir;
+ }
+ } else {
+ logger_.debug("Temporary directory explicitely set.");
+ }
+ File tmpdirFile = new File(StrSubstitutor.replaceSystemProperties(assertFileSeparator(tmpdir) + Constants.TEMP_DIR_NAME));
+ try {
+ tmpdir = assertFileSeparator(tmpdirFile.getCanonicalPath());
+ } catch (IOException e) {
+ tmpdir = assertFileSeparator(tmpdirFile.getPath());
+ }
+
+ RESOURCES_PATH = configdir;
+ TMP_PATH = tmpdir;
+ CONFIG_PATH = RESOURCES_PATH + CFG + FILE_SEP;
+ CERT_PATH = RESOURCES_PATH + CERT + FILE_SEP;
+
+ int length = Utils.max(new int[] { RESOURCES_PATH.length(), TMP_PATH.length(), CONFIG_PATH.length(), CERT_PATH.length() });
+
+ logger_.debug(StringUtils.repeat("*", length + 25));
+ logger_.debug(" resources path = \"" + RESOURCES_PATH + "\"");
+ logger_.debug(" configuration path = \"" + CONFIG_PATH + "\"");
+ logger_.debug(" certstore path = \"" + CERT_PATH + "\"");
+ logger_.debug(" temporary path = \"" + TMP_PATH + "\"");
+ if (defaultConfigDeployed) {
+ logger_.debug(" default configuration was deployed to the current user's home directory ");
+ }
+ logger_.debug(StringUtils.repeat("*", length + 25));
}
public static void initialize(String base_dir)
{
- RESOURCES_PATH = base_dir + FILE_SEP; //CATALINA_HOME + FILE_SEP + WEB_APPL_DIR;
- CONFIG_PATH = RESOURCES_PATH + CFG + FILE_SEP;
- CERT_PATH = RESOURCES_PATH + CERT + FILE_SEP;
+ initialize(base_dir, null);
}
/**
@@ -707,10 +788,7 @@ public class SettingsReader implements Serializable
*/
public static void initializeForWeb(String base_dir)
{
- initialize(base_dir);
-// RESOURCES_PATH = base_dir + FILE_SEP; //CATALINA_HOME + FILE_SEP + WEB_APPL_DIR;
-// CONFIG_PATH = RESOURCES_PATH + CFG + FILE_SEP;
-// CERT_PATH = RESOURCES_PATH + CERT + FILE_SEP;
+ initialize(base_dir, base_dir);
}
/**
@@ -718,10 +796,7 @@ public class SettingsReader implements Serializable
*/
public static void initializeForCommandLine()
{
- initialize(USER_DIR);
-// RESOURCES_PATH = USER_DIR + FILE_SEP;
-// CONFIG_PATH = RESOURCES_PATH + CFG + FILE_SEP;
-// CERT_PATH = RESOURCES_PATH + CERT + FILE_SEP;
+ initialize(null);
}
static {