Skip to content

Commit 7bc70b2

Browse files
author
manico.james
committed
make file io loading of properties file happen before classapth loading
1 parent c5500c2 commit 7bc70b2

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

src/main/java/org/owasp/esapi/reference/DefaultSecurityConfiguration.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,20 @@ public int getAllowedFileUploadSize() {
232232
* if the file is inaccessible
233233
*/
234234
private void loadConfiguration() throws IOException {
235-
236-
logSpecial("Attempting to load " + RESOURCE_FILE + " via the classpath.");
237235

238236
try {
239-
properties = loadConfigurationFromClasspath(RESOURCE_FILE);
240-
} catch (IllegalArgumentException iae) {
241-
237+
//first attempt file IO loading of properties
242238
logSpecial("Attempting to load " + RESOURCE_FILE + " via file io.");
239+
properties = loadPropertiesFromStream(getResourceStream(RESOURCE_FILE), RESOURCE_FILE);
240+
241+
} catch (Exception iae) {
242+
//if file io loading fails, attempt classpath based loading next
243+
logSpecial("Loading " + RESOURCE_FILE + " via file io failed.");
244+
logSpecial("Attempting to load " + RESOURCE_FILE + " via the classpath.");
243245
try {
244-
properties = loadPropertiesFromStream(getResourceStream(RESOURCE_FILE), RESOURCE_FILE);
245-
} catch (Exception e) {
246-
logSpecial(RESOURCE_FILE + " could not be successfully loaded by any means. fail.");
246+
properties = loadConfigurationFromClasspath(RESOURCE_FILE);
247+
} catch (Exception e) {
248+
logSpecial(RESOURCE_FILE + " could not be loaded by any means. fail.", e);
247249
}
248250
}
249251
}
@@ -588,21 +590,20 @@ public Pattern getValidationPattern(String key) {
588590
return pattern;
589591
}
590592

591-
private Properties loadPropertiesFromStream(InputStream is, String name)
592-
throws IOException {
593-
Properties config = new Properties();
594-
try {
595-
config.load(is);
596-
logSpecial("Successfully loaded '" + name + "' via an InputStream.");
597-
} finally {
598-
if (is != null)
599-
try {
600-
is.close();
601-
} catch (Exception e) {
602-
}
603-
}
604-
return config;
605-
}
593+
private Properties loadPropertiesFromStream(InputStream is, String name) throws IOException {
594+
Properties config = new Properties();
595+
try {
596+
config.load(is);
597+
logSpecial("successfully loaded '" + name + "' via an inputStream.");
598+
} finally {
599+
if (is != null)
600+
try {
601+
is.close();
602+
} catch (Exception e) {
603+
}
604+
}
605+
return config;
606+
}
606607

607608
/**
608609
* Utility method to get a resource as an InputStream. The search looks for

0 commit comments

Comments
 (0)