Skip to content

Commit 05c0c03

Browse files
author
David Touzet
committed
Internationalization refactoring pass 2 : removing dependencies to
previous implentation
1 parent 92b317b commit 05c0c03

34 files changed

+3829
-3372
lines changed

src/main/java/org/owasp/webgoat/lessons/AbstractLesson.java

Lines changed: 808 additions & 798 deletions
Large diffs are not rendered by default.

src/main/java/org/owasp/webgoat/lessons/BasicAuthentication.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.apache.ecs.html.Table;
1414
import org.owasp.webgoat.session.ECSFactory;
1515
import org.owasp.webgoat.session.WebSession;
16-
import org.owasp.webgoat.util.WebGoatI18N;
1716

1817

1918
/***************************************************************************************************
@@ -102,12 +101,12 @@ protected Element doStage1(WebSession s) throws Exception
102101
{
103102
if (headerName.length() > 0 && !headerName.equalsIgnoreCase(AUTHORIZATION))
104103
{
105-
s.setMessage(WebGoatI18N.get("BasicAuthHeaderNameIncorrect"));
104+
s.setMessage(getLabelManager().get("BasicAuthHeaderNameIncorrect"));
106105
}
107106
if (headerValue.length() > 0
108107
&& !(headerValue.equals("guest:guest") || headerValue.equals("webgoat:webgoat")))
109108
{
110-
s.setMessage(WebGoatI18N.get("BasicAuthHeaderValueIncorrect"));
109+
s.setMessage(getLabelManager().get("BasicAuthHeaderValueIncorrect"));
111110

112111
}
113112
}
@@ -121,8 +120,8 @@ protected Element doStage1(WebSession s) throws Exception
121120

122121
TR row1 = new TR();
123122
TR row2 = new TR();
124-
row1.addElement(new TD(new StringElement(WebGoatI18N.get("BasicAuthenticationWhatIsNameOfHeader"))));
125-
row2.addElement(new TD(new StringElement(WebGoatI18N.get("BasicAuthenticationWhatIsDecodedValueOfHeader"))));
123+
row1.addElement(new TD(new StringElement(getLabelManager().get("BasicAuthenticationWhatIsNameOfHeader"))));
124+
row2.addElement(new TD(new StringElement(getLabelManager().get("BasicAuthenticationWhatIsDecodedValueOfHeader"))));
126125

127126
row1.addElement(new TD(new Input(Input.TEXT, HEADER_NAME, headerName.toString())));
128127
row2.addElement(new TD(new Input(Input.TEXT, HEADER_VALUE, headerValue.toString())));
@@ -133,7 +132,7 @@ protected Element doStage1(WebSession s) throws Exception
133132
ec.addElement(t);
134133
ec.addElement(new P());
135134

136-
Element b = ECSFactory.makeButton(WebGoatI18N.get("Submit"));
135+
Element b = ECSFactory.makeButton(getLabelManager().get("Submit"));
137136
ec.addElement(b);
138137

139138
} catch (Exception e)
@@ -159,7 +158,7 @@ protected Element doStage2(WebSession s) throws Exception
159158
getLessonTracker(s, originalUser).setStage(1);
160159
getLessonTracker(s, originalUser).store(s, this);
161160
makeSuccess(s);
162-
s.setMessage(WebGoatI18N.get("BasicAuthenticiationGreenStars1")+ originalUser + WebGoatI18N.get("BasicAuthenticationGreenStars2"));
161+
s.setMessage(getLabelManager().get("BasicAuthenticiationGreenStars1")+ originalUser + getLabelManager().get("BasicAuthenticationGreenStars2"));
163162
return ec;
164163
}
165164
else
@@ -185,36 +184,36 @@ protected Element doStage2(WebSession s) throws Exception
185184
getLessonTracker(s, BASIC).store(s, this, BASIC);
186185
}
187186

188-
s.setMessage(WebGoatI18N.get("BasicAuthenticationStage1Completed"));
187+
s.setMessage(getLabelManager().get("BasicAuthenticationStage1Completed"));
189188

190189
// If the auth header is different but still the original user - tell the user
191190
// that the original cookie was posted bak and basic auth uses the cookie before the
192191
// authorization token
193192
if (!originalAuth.equals("") && !originalAuth.equals(s.getHeader(AUTHORIZATION)))
194193
{
195194
ec
196-
.addElement(WebGoatI18N.get("BasicAuthenticationAlmostThere1")
195+
.addElement(getLabelManager().get("BasicAuthenticationAlmostThere1")
197196
+ AUTHORIZATION
198-
+ WebGoatI18N.get("BasicAuthenticationAlmostThere2")
197+
+ getLabelManager().get("BasicAuthenticationAlmostThere2")
199198
+ s.getUserName()
200-
+ WebGoatI18N.get("BasicAuthenticationAlmostThere3"));
199+
+ getLabelManager().get("BasicAuthenticationAlmostThere3"));
201200
}
202201
else if (!originalSessionId.equals(s.getCookie(JSESSIONID)))
203202
{
204203
ec
205-
.addElement(WebGoatI18N.get("BasicAuthenticationReallyClose"));
204+
.addElement(getLabelManager().get("BasicAuthenticationReallyClose"));
206205

207206
}
208207
else
209208
{
210-
ec.addElement(WebGoatI18N.get("BasicAuthenticationUseTheHints"));
209+
ec.addElement(getLabelManager().get("BasicAuthenticationUseTheHints"));
211210
}
212211

213212
}
214213

215214
} catch (Exception e)
216215
{
217-
s.setMessage(WebGoatI18N.get("ErrorGenerating") + this.getClass().getName());
216+
s.setMessage(getLabelManager().get("ErrorGenerating") + this.getClass().getName());
218217
e.printStackTrace();
219218
}
220219

@@ -245,18 +244,18 @@ public List<String> getHints(WebSession s)
245244
// switch ( stage )
246245
// {
247246
// case 1:
248-
hints.add(WebGoatI18N.get("BasicAuthenticationHint1"));
249-
hints.add(WebGoatI18N.get("BasicAuthenticationHint2"));
250-
hints.add(WebGoatI18N.get("BasicAuthenticationHint3"));
251-
hints.add(WebGoatI18N.get("BasicAuthenticationHint4"));
247+
hints.add(getLabelManager().get("BasicAuthenticationHint1"));
248+
hints.add(getLabelManager().get("BasicAuthenticationHint2"));
249+
hints.add(getLabelManager().get("BasicAuthenticationHint3"));
250+
hints.add(getLabelManager().get("BasicAuthenticationHint4"));
252251

253252
// break;
254253
// case 2:
255-
hints.add(WebGoatI18N.get("BasicAuthenticationHint5"));
256-
hints.add(WebGoatI18N.get("BasicAuthenticationHint6"));
257-
hints.add(WebGoatI18N.get("BasicAuthenticationHint7"));
258-
hints.add(WebGoatI18N.get("BasicAuthenticationHint8"));
259-
hints.add(WebGoatI18N.get("BasicAuthenticationHint9"));
254+
hints.add(getLabelManager().get("BasicAuthenticationHint5"));
255+
hints.add(getLabelManager().get("BasicAuthenticationHint6"));
256+
hints.add(getLabelManager().get("BasicAuthenticationHint7"));
257+
hints.add(getLabelManager().get("BasicAuthenticationHint8"));
258+
hints.add(getLabelManager().get("BasicAuthenticationHint9"));
260259

261260
// break;
262261
// }

src/main/java/org/owasp/webgoat/lessons/BypassHtmlFieldRestrictions.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11

22
package org.owasp.webgoat.lessons;
33

4-
import java.sql.Connection;
5-
import java.sql.ResultSet;
6-
import java.sql.ResultSetMetaData;
7-
import java.sql.SQLException;
8-
import java.sql.Statement;
94
import java.util.ArrayList;
105
import java.util.List;
116
import org.apache.ecs.Element;
@@ -17,12 +12,9 @@
1712
import org.apache.ecs.html.IMG;
1813
import org.apache.ecs.html.Input;
1914
import org.apache.ecs.html.P;
20-
import org.apache.ecs.html.PRE;
21-
import org.owasp.webgoat.session.DatabaseUtilities;
2215
import org.owasp.webgoat.session.ECSFactory;
2316
import org.owasp.webgoat.session.ParameterNotFoundException;
2417
import org.owasp.webgoat.session.WebSession;
25-
import org.owasp.webgoat.util.WebGoatI18N;
2618

2719

2820
/***************************************************************************************************
@@ -197,9 +189,9 @@ protected List<String> getHints(WebSession s)
197189
{
198190
List<String> hints = new ArrayList<String>();
199191

200-
hints.add(WebGoatI18N.get("BypassHtmlFieldRestrictionsHint1"));
201-
hints.add(WebGoatI18N.get("BypassHtmlFieldRestrictionsHint2"));
202-
hints.add(WebGoatI18N.get("BypassHtmlFieldRestrictionsHint3"));
192+
hints.add(getLabelManager().get("BypassHtmlFieldRestrictionsHint1"));
193+
hints.add(getLabelManager().get("BypassHtmlFieldRestrictionsHint2"));
194+
hints.add(getLabelManager().get("BypassHtmlFieldRestrictionsHint3"));
203195

204196
return hints;
205197
}

src/main/java/org/owasp/webgoat/lessons/CommandInjection.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.owasp.webgoat.session.WebSession;
1717
import org.owasp.webgoat.util.Exec;
1818
import org.owasp.webgoat.util.ExecResults;
19-
import org.owasp.webgoat.util.WebGoatI18N;
2019

2120

2221
/***************************************************************************************************
@@ -79,7 +78,7 @@ protected Element createContent(WebSession s)
7978
}
8079
index = index + 1;
8180
int helpFileLen = helpFile.length() - 1; // subtract 1 for the closing quote
82-
System.out.println(WebGoatI18N.get("Command")+" = [" + helpFile.substring(index, helpFileLen).trim().toLowerCase() + "]");
81+
System.out.println(getLabelManager().get("Command")+" = [" + helpFile.substring(index, helpFileLen).trim().toLowerCase() + "]");
8382
if ((osName.indexOf("Windows") != -1 && (helpFile.substring(index, helpFileLen).trim().toLowerCase()
8483
.equals("netstat -a")
8584
|| helpFile.substring(index, helpFileLen).trim().toLowerCase().equals("dir")
@@ -97,7 +96,7 @@ protected Element createContent(WebSession s)
9796
}
9897
else
9998
{
100-
s.setMessage(WebGoatI18N.get("CommandInjectionRightTrack1"));
99+
s.setMessage(getLabelManager().get("CommandInjectionRightTrack1"));
101100

102101
}
103102
}
@@ -114,7 +113,7 @@ protected Element createContent(WebSession s)
114113
}
115114
else
116115
{
117-
s.setMessage(WebGoatI18N.get("CommandInjectionRightTrack2"));
116+
s.setMessage(getLabelManager().get("CommandInjectionRightTrack2"));
118117
}
119118
}
120119
else
@@ -125,8 +124,8 @@ protected Element createContent(WebSession s)
125124
}
126125
File safeDir = new File(s.getContext().getRealPath("/lesson_plans/en"));
127126

128-
ec.addElement(new StringElement(WebGoatI18N.get("YouAreCurrentlyViewing")+"<b>"
129-
+ (helpFile.toString().length() == 0 ? "&lt;"+WebGoatI18N.get("SelectFileFromListBelow")+"&gt;" : helpFile.toString())
127+
ec.addElement(new StringElement(getLabelManager().get("YouAreCurrentlyViewing")+"<b>"
128+
+ (helpFile.toString().length() == 0 ? "&lt;"+getLabelManager().get("SelectFileFromListBelow")+"&gt;" : helpFile.toString())
130129
+ "</b>"));
131130

132131
if (!illegalCommand)
@@ -151,11 +150,11 @@ protected Element createContent(WebSession s)
151150
fileData = exec(s, cmd2);
152151
}
153152

154-
ec.addElement(new P().addElement(WebGoatI18N.get("SelectLessonPlanToView")));
153+
ec.addElement(new P().addElement(getLabelManager().get("SelectLessonPlanToView")));
155154
ec.addElement(ECSFactory.makePulldown(HELP_FILE, parseResults(results.replaceAll("(?s)\\.html",
156155
"\\.help"))));
157156
// ec.addElement( results );
158-
Element b = ECSFactory.makeButton(WebGoatI18N.get("View"));
157+
Element b = ECSFactory.makeButton(getLabelManager().get("View"));
159158
ec.addElement(b);
160159
// Strip out some of the extra html from the "help" file
161160
ec.addElement(new BR());
@@ -271,10 +270,10 @@ protected Category getDefaultCategory()
271270
protected List<String> getHints(WebSession s)
272271
{
273272
List<String> hints = new ArrayList<String>();
274-
hints.add(WebGoatI18N.get("CommandInjectionHint1"));
275-
hints.add(WebGoatI18N.get("CommandInjectionHint2"));
276-
hints.add(WebGoatI18N.get("CommandInjectionHint3"));
277-
hints.add(WebGoatI18N.get("CommandInjectionHint4"));
273+
hints.add(getLabelManager().get("CommandInjectionHint1"));
274+
hints.add(getLabelManager().get("CommandInjectionHint2"));
275+
hints.add(getLabelManager().get("CommandInjectionHint3"));
276+
hints.add(getLabelManager().get("CommandInjectionHint4"));
278277

279278
return hints;
280279
}

src/main/java/org/owasp/webgoat/lessons/HiddenFieldTampering.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.ecs.html.Table;
2323
import org.owasp.webgoat.session.ECSFactory;
2424
import org.owasp.webgoat.session.WebSession;
25-
import org.owasp.webgoat.util.WebGoatI18N;
2625

2726

2827
/***************************************************************************************************
@@ -107,7 +106,7 @@ protected Element createContent(WebSession s)
107106
total = quantity * Float.parseFloat(price);
108107
} catch (Exception e)
109108
{
110-
s.setMessage(WebGoatI18N.get("Invaild data") + this.getClass().getName());
109+
s.setMessage(getLabelManager().get("Invaild data") + this.getClass().getName());
111110
price = PRICE_TV;
112111
quantity = 1.0f;
113112
total = quantity * Float.parseFloat(PRICE_TV);
@@ -116,7 +115,7 @@ protected Element createContent(WebSession s)
116115

117116
if (price.equals(PRICE_TV))
118117
{
119-
ec.addElement(new Center().addElement(new H1().addElement(WebGoatI18N.get("ShoppingCart"))));
118+
ec.addElement(new Center().addElement(new H1().addElement(getLabelManager().get("ShoppingCart"))));
120119
ec.addElement(new BR());
121120
Table t = new Table().setCellSpacing(0).setCellPadding(2).setBorder(1).setWidth("90%").setAlign("center");
122121

@@ -126,10 +125,10 @@ protected Element createContent(WebSession s)
126125
}
127126

128127
TR tr = new TR();
129-
tr.addElement(new TH().addElement(WebGoatI18N.get("ShoppingCartItems")).setWidth("80%"));
130-
tr.addElement(new TH().addElement(WebGoatI18N.get("Price")).setWidth("10%"));
131-
tr.addElement(new TH().addElement(WebGoatI18N.get("Quantity")).setWidth("3%"));
132-
tr.addElement(new TH().addElement(WebGoatI18N.get("Total")).setWidth("7%"));
128+
tr.addElement(new TH().addElement(getLabelManager().get("ShoppingCartItems")).setWidth("80%"));
129+
tr.addElement(new TH().addElement(getLabelManager().get("Price")).setWidth("10%"));
130+
tr.addElement(new TH().addElement(getLabelManager().get("Quantity")).setWidth("3%"));
131+
tr.addElement(new TH().addElement(getLabelManager().get("Total")).setWidth("7%"));
133132
t.addElement(tr);
134133

135134
tr = new TR();
@@ -150,10 +149,10 @@ protected Element createContent(WebSession s)
150149

151150
ec.addElement(new BR());
152151
tr = new TR();
153-
tr.addElement(new TD().addElement(WebGoatI18N.get("TotalChargedCreditCard")+":"));
152+
tr.addElement(new TD().addElement(getLabelManager().get("TotalChargedCreditCard")+":"));
154153
tr.addElement(new TD().addElement(money.format(total)));
155-
tr.addElement(new TD().addElement(ECSFactory.makeButton(WebGoatI18N.get("UpdateCart"))));
156-
tr.addElement(new TD().addElement(ECSFactory.makeButton(WebGoatI18N.get("Purchase"), "validate()")));
154+
tr.addElement(new TD().addElement(ECSFactory.makeButton(getLabelManager().get("UpdateCart"))));
155+
tr.addElement(new TD().addElement(ECSFactory.makeButton(getLabelManager().get("Purchase"), "validate()")));
157156
t.addElement(tr);
158157

159158
ec.addElement(t);
@@ -170,10 +169,10 @@ protected Element createContent(WebSession s)
170169
makeSuccess(s);
171170
}
172171

173-
ec.addElement(new P().addElement(WebGoatI18N.get("TotalPriceIs")+":"));
172+
ec.addElement(new P().addElement(getLabelManager().get("TotalPriceIs")+":"));
174173
ec.addElement(new B("$" + total));
175174
ec.addElement(new BR());
176-
ec.addElement(new P().addElement(WebGoatI18N.get("ThisAmountCharged")));
175+
ec.addElement(new P().addElement(getLabelManager().get("ThisAmountCharged")));
177176
}
178177

179178
return (ec);
@@ -198,9 +197,9 @@ protected List<String> getHints(WebSession s)
198197
{
199198
List<String> hints = new ArrayList<String>();
200199

201-
hints.add(WebGoatI18N.get("HiddenFieldTamperingHint1"));
202-
hints.add(WebGoatI18N.get("HiddenFieldTamperingHint2"));
203-
hints.add(WebGoatI18N.get("HiddenFieldTamperingHint3")+ PRICE_TV +WebGoatI18N.get("HiddenFieldTamperingHint32") + PRICE_TV_HACKED );
200+
hints.add(getLabelManager().get("HiddenFieldTamperingHint1"));
201+
hints.add(getLabelManager().get("HiddenFieldTamperingHint2"));
202+
hints.add(getLabelManager().get("HiddenFieldTamperingHint3")+ PRICE_TV +getLabelManager().get("HiddenFieldTamperingHint32") + PRICE_TV_HACKED );
204203

205204
return hints;
206205
}

0 commit comments

Comments
 (0)