Skip to content

Commit 9b453ed

Browse files
author
lawson89
committed
removed tiles dependency
added better error handling for problems when loading webgoat properties
1 parent 2d7679c commit 9b453ed

File tree

4 files changed

+114
-133
lines changed

4 files changed

+114
-133
lines changed

java/org/owasp/webgoat/HammerHead.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public void init() throws ServletException {
245245
logger.info("Initializing main webgoat servlet");
246246
httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyyy HH:mm:ss z", Locale.US);
247247
httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
248-
propertiesPath = getServletContext().getRealPath("./WEB-INF/webgoat.properties");
248+
propertiesPath = getServletContext().getRealPath("/WEB-INF/webgoat.properties");
249249
webgoatContext = new WebgoatContext(this);
250250
}
251251

java/org/owasp/webgoat/session/Course.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.owasp.webgoat.HammerHead;
1414
import org.owasp.webgoat.lessons.AbstractLesson;
1515
import org.owasp.webgoat.lessons.Category;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618

1719
/**
1820
* *************************************************************************************************
@@ -49,6 +51,8 @@
4951
*/
5052
public class Course {
5153

54+
final Logger logger = LoggerFactory.getLogger(WebgoatProperties.class);
55+
5256
private List<AbstractLesson> lessons = new LinkedList<AbstractLesson>();
5357

5458
private final static String PROPERTIES_FILENAME = HammerHead.propertiesPath;
@@ -63,8 +67,7 @@ public Course() {
6367
try {
6468
properties = new WebgoatProperties(PROPERTIES_FILENAME);
6569
} catch (IOException e) {
66-
System.out.println("Error loading WebGoat properties");
67-
e.printStackTrace();
70+
logger.error("Error loading webgoat properties", e);
6871
}
6972
}
7073

Lines changed: 108 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,119 @@
1-
21
package org.owasp.webgoat.session;
32

3+
import java.io.File;
44
import java.io.FileInputStream;
55
import java.io.IOException;
66
import java.util.Properties;
7-
8-
9-
/***************************************************************************************************
10-
*
11-
*
12-
* This file is part of WebGoat, an Open Web Application Security Project utility. For details,
13-
* please see http://www.owasp.org/
14-
*
7+
import org.owasp.webgoat.HammerHead;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
11+
/**
12+
* *************************************************************************************************
13+
*
14+
*
15+
* This file is part of WebGoat, an Open Web Application Security Project
16+
* utility. For details, please see http://www.owasp.org/
17+
*
1518
* Copyright (c) 2002 - 2007 Bruce Mayhew
16-
*
17-
* This program is free software; you can redistribute it and/or modify it under the terms of the
18-
* GNU General Public License as published by the Free Software Foundation; either version 2 of the
19-
* License, or (at your option) any later version.
20-
*
21-
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
22-
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23-
* General Public License for more details.
24-
*
25-
* You should have received a copy of the GNU General Public License along with this program; if
26-
* not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27-
* 02111-1307, USA.
28-
*
19+
*
20+
* This program is free software; you can redistribute it and/or modify it under
21+
* the terms of the GNU General Public License as published by the Free Software
22+
* Foundation; either version 2 of the License, or (at your option) any later
23+
* version.
24+
*
25+
* This program is distributed in the hope that it will be useful, but WITHOUT
26+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
27+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
28+
* details.
29+
*
30+
* You should have received a copy of the GNU General Public License along with
31+
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
32+
* Place - Suite 330, Boston, MA 02111-1307, USA.
33+
*
2934
* Getting Source ==============
30-
*
31-
* Source for this application is maintained at code.google.com, a repository for free software
32-
* projects.
33-
*
35+
*
36+
* Source for this application is maintained at code.google.com, a repository
37+
* for free software projects.
38+
*
3439
* For details, please see http://code.google.com/p/webgoat/
3540
*/
36-
public class WebgoatProperties extends Properties
37-
{
38-
39-
/**
40-
*
41-
*/
42-
private static final long serialVersionUID = 4351681705558227918L;
43-
44-
public WebgoatProperties(String propertiesFileName) throws IOException
45-
{
46-
try
47-
{
48-
FileInputStream in = new FileInputStream(propertiesFileName);
49-
load(in);
50-
} catch (IOException e)
51-
{
52-
System.out.println("Warning: Unable to open webgoat.properties file");
53-
}
54-
}
55-
56-
public int getIntProperty(String key, int defaultValue)
57-
{
58-
int value = defaultValue;
59-
60-
String s = getProperty(key);
61-
if (s != null)
62-
{
63-
value = Integer.parseInt(s);
64-
}
65-
66-
return value;
67-
}
68-
69-
public boolean getBooleanProperty(String key, boolean defaultValue)
70-
{
71-
boolean value = defaultValue;
72-
key = this.trimLesson(key);
73-
74-
String s = getProperty(key);
75-
if (s != null)
76-
{
77-
if (s.equalsIgnoreCase("true"))
78-
value = true;
79-
else if (s.equalsIgnoreCase("yes"))
80-
value = true;
81-
else if (s.equalsIgnoreCase("on"))
82-
value = true;
83-
else if (s.equalsIgnoreCase("false"))
84-
value = false;
85-
else if (s.equalsIgnoreCase("no"))
86-
value = false;
87-
else if (s.equalsIgnoreCase("off")) value = false;
88-
}
89-
90-
return value;
91-
}
92-
93-
private String trimLesson(String lesson)
94-
{
95-
String result = "";
96-
97-
if (lesson.startsWith("org.owasp.webgoat.lessons."))
98-
{
99-
result = lesson.substring("org.owasp.webgoat.lessons.".length(), lesson.length());
100-
}
101-
else
102-
{
103-
result = lesson;
104-
}
105-
106-
return result;
107-
}
108-
109-
public static void main(String[] args)
110-
{
111-
WebgoatProperties properties = null;
112-
try
113-
{
114-
properties = new WebgoatProperties("C:\\webgoat.properties");
115-
} catch (IOException e)
116-
{
117-
System.out.println("Error loading properties");
118-
e.printStackTrace();
119-
}
120-
System.out.println(properties.getProperty("CommandInjection.category"));
121-
}
41+
public class WebgoatProperties extends Properties {
42+
43+
/**
44+
*
45+
*/
46+
private static final long serialVersionUID = 4351681705558227918L;
47+
final Logger logger = LoggerFactory.getLogger(WebgoatProperties.class);
48+
49+
public WebgoatProperties(String propertiesFileName) throws IOException {
50+
if (propertiesFileName == null) {
51+
throw new IOException("Path to webgoat.properties is null, initialization must have failed");
52+
}
53+
File propertiesFile = new File(propertiesFileName);
54+
if (propertiesFile.exists() == false) {
55+
throw new IOException("Unable to locate webgoat.properties at: " + propertiesFileName);
56+
}
57+
FileInputStream in = new FileInputStream(propertiesFile);
58+
load(in);
59+
}
60+
61+
public int getIntProperty(String key, int defaultValue) {
62+
int value = defaultValue;
63+
64+
String s = getProperty(key);
65+
if (s != null) {
66+
value = Integer.parseInt(s);
67+
}
68+
69+
return value;
70+
}
71+
72+
public boolean getBooleanProperty(String key, boolean defaultValue) {
73+
boolean value = defaultValue;
74+
key = this.trimLesson(key);
75+
76+
String s = getProperty(key);
77+
if (s != null) {
78+
if (s.equalsIgnoreCase("true")) {
79+
value = true;
80+
} else if (s.equalsIgnoreCase("yes")) {
81+
value = true;
82+
} else if (s.equalsIgnoreCase("on")) {
83+
value = true;
84+
} else if (s.equalsIgnoreCase("false")) {
85+
value = false;
86+
} else if (s.equalsIgnoreCase("no")) {
87+
value = false;
88+
} else if (s.equalsIgnoreCase("off")) {
89+
value = false;
90+
}
91+
}
92+
93+
return value;
94+
}
95+
96+
private String trimLesson(String lesson) {
97+
String result = "";
98+
99+
if (lesson.startsWith("org.owasp.webgoat.lessons.")) {
100+
result = lesson.substring("org.owasp.webgoat.lessons.".length(), lesson.length());
101+
} else {
102+
result = lesson;
103+
}
104+
105+
return result;
106+
}
107+
108+
public static void main(String[] args) {
109+
WebgoatProperties properties = null;
110+
try {
111+
properties = new WebgoatProperties("C:\\webgoat.properties");
112+
} catch (IOException e) {
113+
System.out.println("Error loading properties");
114+
e.printStackTrace();
115+
}
116+
System.out.println(properties.getProperty("CommandInjection.category"));
117+
}
122118

123119
}

pom.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -301,24 +301,6 @@
301301
<version>${tiles.version}</version>
302302
<type>jar</type>
303303
</dependency>
304-
<dependency>
305-
<groupId>org.apache.tiles</groupId>
306-
<artifactId>tiles-template</artifactId>
307-
<version>${tiles.version}</version>
308-
<type>jar</type>
309-
</dependency>
310-
<dependency>
311-
<groupId>org.apache.tiles</groupId>
312-
<artifactId>tiles-servlet</artifactId>
313-
<version>${tiles.version}</version>
314-
<type>jar</type>
315-
</dependency>
316-
<dependency>
317-
<groupId>org.apache.tiles</groupId>
318-
<artifactId>tiles-jsp</artifactId>
319-
<version>${tiles.version}</version>
320-
<type>jar</type>
321-
</dependency>
322304
<dependency>
323305
<groupId>org.slf4j</groupId>
324306
<artifactId>slf4j-api</artifactId>

0 commit comments

Comments
 (0)