aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-07-11 13:38:49 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-07-11 13:38:49 +0200
commit1219abaf9f0029e39f5fbdf342fd4ebf07144b5b (patch)
tree1baeb54030e016158ea287a9c87d70597e0f19f5 /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
parent0bfafff409078ef49b2d4a0d71405e8f5b0eb078 (diff)
downloadpdf-as-4-1219abaf9f0029e39f5fbdf342fd4ebf07144b5b.tar.gz
pdf-as-4-1219abaf9f0029e39f5fbdf342fd4ebf07144b5b.tar.bz2
pdf-as-4-1219abaf9f0029e39f5fbdf342fd4ebf07144b5b.zip
added Signature Verification Level
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java159
1 files changed, 107 insertions, 52 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
index 299c166f..288b62c4 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
@@ -35,58 +35,61 @@ import org.slf4j.LoggerFactory;
public class WebConfiguration {
-
public static final String PUBLIC_URL = "public.url";
public static final String LOCAL_BKU_URL = "bku.local.url";
public static final String ONLINE_BKU_URL = "bku.online.url";
public static final String MOBILE_BKU_URL = "bku.mobile.url";
public static final String ERROR_DETAILS = "error.showdetails";
public static final String PDF_AS_WORK_DIR = "pdfas.dir";
-
+
public static final String MOA_SS_ENABLED = "moa.enabled";
public static final String SOAP_SIGN_ENABLED = "soap.sign.enabled";
-
+
public static final String KEYSTORE_ENABLED = "ks.enabled";
public static final String KEYSTORE_FILE = "ks.file";
public static final String KEYSTORE_TYPE = "ks.type";
public static final String KEYSTORE_PASS = "ks.pass";
public static final String KEYSTORE_ALIAS = "ks.key.alias";
public static final String KEYSTORE_KEY_PASS = "ks.key.pass";
-
+
public static final String WHITELIST_ENABLED = "whitelist.enabled";
public static final String WHITELIST_VALUE_PRE = "whitelist.url.";
-
+
public static final String REQUEST_STORE = "request.store";
public static final String REQUEST_STORE_INMEM = "at.gv.egiz.pdfas.web.store.InMemoryRequestStore";
-
+ public static final String REQUEST_STORE_DB = "at.gv.egiz.pdfas.web.store.DBRequestStore";
+ public static final String DB_REQUEST_TIMEOUT = "request.db.timeout";
+ public static final String HIBERNATE_PREFIX = "hibernate.props.";
+
private static Properties properties = new Properties();
-
+ private static Properties hibernateProps = new Properties();
+
private static final Logger logger = LoggerFactory
.getLogger(WebConfiguration.class);
-
+
private static List<String> whiteListregEx = new ArrayList<String>();
public static void configure(String config) {
-
+
properties.clear();
whiteListregEx.clear();
-
+
try {
properties.load(new FileInputStream(config));
- } catch(Exception e) {
+ } catch (Exception e) {
logger.error("Failed to load configuration: " + e.getMessage());
throw new RuntimeException(e);
}
-
- if(isWhiteListEnabled()) {
+
+ if (isWhiteListEnabled()) {
Iterator<Object> keyIt = properties.keySet().iterator();
- while(keyIt.hasNext()) {
+ while (keyIt.hasNext()) {
Object keyObj = keyIt.next();
- if(keyObj != null) {
+ if (keyObj != null) {
String key = keyObj.toString();
- if(key.startsWith(WHITELIST_VALUE_PRE)) {
+ if (key.startsWith(WHITELIST_VALUE_PRE)) {
String whitelist_expr = properties.getProperty(key);
- if(whitelist_expr != null) {
+ if (whitelist_expr != null) {
whiteListregEx.add(whitelist_expr);
logger.debug("URL Whitelist: " + whitelist_expr);
}
@@ -94,21 +97,52 @@ public class WebConfiguration {
}
}
}
-
+
+ Iterator<Object> keyIt = properties.keySet().iterator();
+ while (keyIt.hasNext()) {
+ Object keyObj = keyIt.next();
+ if (keyObj != null) {
+ String key = keyObj.toString();
+ if (key.startsWith(HIBERNATE_PREFIX)) {
+ String value = properties.getProperty(key);
+ if (value != null) {
+ String hibKey = key.replace(HIBERNATE_PREFIX, "");
+ hibernateProps.put(hibKey, value);
+ }
+ }
+ }
+ }
+
+ if (hibernateProps.size() != 0) {
+ logger.debug("DB Properties: ");
+ Iterator<Object> hibkeyIt = hibernateProps.keySet().iterator();
+ while (hibkeyIt.hasNext()) {
+ Object keyObj = hibkeyIt.next();
+ if (keyObj != null) {
+ String key = keyObj.toString();
+ String value = hibernateProps.getProperty(key);
+ logger.debug(" {}: {}", key, value);
+ }
+ }
+ }
+
String pdfASDir = getPdfASDir();
- if(pdfASDir == null) {
+ if (pdfASDir == null) {
logger.error("Please configure pdf as working directory in the web configuration");
- throw new RuntimeException("Please configure pdf as working directory in the web configuration");
+ throw new RuntimeException(
+ "Please configure pdf as working directory in the web configuration");
}
-
+
File f = new File(pdfASDir);
-
- if(!f.exists() || !f.isDirectory()) {
- logger.error("Pdf As working directory does not exists or is not a directory!: " + pdfASDir);
- throw new RuntimeException("Pdf As working directory does not exists or is not a directory!");
+
+ if (!f.exists() || !f.isDirectory()) {
+ logger.error("Pdf As working directory does not exists or is not a directory!: "
+ + pdfASDir);
+ throw new RuntimeException(
+ "Pdf As working directory does not exists or is not a directory!");
}
}
-
+
public static String getPublicURL() {
return properties.getProperty(PUBLIC_URL);
}
@@ -124,71 +158,75 @@ public class WebConfiguration {
public static String getHandyBKUURL() {
return properties.getProperty(MOBILE_BKU_URL);
}
-
+
public static String getPdfASDir() {
return properties.getProperty(PDF_AS_WORK_DIR);
}
-
+
public static String getKeystoreFile() {
return properties.getProperty(KEYSTORE_FILE);
}
+
public static String getKeystoreType() {
return properties.getProperty(KEYSTORE_TYPE);
}
+
public static String getKeystorePass() {
return properties.getProperty(KEYSTORE_PASS);
}
+
public static String getKeystoreAlias() {
return properties.getProperty(KEYSTORE_ALIAS);
}
+
public static String getKeystoreKeyPass() {
return properties.getProperty(KEYSTORE_KEY_PASS);
}
-
+
public static boolean getMOASSEnabled() {
String value = properties.getProperty(MOA_SS_ENABLED);
- if(value != null) {
- if(value.equals("true")) {
+ if (value != null) {
+ if (value.equals("true")) {
return true;
}
}
return false;
}
-
+
public static boolean getKeystoreEnabled() {
String value = properties.getProperty(KEYSTORE_ENABLED);
- if(value != null) {
- if(value.equals("true")) {
+ if (value != null) {
+ if (value.equals("true")) {
return true;
}
}
return false;
}
-
+
public static boolean getSoapSignEnabled() {
String value = properties.getProperty(SOAP_SIGN_ENABLED);
- if(value != null) {
- if(value.equals("true")) {
+ if (value != null) {
+ if (value.equals("true")) {
return true;
}
}
return false;
}
-
+
public static boolean isShowErrorDetails() {
String value = properties.getProperty(ERROR_DETAILS);
- if(value != null) {
- if(value.equals("true")) {
+ if (value != null) {
+ if (value.equals("true")) {
return true;
}
}
return false;
}
-
+
public static boolean isWhiteListEnabled() {
String value = properties.getProperty(WHITELIST_ENABLED);
- if(value != null) {
- if(value.equals("true")) {
+ if (value != null) {
+ if (value.equals("true")) {
return true;
}
}
@@ -196,32 +234,49 @@ public class WebConfiguration {
}
public static synchronized boolean isProvidePdfURLinWhitelist(String url) {
- if(isWhiteListEnabled()) {
-
+ if (isWhiteListEnabled()) {
+
Iterator<String> patterns = whiteListregEx.iterator();
- while(patterns.hasNext()) {
+ while (patterns.hasNext()) {
String pattern = patterns.next();
try {
- if(url.matches(pattern)) {
+ if (url.matches(pattern)) {
return true;
}
- } catch(Throwable e) {
+ } catch (Throwable e) {
logger.error("Error in matching regex: " + pattern, e);
}
}
-
+
return false;
}
return true;
}
+
+ public static Properties getHibernateProps() {
+ return (Properties) hibernateProps.clone();
+ }
+
+ public static int getDBTimeout() {
+ String value = properties.getProperty(DB_REQUEST_TIMEOUT);
+ int ivalue = 600;
+ if (value != null) {
+ try {
+ ivalue = Integer.parseInt(value);
+ } catch(NumberFormatException e) {
+ logger.error("DB request Timeout not a number", e);
+ }
+ }
+ return ivalue;
+ }
public static String getStoreClass() {
String cls = properties.getProperty(REQUEST_STORE);
-
- if(cls != null) {
+
+ if (cls != null) {
return cls;
}
-
+
return REQUEST_STORE_INMEM;
}
}