A first attempt at internationalization of WebGoat. For complete internationalization WebGoat needs two things:
1. Every text passage/label that appears in lessons must independent of the current language set for WebGoat. 2. Every lesson plan and solutions must be translated for each supported language. Number 1 is achieved by using webgoat/util/WebgoatI18N.java and by having every output routed through this piece of code. You no longer say hints.add("Lesson Hint 1"); or ....addElement("Shopping Cart")) but you in the lesson you say hints.add(WebGoatI18N.get("Lesson Hint1")) or ....addElement(WebGoatI18N.get("Shopping Cart"). Then WebGoatI18N looks up the corresponding string for the language set as the current lanuage and returns it. Number 2 is achieved by having subdirectories in lesson_plans corresponding to every language. That means, a lesson that has been translated to Spanish and German will be found in lesson_plans/English and lesson_plans/Spanish and lesson_plans/German. This is how WebGoat finds out about available languages: in Course.java in loadResources() it looks for lesson plans. Unlike before, now a lesson plan can be found multiple times in different "language" directories. So for every directory the lesson plan is found in, WebGoat associates this language with the lesson and also lets WebGoatI18N load the appropriate WebGoatLabels_$LANGAUGE$.properties file which contains the translations of labels. So this is what you have to do for a new language: First of all, you have to copy and translate every lesson plan that you need in the new language, and then you also have to create a WebGoatLabels_$LANGUAGE$.properties file with that labels that will be used in these lessons. Atm WebGoat crashes throws an exception when a label is missing but this can be sorted out quickly. git-svn-id: http://webgoat.googlecode.com/svn/trunk/webgoat@389 4033779f-a91e-0410-96ef-6bf7bf53c507
This commit is contained in:
@ -4,6 +4,7 @@ package org.owasp.webgoat.session;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -16,6 +17,7 @@ import org.owasp.webgoat.lessons.AbstractLesson;
|
||||
import org.owasp.webgoat.lessons.Category;
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
*
|
||||
*
|
||||
@ -59,6 +61,7 @@ public class Course
|
||||
|
||||
private WebgoatContext webgoatContext;
|
||||
|
||||
|
||||
public Course()
|
||||
{
|
||||
try
|
||||
@ -71,6 +74,9 @@ public class Course
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Take an absolute file and return the filename.
|
||||
*
|
||||
@ -368,6 +374,15 @@ public class Course
|
||||
}
|
||||
}
|
||||
|
||||
private String getLanguageFromFileName(String first, String absoluteFile){
|
||||
int p1 = absoluteFile.indexOf("/",absoluteFile.indexOf(first)+1);
|
||||
int p2 = absoluteFile.indexOf("/",p1+1);
|
||||
String langStr=absoluteFile.substring(p1+1,p2);
|
||||
|
||||
|
||||
return new String(langStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* For each lesson, set the source file and lesson file
|
||||
*/
|
||||
@ -402,7 +417,9 @@ public class Course
|
||||
// lesson " +
|
||||
// lesson.getClass().getName());
|
||||
// System.out.println("fileName: " + fileName + " == className: " + className );
|
||||
lesson.setLessonPlanFileName(absoluteFile);
|
||||
String language = getLanguageFromFileName("/lesson_plans",absoluteFile);
|
||||
lesson.setLessonPlanFileName(language, absoluteFile);
|
||||
this.webgoatContext.getWebgoatI18N().loadLanguage(language);
|
||||
}
|
||||
if (absoluteFile.startsWith("/lesson_solutions") && absoluteFile.endsWith(".html")
|
||||
&& className.endsWith(fileName))
|
||||
|
@ -23,6 +23,8 @@ import org.owasp.webgoat.lessons.AbstractLesson;
|
||||
import org.owasp.webgoat.lessons.Category;
|
||||
import org.owasp.webgoat.lessons.RandomLessonAdapter;
|
||||
import org.owasp.webgoat.lessons.SequentialLessonAdapter;
|
||||
import org.owasp.webgoat.util.WebGoatI18N;
|
||||
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
@ -143,6 +145,8 @@ public class WebSession
|
||||
|
||||
public final static String DEBUG = "debug";
|
||||
|
||||
public final static String LANGUAGE = "language";
|
||||
|
||||
/**
|
||||
* Description of the Field
|
||||
*/
|
||||
@ -198,6 +202,10 @@ public class WebSession
|
||||
|
||||
private int currentMenu;
|
||||
|
||||
private String currentLanguage = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for the WebSession object
|
||||
*
|
||||
@ -215,7 +223,9 @@ public class WebSession
|
||||
showSource = webgoatContext.isShowSource();
|
||||
showSolution = webgoatContext.isShowSolution();
|
||||
showRequest = webgoatContext.isShowRequest();
|
||||
currentLanguage = webgoatContext.getDefaultLanguage();
|
||||
this.context = context;
|
||||
|
||||
course = new Course();
|
||||
course.loadCourses(webgoatContext, context, "/");
|
||||
}
|
||||
@ -290,6 +300,9 @@ public class WebSession
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<String> getRoles()
|
||||
{
|
||||
List<String> roles = new ArrayList<String>();
|
||||
@ -591,20 +604,6 @@ public class WebSession
|
||||
return (isAdmin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the admin flag - this routine is ONLY
|
||||
* here to allow someone a backdoor to setting the
|
||||
* user up as an admin.
|
||||
*
|
||||
* This is also used by the WebSession to set the admin, but the method
|
||||
* should be private
|
||||
*
|
||||
* @param state
|
||||
*/
|
||||
public void setAdmin(boolean state)
|
||||
{
|
||||
isAdmin = state;
|
||||
}
|
||||
/**
|
||||
* Gets the hackedAdmin attribute of the WebSession object
|
||||
*
|
||||
@ -728,7 +727,7 @@ public class WebSession
|
||||
*/
|
||||
public boolean isUser()
|
||||
{
|
||||
return (!isAdmin() && !isChallenge());
|
||||
return (!isAdmin && !isChallenge());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -834,6 +833,12 @@ public class WebSession
|
||||
{
|
||||
myParser.update(request);
|
||||
}
|
||||
|
||||
if(myParser.getRawParameter(LANGUAGE,null)!=null){
|
||||
this.currentLanguage=new String(myParser.getRawParameter(LANGUAGE,null));
|
||||
WebGoatI18N.setCurrentLanguage(this.currentLanguage);
|
||||
}
|
||||
|
||||
|
||||
// System.out.println("Current Screen 1: " + currentScreen );
|
||||
// System.out.println("Previous Screen 1: " + previousScreen );
|
||||
@ -965,8 +970,8 @@ public class WebSession
|
||||
|
||||
}
|
||||
|
||||
setAdmin(request.isUserInRole(WEBGOAT_ADMIN));
|
||||
isHackedAdmin = myParser.getBooleanParameter(ADMIN, isAdmin());
|
||||
isAdmin = request.isUserInRole(WEBGOAT_ADMIN);
|
||||
isHackedAdmin = myParser.getBooleanParameter(ADMIN, isAdmin);
|
||||
if (isHackedAdmin)
|
||||
{
|
||||
System.out.println("Hacked admin");
|
||||
@ -1005,10 +1010,7 @@ public class WebSession
|
||||
{
|
||||
RandomLessonAdapter rla = (RandomLessonAdapter) al;
|
||||
rla.setStage(this, rla.getStages()[0]);
|
||||
}
|
||||
else if(al instanceof org.owasp.webgoat.lessons.MaliciousFileExecution) {
|
||||
((org.owasp.webgoat.lessons.MaliciousFileExecution) al).restartLesson(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1093,4 +1095,10 @@ public class WebSession
|
||||
{
|
||||
return webgoatContext;
|
||||
}
|
||||
|
||||
public String getCurrrentLanguage() {
|
||||
return currentLanguage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ package org.owasp.webgoat.session;
|
||||
import java.util.Iterator;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
import org.owasp.webgoat.util.WebGoatI18N;
|
||||
|
||||
|
||||
public class WebgoatContext
|
||||
{
|
||||
@ -39,6 +41,8 @@ public class WebgoatContext
|
||||
public final static String FEEDBACK_ADDRESS = "email";
|
||||
|
||||
public final static String DEBUG = "debug";
|
||||
|
||||
public final static String DEFAULTLANGUAGE = "DefaultLanguage";
|
||||
|
||||
private String databaseConnectionString;
|
||||
|
||||
@ -75,6 +79,10 @@ public class WebgoatContext
|
||||
private String servletName;
|
||||
|
||||
private HttpServlet servlet;
|
||||
|
||||
private String defaultLanguage;
|
||||
|
||||
private WebGoatI18N webgoati18n = null;
|
||||
|
||||
public WebgoatContext(HttpServlet servlet)
|
||||
{
|
||||
@ -100,7 +108,10 @@ public class WebgoatContext
|
||||
showRequest = "true".equals(getParameter(servlet, SHOWREQUEST));
|
||||
isDebug = "true".equals(getParameter(servlet, DEBUG));
|
||||
servletName = servlet.getServletName();
|
||||
|
||||
defaultLanguage = getParameter(servlet,DEFAULTLANGUAGE)!=null ? new String(getParameter(servlet, DEFAULTLANGUAGE)): new String("English");
|
||||
|
||||
webgoati18n = new WebGoatI18N(this);
|
||||
|
||||
}
|
||||
|
||||
private String getParameter(HttpServlet servlet, String key)
|
||||
@ -222,4 +233,16 @@ public class WebgoatContext
|
||||
return showSolution;
|
||||
}
|
||||
|
||||
public String getDefaultLanguage() {
|
||||
return defaultLanguage;
|
||||
}
|
||||
|
||||
public void setWebgoatiI18N(WebGoatI18N webgoati18n) {
|
||||
this.webgoati18n = webgoati18n;
|
||||
}
|
||||
|
||||
public WebGoatI18N getWebgoatI18N() {
|
||||
return webgoati18n;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user