diff --git a/webgoat-classloader/src/main/java/org/owasp/webgoat/classloader/PluginClassLoader.java b/webgoat-classloader/src/main/java/org/owasp/webgoat/classloader/PluginClassLoader.java
index 6f7d4d683..4be6fefda 100644
--- a/webgoat-classloader/src/main/java/org/owasp/webgoat/classloader/PluginClassLoader.java
+++ b/webgoat-classloader/src/main/java/org/owasp/webgoat/classloader/PluginClassLoader.java
@@ -14,15 +14,30 @@ import java.util.List;
*
* With this loader we can add jars we load during the plugin loading and the jsp will pick it up because this is
* the same classloader.
+ *
+ * @version $Id: $Id
*/
public class PluginClassLoader extends WebappClassLoader {
+ /**
+ *
Constructor for PluginClassLoader.
+ */
public PluginClassLoader() {
}
+ /**
+ * Constructor for PluginClassLoader.
+ *
+ * @param parent a {@link java.lang.ClassLoader} object.
+ */
public PluginClassLoader(ClassLoader parent) {
super(parent);
}
+ /**
+ * addURL.
+ *
+ * @param urls a {@link java.util.List} object.
+ */
public void addURL(List urls) {
for (URL url : urls) {
super.addURL(url);
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/Catcher.java b/webgoat-container/src/main/java/org/owasp/webgoat/Catcher.java
index ed26d25d6..6f70157b1 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/Catcher.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/Catcher.java
@@ -1,120 +1,122 @@
-
-package org.owasp.webgoat;
-
-import java.io.IOException;
-import java.util.Enumeration;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.session.Course;
-import org.owasp.webgoat.session.WebSession;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce Mayhew WebGoat
- * @created March 13, 2007
- */
-public class Catcher extends HammerHead
-{
-
- /**
- *
- */
- private static final long serialVersionUID = 7441856110845727651L;
-
- /**
- * Description of the Field
- */
- public final static String START_SOURCE_SKIP = "START_OMIT_SOURCE";
-
- public final static String END_SOURCE_SKIP = "END_OMIT_SOURCE";
-
- public static final String PROPERTY = "PROPERTY";
-
- public static final String EMPTY_STRING = "";
-
- /**
- * Description of the Method
- *
- * @param request
- * Description of the Parameter
- * @param response
- * Description of the Parameter
- * @exception IOException
- * Description of the Exception
- * @exception ServletException
- * Description of the Exception
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
- {
- try
- {
- // System.out.println( "Entering doPost: " );
- // System.out.println( " - request " + request);
- // System.out.println( " - principle: " + request.getUserPrincipal() );
- // setCacheHeaders(response, 0);
- WebSession session = (WebSession) request.getSession(true).getAttribute(WebSession.SESSION);
- session.update(request, response, this.getServletName()); // FIXME: Too much in this
- // call.
-
- int scr = session.getCurrentScreen();
- Course course = session.getCourse();
- AbstractLesson lesson = course.getLesson(session, scr, AbstractLesson.USER_ROLE);
-
- log(request, lesson.getClass().getName() + " | " + session.getParser().toString());
-
- String property = new String(session.getParser().getStringParameter(PROPERTY, EMPTY_STRING));
-
- // if the PROPERTY parameter is available - write all the parameters to the
- // property file. No other control parameters are supported at this time.
- if (!property.equals(EMPTY_STRING))
- {
- Enumeration e = session.getParser().getParameterNames();
-
- while (e.hasMoreElements())
- {
- String name = (String) e.nextElement();
- String value = session.getParser().getParameterValues(name)[0];
- lesson.getLessonTracker(session).getLessonProperties().setProperty(name, value);
- }
- }
- lesson.getLessonTracker(session).store(session, lesson);
-
- // BDM MC
-// WEB-173 - removed for testing, as plugin architecture would not allow this
-// if ( request.getParameter("Deleter") != null ){org.owasp.webgoat.lessons.BlindScript.StaticDeleter();}
-
- } catch (Throwable t)
- {
- t.printStackTrace();
- log("ERROR: " + t);
- }
- }
-}
+
+package org.owasp.webgoat;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.owasp.webgoat.lessons.AbstractLesson;
+import org.owasp.webgoat.session.Course;
+import org.owasp.webgoat.session.WebSession;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce Mayhew WebGoat
+ * @since March 13, 2007
+ * @version $Id: $Id
+ */
+public class Catcher extends HammerHead
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7441856110845727651L;
+
+ /**
+ * Description of the Field
+ */
+ public final static String START_SOURCE_SKIP = "START_OMIT_SOURCE";
+
+ /** Constant END_SOURCE_SKIP="END_OMIT_SOURCE"
*/
+ public final static String END_SOURCE_SKIP = "END_OMIT_SOURCE";
+
+ /** Constant PROPERTY="PROPERTY"
*/
+ public static final String PROPERTY = "PROPERTY";
+
+ /** Constant EMPTY_STRING=""
*/
+ public static final String EMPTY_STRING = "";
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ * @exception IOException
+ * Description of the Exception
+ * @exception ServletException
+ * Description of the Exception
+ */
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ try
+ {
+ // System.out.println( "Entering doPost: " );
+ // System.out.println( " - request " + request);
+ // System.out.println( " - principle: " + request.getUserPrincipal() );
+ // setCacheHeaders(response, 0);
+ WebSession session = (WebSession) request.getSession(true).getAttribute(WebSession.SESSION);
+ session.update(request, response, this.getServletName()); // FIXME: Too much in this
+ // call.
+
+ int scr = session.getCurrentScreen();
+ Course course = session.getCourse();
+ AbstractLesson lesson = course.getLesson(session, scr, AbstractLesson.USER_ROLE);
+
+ log(request, lesson.getClass().getName() + " | " + session.getParser().toString());
+
+ String property = new String(session.getParser().getStringParameter(PROPERTY, EMPTY_STRING));
+
+ // if the PROPERTY parameter is available - write all the parameters to the
+ // property file. No other control parameters are supported at this time.
+ if (!property.equals(EMPTY_STRING))
+ {
+ Enumeration e = session.getParser().getParameterNames();
+
+ while (e.hasMoreElements())
+ {
+ String name = (String) e.nextElement();
+ String value = session.getParser().getParameterValues(name)[0];
+ lesson.getLessonTracker(session).getLessonProperties().setProperty(name, value);
+ }
+ }
+ lesson.getLessonTracker(session).store(session, lesson);
+
+ // BDM MC
+// WEB-173 - removed for testing, as plugin architecture would not allow this
+// if ( request.getParameter("Deleter") != null ){org.owasp.webgoat.lessons.BlindScript.StaticDeleter();}
+
+ } catch (Throwable t)
+ {
+ t.printStackTrace();
+ log("ERROR: " + t);
+ }
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java b/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java
index 98b25c131..ab48aa74c 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/HammerHead.java
@@ -55,11 +55,11 @@ import java.util.TimeZone;
*
* For details, please see http://webgoat.github.io
*
- *
* @author Jeff Williams Aspect
* Security
* @author Bruce Mayhew WebGoat
- * @created October 28, 2003
+ * @since October 28, 2003
+ * @version $Id: $Id
*/
public class HammerHead extends HttpServlet {
@@ -95,10 +95,9 @@ public class HammerHead extends HttpServlet {
private WebgoatContext webgoatContext = null;
/**
- * Description of the Method
+ * {@inheritDoc}
*
- * @param request Description of the Parameter
- * @param response Description of the Parameter
+ * Description of the Method
* @exception IOException Description of the Exception
* @exception ServletException Description of the Exception
*/
@@ -108,10 +107,9 @@ public class HammerHead extends HttpServlet {
}
/**
- * Description of the Method
+ * {@inheritDoc}
*
- * @param request Description of the Parameter
- * @param response Description of the Parameter
+ * Description of the Method
* @exception IOException Description of the Exception
* @exception ServletException Description of the Exception
*/
@@ -227,9 +225,9 @@ public class HammerHead extends HttpServlet {
}
/**
- * Return information about this servlet
+ * {@inheritDoc}
*
- * @return The servletInfo value
+ * Return information about this servlet
*/
@Override
public String getServletInfo() {
@@ -237,9 +235,9 @@ public class HammerHead extends HttpServlet {
}
/**
- * Return properties path
+ * {@inheritDoc}
*
- * @throws javax.servlet.ServletException
+ * Return properties path
*/
@Override
public void init() throws ServletException {
@@ -371,7 +369,7 @@ public class HammerHead extends HttpServlet {
* @param response Description of the Parameter
* @param context Description of the Parameter
* @return Description of the Return Value
- * @throws java.io.IOException
+ * @throws java.io.IOException if any.
*/
protected WebSession updateSession(HttpServletRequest request, HttpServletResponse response, ServletContext context)
throws IOException {
@@ -415,9 +413,10 @@ public class HammerHead extends HttpServlet {
* Description of the Method
*
* @param s Description of the Parameter
- * @param screen
+ * @param screen a {@link org.owasp.webgoat.session.Screen} object.
* @param response Description of the Parameter
* @exception IOException Description of the Exception
+ * @throws java.io.IOException if any.
*/
protected void writeScreen(WebSession s, Screen screen, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/LessonSource.java b/webgoat-container/src/main/java/org/owasp/webgoat/LessonSource.java
index 8223d5142..d7e00c9f8 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/LessonSource.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/LessonSource.java
@@ -1,185 +1,193 @@
-package org.owasp.webgoat;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.session.Course;
-import org.owasp.webgoat.session.WebSession;
-
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce Mayhew WebGoat
- * @created October 28, 2003
- */
-public class LessonSource extends HammerHead {
-
- /**
- *
- */
- private static final long serialVersionUID = 2588430536196446145L;
-
- /**
- * Description of the Field
- */
- public final static String START_SOURCE_SKIP = "START_OMIT_SOURCE";
-
- public final static String END_SOURCE_SKIP = "END_OMIT_SOURCE";
-
- /**
- * Description of the Method
- *
- * @param request Description of the Parameter
- * @param response Description of the Parameter
- * @exception IOException Description of the Exception
- * @exception ServletException Description of the Exception
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
- String source = null;
-
- try {
- // System.out.println( "Entering doPost: " );
- // System.out.println( " - request " + request);
- // System.out.println( " - principle: " + request.getUserPrincipal()
- // );
- // setCacheHeaders(response, 0);
- WebSession session = (WebSession) request.getSession(true).getAttribute(WebSession.SESSION);
- // FIXME: Too much in this call.
- session.update(request, response, this.getServletName());
-
- boolean showSolution = session.getParser().getBooleanParameter("solution", false);
- boolean showSource = session.getParser().getBooleanParameter("source", false);
- if (showSolution) {
-
- // Get the Java solution of the lesson.
- source = getSolution(session);
-
- int scr = session.getCurrentScreen();
- Course course = session.getCourse();
- AbstractLesson lesson = course.getLesson(session, scr, AbstractLesson.USER_ROLE);
- lesson.getLessonTracker(session).setViewedSolution(true);
-
- } else if (showSource) {
-
- // Get the Java source of the lesson. FIXME: Not needed
- source = getSource(session);
-
- int scr = session.getCurrentScreen();
- Course course = session.getCourse();
- AbstractLesson lesson = course.getLesson(session, scr, AbstractLesson.USER_ROLE);
- lesson.getLessonTracker(session).setViewedSource(true);
- }
- } catch (Throwable t) {
- t.printStackTrace();
- log("ERROR: " + t);
- } finally {
- try {
- this.writeSource(source, response);
- } catch (Throwable thr) {
- thr.printStackTrace();
- log(request, "Could not write error screen: " + thr.getMessage());
- }
- // System.out.println( "Leaving doPost: " );
-
- }
- }
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- * @return Description of the Return Value
- */
- protected String getSource(WebSession s) {
-
- String source = null;
- int scr = s.getCurrentScreen();
- Course course = s.getCourse();
-
- if (s.isUser() || s.isChallenge()) {
-
- AbstractLesson lesson = course.getLesson(s, scr, AbstractLesson.USER_ROLE);
-
- if (lesson != null) {
- source = lesson.getSource(s);
- }
- }
- if (source == null) {
- return "Source code is not available. Contact "
- + s.getWebgoatContext().getFeedbackAddressHTML();
- }
- return (source.replaceAll("(?s)" + START_SOURCE_SKIP + ".*" + END_SOURCE_SKIP,
- "Code Section Deliberately Omitted"));
- }
-
- protected String getSolution(WebSession s) {
-
- String source = null;
- int scr = s.getCurrentScreen();
- Course course = s.getCourse();
-
- if (s.isUser() || s.isChallenge()) {
-
- AbstractLesson lesson = course.getLesson(s, scr, AbstractLesson.USER_ROLE);
-
- if (lesson != null) {
- source = lesson.getSolution(s);
- }
- }
- if (source == null) {
- return "Solution is not available. Contact "
- + s.getWebgoatContext().getFeedbackAddressHTML();
- }
- return (source);
- }
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- * @param response Description of the Parameter
- * @exception IOException Description of the Exception
- */
- protected void writeSource(String s, HttpServletResponse response) throws IOException {
- response.setContentType("text/html");
-
- PrintWriter out = response.getWriter();
-
- if (s == null) {
- s = new String();
- }
-
- out.print(s);
- out.close();
- }
-}
+package org.owasp.webgoat;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.owasp.webgoat.lessons.AbstractLesson;
+import org.owasp.webgoat.session.Course;
+import org.owasp.webgoat.session.WebSession;
+
+/**
+ * *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project
+ * utility. For details, please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
+ * for free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce Mayhew WebGoat
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class LessonSource extends HammerHead {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2588430536196446145L;
+
+ /**
+ * Description of the Field
+ */
+ public final static String START_SOURCE_SKIP = "START_OMIT_SOURCE";
+
+ /** Constant END_SOURCE_SKIP="END_OMIT_SOURCE"
*/
+ public final static String END_SOURCE_SKIP = "END_OMIT_SOURCE";
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ * @exception IOException Description of the Exception
+ * @exception ServletException Description of the Exception
+ */
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
+ String source = null;
+
+ try {
+ // System.out.println( "Entering doPost: " );
+ // System.out.println( " - request " + request);
+ // System.out.println( " - principle: " + request.getUserPrincipal()
+ // );
+ // setCacheHeaders(response, 0);
+ WebSession session = (WebSession) request.getSession(true).getAttribute(WebSession.SESSION);
+ // FIXME: Too much in this call.
+ session.update(request, response, this.getServletName());
+
+ boolean showSolution = session.getParser().getBooleanParameter("solution", false);
+ boolean showSource = session.getParser().getBooleanParameter("source", false);
+ if (showSolution) {
+
+ // Get the Java solution of the lesson.
+ source = getSolution(session);
+
+ int scr = session.getCurrentScreen();
+ Course course = session.getCourse();
+ AbstractLesson lesson = course.getLesson(session, scr, AbstractLesson.USER_ROLE);
+ lesson.getLessonTracker(session).setViewedSolution(true);
+
+ } else if (showSource) {
+
+ // Get the Java source of the lesson. FIXME: Not needed
+ source = getSource(session);
+
+ int scr = session.getCurrentScreen();
+ Course course = session.getCourse();
+ AbstractLesson lesson = course.getLesson(session, scr, AbstractLesson.USER_ROLE);
+ lesson.getLessonTracker(session).setViewedSource(true);
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ log("ERROR: " + t);
+ } finally {
+ try {
+ this.writeSource(source, response);
+ } catch (Throwable thr) {
+ thr.printStackTrace();
+ log(request, "Could not write error screen: " + thr.getMessage());
+ }
+ // System.out.println( "Leaving doPost: " );
+
+ }
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s Description of the Parameter
+ * @return Description of the Return Value
+ */
+ protected String getSource(WebSession s) {
+
+ String source = null;
+ int scr = s.getCurrentScreen();
+ Course course = s.getCourse();
+
+ if (s.isUser() || s.isChallenge()) {
+
+ AbstractLesson lesson = course.getLesson(s, scr, AbstractLesson.USER_ROLE);
+
+ if (lesson != null) {
+ source = lesson.getSource(s);
+ }
+ }
+ if (source == null) {
+ return "Source code is not available. Contact "
+ + s.getWebgoatContext().getFeedbackAddressHTML();
+ }
+ return (source.replaceAll("(?s)" + START_SOURCE_SKIP + ".*" + END_SOURCE_SKIP,
+ "Code Section Deliberately Omitted"));
+ }
+
+ /**
+ * getSolution.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ protected String getSolution(WebSession s) {
+
+ String source = null;
+ int scr = s.getCurrentScreen();
+ Course course = s.getCourse();
+
+ if (s.isUser() || s.isChallenge()) {
+
+ AbstractLesson lesson = course.getLesson(s, scr, AbstractLesson.USER_ROLE);
+
+ if (lesson != null) {
+ source = lesson.getSolution(s);
+ }
+ }
+ if (source == null) {
+ return "Solution is not available. Contact "
+ + s.getWebgoatContext().getFeedbackAddressHTML();
+ }
+ return (source);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s Description of the Parameter
+ * @param response Description of the Parameter
+ * @exception IOException Description of the Exception
+ * @throws java.io.IOException if any.
+ */
+ protected void writeSource(String s, HttpServletResponse response) throws IOException {
+ response.setContentType("text/html");
+
+ PrintWriter out = response.getWriter();
+
+ if (s == null) {
+ s = new String();
+ }
+
+ out.print(s);
+ out.close();
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/application/Application.java b/webgoat-container/src/main/java/org/owasp/webgoat/application/Application.java
index 9f7f156f4..7ad64dbb5 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/application/Application.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/application/Application.java
@@ -12,6 +12,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
* Singleton which is created on context startup
*
* @author rlawson
+ * @version $Id: $Id
*/
public class Application {
@@ -21,6 +22,11 @@ public class Application {
}
+ /**
+ * getInstance.
+ *
+ * @return a {@link org.owasp.webgoat.application.Application} object.
+ */
public static final Application getInstance() {
return INSTANCE;
}
@@ -30,6 +36,8 @@ public class Application {
private String name = "WebGoat";
/**
+ * Getter for the field version
.
+ *
* @return the version
*/
public String getVersion() {
@@ -37,6 +45,8 @@ public class Application {
}
/**
+ * Setter for the field version
.
+ *
* @param version the version to set
*/
public void setVersion(String version) {
@@ -46,6 +56,8 @@ public class Application {
}
/**
+ * Getter for the field build
.
+ *
* @return the build
*/
public String getBuild() {
@@ -53,6 +65,8 @@ public class Application {
}
/**
+ * Setter for the field build
.
+ *
* @param build the build to set
*/
public void setBuild(String build) {
@@ -62,6 +76,8 @@ public class Application {
}
/**
+ * Getter for the field name
.
+ *
* @return the name
*/
public String getName() {
@@ -69,6 +85,8 @@ public class Application {
}
/**
+ * Setter for the field name
.
+ *
* @param name the name to set
*/
public void setName(String name) {
@@ -77,6 +95,7 @@ public class Application {
}
}
+ /** {@inheritDoc} */
@Override
public String toString() {
return new ToStringBuilder(this).
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/application/WebGoatServletListener.java b/webgoat-container/src/main/java/org/owasp/webgoat/application/WebGoatServletListener.java
index 2a0789cfc..8b770cff5 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/application/WebGoatServletListener.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/application/WebGoatServletListener.java
@@ -17,9 +17,11 @@ import java.util.jar.Manifest;
* Web application lifecycle listener.
*
* @author rlawson
+ * @version $Id: $Id
*/
public class WebGoatServletListener implements ServletContextListener {
+ /** {@inheritDoc} */
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
@@ -27,6 +29,7 @@ public class WebGoatServletListener implements ServletContextListener {
setApplicationVariables(context);
}
+ /** {@inheritDoc} */
@Override
public void contextDestroyed(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/controller/About.java b/webgoat-container/src/main/java/org/owasp/webgoat/controller/About.java
index 479f83a74..094d9285f 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/controller/About.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/controller/About.java
@@ -16,8 +16,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
/**
+ * About class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class About {
@@ -25,6 +27,14 @@ public class About {
final Logger logger = LoggerFactory.getLogger(About.class);
private static final String WELCOMED = "welcomed";
+ /**
+ * welcome.
+ *
+ * @param request a {@link javax.servlet.http.HttpServletRequest} object.
+ * @param error a {@link java.lang.String} object.
+ * @param logout a {@link java.lang.String} object.
+ * @return a {@link org.springframework.web.servlet.ModelAndView} object.
+ */
@RequestMapping(value = "about.mvc", method = RequestMethod.GET)
public ModelAndView welcome(HttpServletRequest request,
@RequestParam(value = "error", required = false) String error,
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Login.java b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Login.java
index 612c1d727..6f9021f19 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Login.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Login.java
@@ -12,12 +12,21 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
/**
+ * Login class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class Login {
+ /**
+ * login.
+ *
+ * @param error a {@link java.lang.String} object.
+ * @param logout a {@link java.lang.String} object.
+ * @return a {@link org.springframework.web.servlet.ModelAndView} object.
+ */
@RequestMapping(value = "login.mvc", method = RequestMethod.GET)
public ModelAndView login(
@RequestParam(value = "error", required = false) String error,
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Logout.java b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Logout.java
index 2c2e39a85..92e236a1c 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Logout.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Logout.java
@@ -14,14 +14,23 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
/**
+ * Logout class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class Logout {
final Logger logger = LoggerFactory.getLogger(Logout.class);
+ /**
+ * logout.
+ *
+ * @param error a {@link java.lang.String} object.
+ * @param logout a {@link java.lang.String} object.
+ * @return a {@link org.springframework.web.servlet.ModelAndView} object.
+ */
@RequestMapping(value = "logout.mvc", method = RequestMethod.GET)
public ModelAndView logout(
@RequestParam(value = "error", required = false) String error,
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Start.java b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Start.java
index efaa1ce5f..300209a9d 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Start.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Start.java
@@ -24,8 +24,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
/**
+ * Start class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class Start {
@@ -37,6 +39,14 @@ public class Start {
@Autowired
private ServletContext servletContext;
+ /**
+ * start.
+ *
+ * @param request a {@link javax.servlet.http.HttpServletRequest} object.
+ * @param error a {@link java.lang.String} object.
+ * @param logout a {@link java.lang.String} object.
+ * @return a {@link org.springframework.web.servlet.ModelAndView} object.
+ */
@RequestMapping(value = "start.mvc", method = {RequestMethod.GET, RequestMethod.POST})
public ModelAndView start(HttpServletRequest request,
@RequestParam(value = "error", required = false) String error,
@@ -82,6 +92,12 @@ public class Start {
return role;
}
+ /**
+ * checkWebSession.
+ *
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a boolean.
+ */
public boolean checkWebSession(HttpSession session) {
Object o = session.getAttribute(WebSession.SESSION);
if (o == null) {
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Welcome.java b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Welcome.java
index 5d2f9e93b..050b0a79f 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/controller/Welcome.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/controller/Welcome.java
@@ -16,8 +16,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
/**
+ * Welcome class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class Welcome {
@@ -25,6 +27,14 @@ public class Welcome {
final Logger logger = LoggerFactory.getLogger(Welcome.class);
private static final String WELCOMED = "welcomed";
+ /**
+ * welcome.
+ *
+ * @param request a {@link javax.servlet.http.HttpServletRequest} object.
+ * @param error a {@link java.lang.String} object.
+ * @param logout a {@link java.lang.String} object.
+ * @return a {@link org.springframework.web.servlet.ModelAndView} object.
+ */
@RequestMapping(value = "welcome.mvc", method = RequestMethod.GET)
public ModelAndView welcome(HttpServletRequest request,
@RequestParam(value = "error", required = false) String error,
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/AbstractLesson.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/AbstractLesson.java
index 45bfea76f..4ec41095e 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/AbstractLesson.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/AbstractLesson.java
@@ -1,836 +1,1029 @@
-package org.owasp.webgoat.lessons;
-
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Body;
-import org.apache.ecs.html.Form;
-import org.apache.ecs.html.Head;
-import org.apache.ecs.html.Html;
-import org.apache.ecs.html.IMG;
-import org.apache.ecs.html.PRE;
-import org.apache.ecs.html.Title;
-import org.owasp.webgoat.session.ParameterNotFoundException;
-import org.owasp.webgoat.session.Screen;
-import org.owasp.webgoat.session.WebSession;
-import org.owasp.webgoat.session.WebgoatContext;
-import org.owasp.webgoat.session.WebgoatProperties;
-import org.owasp.webgoat.util.BeanProvider;
-import org.owasp.webgoat.util.LabelManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at
- * https://github.com/WebGoat/WebGoat, a repository for free software projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce Mayhew WebGoat
- * @created October 28, 2003
- */
-public abstract class AbstractLesson extends Screen implements Comparable {
-
- private static final Logger logger = LoggerFactory.getLogger(AbstractLesson.class);
-
- /**
- * Description of the Field
- */
- public final static String ADMIN_ROLE = "admin";
-
- public final static String CHALLENGE_ROLE = "challenge";
-
- /**
- * Description of the Field
- */
- public final static String HACKED_ADMIN_ROLE = "hacked_admin";
-
- /**
- * Description of the Field
- */
- public final static String USER_ROLE = "user";
-
- private static int count = 1;
-
- private Integer id = null;
-
- final static IMG nextGrey = new IMG("images/right16.gif").setAlt("Next").setBorder(0).setHspace(0).setVspace(0);
-
- final static IMG previousGrey = new IMG("images/left14.gif").setAlt("Previous").setBorder(0).setHspace(0)
- .setVspace(0);
-
- private Integer ranking;
-
- private Category category;
-
- private boolean hidden;
-
- private String sourceFileName;
-
- private Map lessonPlanFileName = new HashMap();
-
- private String lessonSolutionFileName;
-
- private WebgoatContext webgoatContext;
-
- private LinkedList availableLanguages = new LinkedList();
-
- private String defaultLanguage = "en";
-
- private LabelManager labelManager = null;
-
- /**
- * Constructor for the Lesson object
- */
- public AbstractLesson() {
- id = new Integer(++count);
- }
-
- public String getName() {
- String className = getClass().getName();
- return className.substring(className.lastIndexOf('.') + 1);
- }
-
- public void setRanking(Integer ranking) {
- this.ranking = ranking;
- }
-
- public void setHidden(boolean hidden) {
- this.hidden = hidden;
- }
-
- public void update(WebgoatProperties properties) {
- String className = getClass().getName();
- className = className.substring(className.lastIndexOf(".") + 1);
- setRanking(new Integer(properties.getIntProperty("lesson." + className + ".ranking", getDefaultRanking()
- .intValue())));
- String categoryRankingKey = "category." + getDefaultCategory().getName() + ".ranking";
- // System.out.println("Category ranking key: " + categoryRankingKey);
- Category tempCategory = Category.getCategory(getDefaultCategory().getName());
- tempCategory.setRanking(new Integer(properties.getIntProperty(categoryRankingKey, getDefaultCategory()
- .getRanking().intValue())));
- category = tempCategory;
- setHidden(properties.getBooleanProperty("lesson." + className + ".hidden", getDefaultHidden()));
- // System.out.println(className + " in " + tempCategory.getName() + "
- // (Category Ranking: " + tempCategory.getRanking() + " Lesson ranking:
- // " + getRanking() + ", hidden:" + hidden +")");
- }
-
- public boolean isCompleted(WebSession s) {
- return getLessonTracker(s, this).getCompleted();
- }
-
- /**
- * Gets the credits attribute of the AbstractLesson object
- *
- * @return The credits value
- * @deprecated - Credits have moved to the about page
- */
- public abstract Element getCredits();
-
- /**
- * Description of the Method
- *
- * @param obj Description of the Parameter
- * @return Description of the Return Value
- */
- public int compareTo(Object obj) {
- return this.getRanking().compareTo(((AbstractLesson) obj).getRanking());
- }
-
- /**
- * Description of the Method
- *
- * @param obj Description of the Parameter
- * @return Description of the Return Value
- */
- public boolean equals(Object obj) {
- return this.getScreenId() == ((AbstractLesson) obj).getScreenId();
- }
-
- /**
- * Gets the category attribute of the Lesson object
- *
- * @return The category value
- */
- public Category getCategory() {
- return category;
- }
-
- protected abstract Integer getDefaultRanking();
-
- protected abstract Category getDefaultCategory();
-
- protected abstract boolean getDefaultHidden();
-
- /**
- * Gets the fileMethod attribute of the Lesson class
- *
- * @param reader Description of the Parameter
- * @param methodName Description of the Parameter
- * @param numbers Description of the Parameter
- * @return The fileMethod value
- */
- public static String getFileMethod(BufferedReader reader, String methodName, boolean numbers) {
- int count = 0;
- StringBuffer sb = new StringBuffer();
- boolean echo = false;
- boolean startCount = false;
- int parenCount = 0;
-
- try {
- String line;
-
- while ((line = reader.readLine()) != null) {
- if ((line.indexOf(methodName) != -1)
- && ((line.indexOf("public") != -1) || (line.indexOf("protected") != -1) || (line
- .indexOf("private") != -1))) {
- echo = true;
- startCount = true;
- }
-
- if (echo && startCount) {
- if (numbers) {
- sb.append(pad(++count) + " ");
- }
-
- sb.append(line + "\n");
- }
-
- if (echo && (line.indexOf("{") != -1)) {
- parenCount++;
- }
-
- if (echo && (line.indexOf("}") != -1)) {
- parenCount--;
-
- if (parenCount == 0) {
- startCount = false;
- echo = false;
- }
- }
- }
-
- reader.close();
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- }
-
- return (sb.toString());
- }
-
- /**
- * Reads text from a file into an ElementContainer. Each line in the file is
- * represented in the ElementContainer by a StringElement. Each
- * StringElement is appended with a new-line character.
- *
- * @param reader Description of the Parameter
- * @param numbers Description of the Parameter
- * @return Description of the Return Value
- */
- public static String readFromFile(BufferedReader reader, boolean numbers) {
- return (getFileText(reader, numbers));
- }
-
- /**
- * Gets the fileText attribute of the Screen class
- *
- * @param reader Description of the Parameter
- * @param numbers Description of the Parameter
- * @return The fileText value
- */
- public static String getFileText(BufferedReader reader, boolean numbers) {
- int count = 0;
- StringBuffer sb = new StringBuffer();
-
- try {
- String line;
-
- while ((line = reader.readLine()) != null) {
- if (numbers) {
- sb.append(pad(++count) + " ");
- }
- sb.append(line + System.getProperty("line.separator"));
- }
-
- reader.close();
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- }
-
- return (sb.toString());
- }
-
- /**
- * Will this screen be included in an enterprise edition.
- *
- * @return The ranking value
- */
- public boolean isEnterprise() {
- return false;
- }
-
- /**
- * Gets the hintCount attribute of the Lesson object
- *
- * @param s The user's WebSession
- * @return The hintCount value
- */
- public int getHintCount(WebSession s) {
- return getHints(s).size();
- }
-
- protected abstract List getHints(WebSession s);
-
- // @TODO we need to restrict access at the service layer
- // rather than passing session object around
- public List getHintsPublic(WebSession s) {
- List hints = getHints(s);
- return hints;
- }
-
- /**
- * Fill in a minor hint that will help people who basically get it, but are
- * stuck on somthing silly.
- *
- * @param s The users WebSession
- * @return The hint1 value
- */
- public String getHint(WebSession s, int hintNumber) {
- return "Hint: " + getHints(s).get(hintNumber);
- }
-
- /**
- * Gets the instructions attribute of the AbstractLesson object
- *
- * @return The instructions value
- */
- public abstract String getInstructions(WebSession s);
-
- /**
- * Gets the lessonPlan attribute of the Lesson object
- *
- * @return The lessonPlan value
- */
- protected String getLessonName() {
- return this.getClass().getSimpleName();
- }
-
- /**
- * Gets the title attribute of the HelloScreen object
- *
- * @return The title value
- */
- public abstract String getTitle();
-
- /**
- * Gets the content of lessonPlanURL
- *
- * @param s The user's WebSession
- * @return The HTML content of the current lesson plan
- */
- public String getLessonPlan(WebSession s) {
- StringBuffer src = new StringBuffer();
- String lang = s.getCurrrentLanguage();
-
- try {
- // System.out.println("Loading lesson plan file: " +
- // getLessonPlanFileName());
- String filename = getLessonPlanFileName(lang);
- if (filename == null) {
- filename = getLessonPlanFileName(getDefaultLanguage());
-
- }
-
- src.append(readFromFile(new BufferedReader(new FileReader(filename)), false));
-
- } catch (Exception e) {
- // s.setMessage( "Could not find lesson plan for " +
- // getLessonName());
- src = new StringBuffer("Could not find lesson plan for: " + getLessonName() + " and language " + lang);
-
- }
- return src.toString();
- }
-
- /**
- * Gets the ranking attribute of the Lesson object
- *
- * @return The ranking value
- */
- public Integer getRanking() {
- if (ranking != null) {
- return ranking;
- } else {
- return getDefaultRanking();
- }
- }
-
- /**
- * Gets the hidden value of the Lesson Object
- *
- * @return The hidden value
- */
- public boolean getHidden() {
- return this.hidden;
- }
-
- /**
- * Gets the role attribute of the AbstractLesson object
- *
- * @return The role value
- */
- public String getRole() {
- // FIXME: Each lesson should have a role assigned to it. Each
- // user/student
- // should also have a role(s) assigned. The user would only be allowed
- // to see lessons that correspond to their role. Eventually these roles
- // will be stored in the internal database. The user will be able to
- // hack
- // into the database and change their role. This will allow the user to
- // see the admin screens, once they figure out how to turn the admin
- // switch on.
- return USER_ROLE;
- }
-
- /**
- * Gets the uniqueID attribute of the AbstractLesson object
- *
- * @return The uniqueID value
- */
- public int getScreenId() {
- return id.intValue();
- }
-
- public String getHtml_DELETE_ME(WebSession s) {
- String html = null;
-
- // FIXME: This doesn't work for the labs since they do not implement
- // createContent().
- String rawHtml = createContent(s).toString();
- // System.out.println("Getting raw html content: " +
- // rawHtml.substring(0, Math.min(rawHtml.length(), 100)));
- html = convertMetachars(AbstractLesson.readFromFile(new BufferedReader(new StringReader(rawHtml)), true));
- // System.out.println("Getting encoded html content: " +
- // html.substring(0, Math.min(html.length(), 100)));
-
- return html;
- }
-
- public String getSource(WebSession s) {
- String source = null;
- String src = null;
-
- try {
- // System.out.println("Loading source file: " +
- // getSourceFileName());
- src = convertMetacharsJavaCode(readFromFile(new BufferedReader(new FileReader(getSourceFileName())), true));
-
- // TODO: For styled line numbers and better memory efficiency,
- // use a custom FilterReader
- // that performs the convertMetacharsJavaCode() transform plus
- // optionally adds a styled
- // line number. Wouldn't color syntax be great too?
- } catch (Exception e) {
- s.setMessage("Could not find source file");
- src = ("Could not find the source file or source file does not exist. "
- + "Send this message to: " + s.getWebgoatContext()
- .getFeedbackAddress() + " ");
- }
-
- Html html = new Html();
-
- Head head = new Head();
- head.addElement(new Title(getSourceFileName()));
-
- Body body = new Body();
- body.addElement(new StringElement(src));
-
- html.addElement(head);
- html.addElement(body);
-
- source = html.toString();
-
- return source;
- }
-
- public String getRawSource(WebSession s) {
- String src;
-
- try {
- logger.debug("Loading source file: " + getSourceFileName());
- src = readFromFile(new BufferedReader(new FileReader(getSourceFileName())), false);
-
- } catch (FileNotFoundException e) {
- s.setMessage("Could not find source file");
- src = ("Could not find the source file or source file does not exist. "
- + "Send this message to: " + s.getWebgoatContext()
- .getFeedbackAddress() + " ");
- }
-
- return src;
- }
-
- public String getSolution(WebSession s) {
- String src = null;
-
- try {
- // System.out.println("Solution: " + getLessonSolutionFileName());
- src = readFromFile(new BufferedReader(new FileReader(getLessonSolutionFileName())), false);
- } catch (Exception e) {
- logger.error("Could not find solution for {}", getLessonSolutionFileName());
- s.setMessage("Could not find the solution file");
- src = ("Could not find the solution file or solution file does not exist. "
- + "Send this message to: " + s.getWebgoatContext()
- .getFeedbackAddress() + " ");
- }
-
- // Solutions are html files
- return src;
- }
-
- /**
- *
- * Returns the default "path" portion of a lesson's URL.
- *
- *
- * Legacy webgoat lesson links are of the form
- * "attack?Screen=Xmenu=Ystage=Z". This method returns the path portion of
- * the url, i.e., "attack" in the string above.
- *
- *
- * Newer, Spring-Controller-based classes will override this method to
- * return "*.do"-styled paths.
- */
- protected String getPath() {
- return "#attack";
- }
-
- /**
- * Get the link that can be used to request this screen.
- *
- * @return
- */
- public String getLink() {
- StringBuffer link = new StringBuffer();
-
- // mvc update:
- link.append(getPath()).append("/");
- link.append(getScreenId());
- link.append("/");
- link.append(getCategory().getRanking());
-
- return link.toString();
- }
-
- /**
- * Get the link to the jsp page used to render this screen.
- *
- * @return
- */
- public String getPage(WebSession s) {
- return null;
- }
-
- /**
- * Get the link to the jsp template page used to render this screen.
- *
- * @return
- */
- public String getTemplatePage(WebSession s) {
- return null;
- }
-
- public abstract String getCurrentAction(WebSession s);
-
- public abstract void setCurrentAction(WebSession s, String lessonScreen);
-
- /**
- * Override this method to implement accesss control in a lesson.
- *
- * @param s
- * @param functionId
- * @return
- */
- public boolean isAuthorized(WebSession s, int employeeId, String functionId) {
- return false;
- }
-
- /**
- * Override this method to implement accesss control in a lesson.
- *
- * @param s
- * @param functionId
- * @return
- */
- public boolean isAuthorized(WebSession s, String role, String functionId) {
- logger.info("Checking if " + role + " authorized for: " + functionId);
- boolean authorized = false;
- try {
- String query = "SELECT * FROM auth WHERE role = '" + role + "' and functionid = '" + functionId + "'";
- try {
- Statement answer_statement = WebSession.getConnection(s)
- .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- ResultSet answer_results = answer_statement.executeQuery(query);
- authorized = answer_results.first();
- logger.info("authorized: " + authorized);
- } catch (SQLException sqle) {
- s.setMessage("Error authorizing");
- logger.error("Error authorizing", sqle);
- }
- } catch (Exception e) {
- s.setMessage("Error authorizing");
- logger.error("Error authorizing", e);
- }
- return authorized;
- }
-
- public int getUserId(WebSession s) throws ParameterNotFoundException {
- return -1;
- }
-
- public String getUserName(WebSession s) throws ParameterNotFoundException {
- return null;
- }
-
- /**
- * Description of the Method
- *
- * @param windowName Description of the Parameter
- * @return Description of the Return Value
- */
- public static String makeWindowScript(String windowName) {
- // FIXME: make this string static
- StringBuffer script = new StringBuffer();
- script.append("\n");
-
- return script.toString();
- }
-
- /**
- * Simply reads a url into an Element for display. CAUTION: you might want
- * to tinker with any non-https links (href)
- *
- * @param url Description of the Parameter
- * @return Description of the Return Value
- */
- public static Element readFromURL(String url) {
- ElementContainer ec = new ElementContainer();
-
- try {
- URL u = new URL(url);
- HttpURLConnection huc = (HttpURLConnection) u.openConnection();
- BufferedReader reader = new BufferedReader(new InputStreamReader(huc.getInputStream()));
- String line;
-
- while ((line = reader.readLine()) != null) {
- ec.addElement(new StringElement(line));
- }
-
- reader.close();
- } catch (Exception e) {
- System.out.println(e);
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Description of the Method
- *
- * @param reader Description of the Parameter
- * @param numbers Description of the Parameter
- * @param methodName Description of the Parameter
- * @return Description of the Return Value
- */
- public static Element readMethodFromFile(BufferedReader reader, String methodName, boolean numbers) {
- PRE pre = new PRE().addElement(getFileMethod(reader, methodName, numbers));
-
- return (pre);
- }
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- */
- public void handleRequest(WebSession s) {
- // call createContent first so messages will go somewhere
- Form form = new Form(getFormAction(), Form.POST).setName("form").setEncType("");
- form.addElement(createContent(s));
- setContent(form);
- s.getRequest().getRequestURL();
- }
-
- public String getFormAction() {
- return getLink();
- }
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- * @return Description of the Return Value
- */
- public String toString() {
- return getTitle();
- }
-
- public String getDefaultLanguage() {
- return this.defaultLanguage;
- }
-
- public String getLessonPlanFileName(String lang) {
- String ret = lessonPlanFileName.get(lang);
- if (ret == null) {
- ret = lessonPlanFileName.get(getDefaultLanguage());
- }
- return ret;
- }
-
- public void setLessonPlanFileName(String lang, String lessonPlanFileName) {
- this.lessonPlanFileName.put(lang, lessonPlanFileName);
- this.availableLanguages.add(lang);
- }
-
- public List getAvailableLanguages() {
- return this.availableLanguages;
- }
-
- public String getLessonSolutionFileName() {
- return lessonSolutionFileName;
- }
-
- public void setLessonSolutionFileName(String lessonSolutionFileName) {
- this.lessonSolutionFileName = lessonSolutionFileName;
- }
-
- public String getSourceFileName() {
- return sourceFileName;
- }
-
- public void setSourceFileName(String sourceFileName) {
- logger.debug("Setting source file of lesson " + this + " to: " + sourceFileName);
- this.sourceFileName = sourceFileName;
- }
-
- public WebgoatContext getWebgoatContext() {
- return webgoatContext;
- }
-
- public void setWebgoatContext(WebgoatContext webgoatContext) {
- this.webgoatContext = webgoatContext;
- }
-
- protected LabelManager getLabelManager() {
- if (labelManager == null) {
- labelManager = BeanProvider.getBean("labelManager", LabelManager.class);
- }
- return labelManager;
- }
-
- /**
- * A reference from an image, script and link tag must include the context path.
- *
- * A reference in include directives are made from within the web application on the server.
- * However, img tags (and the like) make references from the client browser.
- * In such external references, the context path must be included.
- */
- protected final String buildImagePath(WebSession w, String imgResourceName) {
- return w.getRequest()
- .getContextPath() + "/plugin_extracted/plugin/" + getLessonName() + "/images/" + imgResourceName;
- }
-
-
- protected final String buildJspPath(WebSession w, String jspResourceName, boolean includeContextPath) {
- String path = includeContextPath ? w.getContext().getContextPath() : "";
- return path + "/plugin_extracted/plugin/" + getLessonName() + "/jsp/" + jspResourceName;
- }
-
- protected final String buildJsPath(WebSession w, String jsResourceName) {
- return w.getRequest()
- .getContextPath() + "/plugin_extracted/plugin/" + getLessonName() + "/js/" + jsResourceName;
- }
-
- protected final File getLessonDirectory(WebSession w) {
- return new File(w.getContext().getRealPath("/plugin_extracted/plugin/" + getLessonName() + "/"));
- }
-
-}
+package org.owasp.webgoat.lessons;
+
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.StringElement;
+import org.apache.ecs.html.Body;
+import org.apache.ecs.html.Form;
+import org.apache.ecs.html.Head;
+import org.apache.ecs.html.Html;
+import org.apache.ecs.html.IMG;
+import org.apache.ecs.html.PRE;
+import org.apache.ecs.html.Title;
+import org.owasp.webgoat.session.ParameterNotFoundException;
+import org.owasp.webgoat.session.Screen;
+import org.owasp.webgoat.session.WebSession;
+import org.owasp.webgoat.session.WebgoatContext;
+import org.owasp.webgoat.session.WebgoatProperties;
+import org.owasp.webgoat.util.BeanProvider;
+import org.owasp.webgoat.util.LabelManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce Mayhew WebGoat
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public abstract class AbstractLesson extends Screen implements Comparable {
+
+ private static final Logger logger = LoggerFactory.getLogger(AbstractLesson.class);
+
+ /**
+ * Description of the Field
+ */
+ public final static String ADMIN_ROLE = "admin";
+
+ /** Constant CHALLENGE_ROLE="challenge"
*/
+ public final static String CHALLENGE_ROLE = "challenge";
+
+ /**
+ * Description of the Field
+ */
+ public final static String HACKED_ADMIN_ROLE = "hacked_admin";
+
+ /**
+ * Description of the Field
+ */
+ public final static String USER_ROLE = "user";
+
+ private static int count = 1;
+
+ private Integer id = null;
+
+ final static IMG nextGrey = new IMG("images/right16.gif").setAlt("Next").setBorder(0).setHspace(0).setVspace(0);
+
+ final static IMG previousGrey = new IMG("images/left14.gif").setAlt("Previous").setBorder(0).setHspace(0)
+ .setVspace(0);
+
+ private Integer ranking;
+
+ private Category category;
+
+ private boolean hidden;
+
+ private String sourceFileName;
+
+ private Map lessonPlanFileName = new HashMap();
+
+ private String lessonSolutionFileName;
+
+ private WebgoatContext webgoatContext;
+
+ private LinkedList availableLanguages = new LinkedList();
+
+ private String defaultLanguage = "en";
+
+ private LabelManager labelManager = null;
+
+ /**
+ * Constructor for the Lesson object
+ */
+ public AbstractLesson() {
+ id = new Integer(++count);
+ }
+
+ /**
+ * getName.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getName() {
+ String className = getClass().getName();
+ return className.substring(className.lastIndexOf('.') + 1);
+ }
+
+ /**
+ * Setter for the field ranking
.
+ *
+ * @param ranking a {@link java.lang.Integer} object.
+ */
+ public void setRanking(Integer ranking) {
+ this.ranking = ranking;
+ }
+
+ /**
+ * Setter for the field hidden
.
+ *
+ * @param hidden a boolean.
+ */
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+
+ /**
+ * update.
+ *
+ * @param properties a {@link org.owasp.webgoat.session.WebgoatProperties} object.
+ */
+ public void update(WebgoatProperties properties) {
+ String className = getClass().getName();
+ className = className.substring(className.lastIndexOf(".") + 1);
+ setRanking(new Integer(properties.getIntProperty("lesson." + className + ".ranking", getDefaultRanking()
+ .intValue())));
+ String categoryRankingKey = "category." + getDefaultCategory().getName() + ".ranking";
+ // System.out.println("Category ranking key: " + categoryRankingKey);
+ Category tempCategory = Category.getCategory(getDefaultCategory().getName());
+ tempCategory.setRanking(new Integer(properties.getIntProperty(categoryRankingKey, getDefaultCategory()
+ .getRanking().intValue())));
+ category = tempCategory;
+ setHidden(properties.getBooleanProperty("lesson." + className + ".hidden", getDefaultHidden()));
+ // System.out.println(className + " in " + tempCategory.getName() + "
+ // (Category Ranking: " + tempCategory.getRanking() + " Lesson ranking:
+ // " + getRanking() + ", hidden:" + hidden +")");
+ }
+
+ /**
+ * isCompleted.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a boolean.
+ */
+ public boolean isCompleted(WebSession s) {
+ return getLessonTracker(s, this).getCompleted();
+ }
+
+ /**
+ * Gets the credits attribute of the AbstractLesson object
+ *
+ * @return The credits value
+ * @deprecated - Credits have moved to the about page
+ */
+ public abstract Element getCredits();
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ public int compareTo(Object obj) {
+ return this.getRanking().compareTo(((AbstractLesson) obj).getRanking());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ public boolean equals(Object obj) {
+ return this.getScreenId() == ((AbstractLesson) obj).getScreenId();
+ }
+
+ /**
+ * Gets the category attribute of the Lesson object
+ *
+ * @return The category value
+ */
+ public Category getCategory() {
+ return category;
+ }
+
+ /**
+ * getDefaultRanking.
+ *
+ * @return a {@link java.lang.Integer} object.
+ */
+ protected abstract Integer getDefaultRanking();
+
+ /**
+ * getDefaultCategory.
+ *
+ * @return a {@link org.owasp.webgoat.lessons.Category} object.
+ */
+ protected abstract Category getDefaultCategory();
+
+ /**
+ * getDefaultHidden.
+ *
+ * @return a boolean.
+ */
+ protected abstract boolean getDefaultHidden();
+
+ /**
+ * Gets the fileMethod attribute of the Lesson class
+ *
+ * @param reader Description of the Parameter
+ * @param methodName Description of the Parameter
+ * @param numbers Description of the Parameter
+ * @return The fileMethod value
+ */
+ public static String getFileMethod(BufferedReader reader, String methodName, boolean numbers) {
+ int count = 0;
+ StringBuffer sb = new StringBuffer();
+ boolean echo = false;
+ boolean startCount = false;
+ int parenCount = 0;
+
+ try {
+ String line;
+
+ while ((line = reader.readLine()) != null) {
+ if ((line.indexOf(methodName) != -1)
+ && ((line.indexOf("public") != -1) || (line.indexOf("protected") != -1) || (line
+ .indexOf("private") != -1))) {
+ echo = true;
+ startCount = true;
+ }
+
+ if (echo && startCount) {
+ if (numbers) {
+ sb.append(pad(++count) + " ");
+ }
+
+ sb.append(line + "\n");
+ }
+
+ if (echo && (line.indexOf("{") != -1)) {
+ parenCount++;
+ }
+
+ if (echo && (line.indexOf("}") != -1)) {
+ parenCount--;
+
+ if (parenCount == 0) {
+ startCount = false;
+ echo = false;
+ }
+ }
+ }
+
+ reader.close();
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ }
+
+ return (sb.toString());
+ }
+
+ /**
+ * Reads text from a file into an ElementContainer. Each line in the file is
+ * represented in the ElementContainer by a StringElement. Each
+ * StringElement is appended with a new-line character.
+ *
+ * @param reader Description of the Parameter
+ * @param numbers Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static String readFromFile(BufferedReader reader, boolean numbers) {
+ return (getFileText(reader, numbers));
+ }
+
+ /**
+ * Gets the fileText attribute of the Screen class
+ *
+ * @param reader Description of the Parameter
+ * @param numbers Description of the Parameter
+ * @return The fileText value
+ */
+ public static String getFileText(BufferedReader reader, boolean numbers) {
+ int count = 0;
+ StringBuffer sb = new StringBuffer();
+
+ try {
+ String line;
+
+ while ((line = reader.readLine()) != null) {
+ if (numbers) {
+ sb.append(pad(++count) + " ");
+ }
+ sb.append(line + System.getProperty("line.separator"));
+ }
+
+ reader.close();
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ }
+
+ return (sb.toString());
+ }
+
+ /**
+ * Will this screen be included in an enterprise edition.
+ *
+ * @return The ranking value
+ */
+ public boolean isEnterprise() {
+ return false;
+ }
+
+ /**
+ * Gets the hintCount attribute of the Lesson object
+ *
+ * @param s The user's WebSession
+ * @return The hintCount value
+ */
+ public int getHintCount(WebSession s) {
+ return getHints(s).size();
+ }
+
+ /**
+ * getHints.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.util.List} object.
+ */
+ protected abstract List getHints(WebSession s);
+
+ // @TODO we need to restrict access at the service layer
+ // rather than passing session object around
+ /**
+ * getHintsPublic.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.util.List} object.
+ */
+ public List getHintsPublic(WebSession s) {
+ List hints = getHints(s);
+ return hints;
+ }
+
+ /**
+ * Fill in a minor hint that will help people who basically get it, but are
+ * stuck on somthing silly.
+ *
+ * @param s The users WebSession
+ * @return The hint1 value
+ * @param hintNumber a int.
+ */
+ public String getHint(WebSession s, int hintNumber) {
+ return "Hint: " + getHints(s).get(hintNumber);
+ }
+
+ /**
+ * Gets the instructions attribute of the AbstractLesson object
+ *
+ * @return The instructions value
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ */
+ public abstract String getInstructions(WebSession s);
+
+ /**
+ * Gets the lessonPlan attribute of the Lesson object
+ *
+ * @return The lessonPlan value
+ */
+ protected String getLessonName() {
+ return this.getClass().getSimpleName();
+ }
+
+ /**
+ * Gets the title attribute of the HelloScreen object
+ *
+ * @return The title value
+ */
+ public abstract String getTitle();
+
+ /**
+ * Gets the content of lessonPlanURL
+ *
+ * @param s The user's WebSession
+ * @return The HTML content of the current lesson plan
+ */
+ public String getLessonPlan(WebSession s) {
+ StringBuffer src = new StringBuffer();
+ String lang = s.getCurrrentLanguage();
+
+ try {
+ // System.out.println("Loading lesson plan file: " +
+ // getLessonPlanFileName());
+ String filename = getLessonPlanFileName(lang);
+ if (filename == null) {
+ filename = getLessonPlanFileName(getDefaultLanguage());
+
+ }
+
+ src.append(readFromFile(new BufferedReader(new FileReader(filename)), false));
+
+ } catch (Exception e) {
+ // s.setMessage( "Could not find lesson plan for " +
+ // getLessonName());
+ src = new StringBuffer("Could not find lesson plan for: " + getLessonName() + " and language " + lang);
+
+ }
+ return src.toString();
+ }
+
+ /**
+ * Gets the ranking attribute of the Lesson object
+ *
+ * @return The ranking value
+ */
+ public Integer getRanking() {
+ if (ranking != null) {
+ return ranking;
+ } else {
+ return getDefaultRanking();
+ }
+ }
+
+ /**
+ * Gets the hidden value of the Lesson Object
+ *
+ * @return The hidden value
+ */
+ public boolean getHidden() {
+ return this.hidden;
+ }
+
+ /**
+ * Gets the role attribute of the AbstractLesson object
+ *
+ * @return The role value
+ */
+ public String getRole() {
+ // FIXME: Each lesson should have a role assigned to it. Each
+ // user/student
+ // should also have a role(s) assigned. The user would only be allowed
+ // to see lessons that correspond to their role. Eventually these roles
+ // will be stored in the internal database. The user will be able to
+ // hack
+ // into the database and change their role. This will allow the user to
+ // see the admin screens, once they figure out how to turn the admin
+ // switch on.
+ return USER_ROLE;
+ }
+
+ /**
+ * Gets the uniqueID attribute of the AbstractLesson object
+ *
+ * @return The uniqueID value
+ */
+ public int getScreenId() {
+ return id.intValue();
+ }
+
+ /**
+ * getHtml_DELETE_ME.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String getHtml_DELETE_ME(WebSession s) {
+ String html = null;
+
+ // FIXME: This doesn't work for the labs since they do not implement
+ // createContent().
+ String rawHtml = createContent(s).toString();
+ // System.out.println("Getting raw html content: " +
+ // rawHtml.substring(0, Math.min(rawHtml.length(), 100)));
+ html = convertMetachars(AbstractLesson.readFromFile(new BufferedReader(new StringReader(rawHtml)), true));
+ // System.out.println("Getting encoded html content: " +
+ // html.substring(0, Math.min(html.length(), 100)));
+
+ return html;
+ }
+
+ /**
+ * getSource.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String getSource(WebSession s) {
+ String source = null;
+ String src = null;
+
+ try {
+ // System.out.println("Loading source file: " +
+ // getSourceFileName());
+ src = convertMetacharsJavaCode(readFromFile(new BufferedReader(new FileReader(getSourceFileName())), true));
+
+ // TODO: For styled line numbers and better memory efficiency,
+ // use a custom FilterReader
+ // that performs the convertMetacharsJavaCode() transform plus
+ // optionally adds a styled
+ // line number. Wouldn't color syntax be great too?
+ } catch (Exception e) {
+ s.setMessage("Could not find source file");
+ src = ("Could not find the source file or source file does not exist. "
+ + "Send this message to: " + s.getWebgoatContext()
+ .getFeedbackAddress() + " ");
+ }
+
+ Html html = new Html();
+
+ Head head = new Head();
+ head.addElement(new Title(getSourceFileName()));
+
+ Body body = new Body();
+ body.addElement(new StringElement(src));
+
+ html.addElement(head);
+ html.addElement(body);
+
+ source = html.toString();
+
+ return source;
+ }
+
+ /**
+ * getRawSource.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String getRawSource(WebSession s) {
+ String src;
+
+ try {
+ logger.debug("Loading source file: " + getSourceFileName());
+ src = readFromFile(new BufferedReader(new FileReader(getSourceFileName())), false);
+
+ } catch (FileNotFoundException e) {
+ s.setMessage("Could not find source file");
+ src = ("Could not find the source file or source file does not exist. "
+ + "Send this message to: " + s.getWebgoatContext()
+ .getFeedbackAddress() + " ");
+ }
+
+ return src;
+ }
+
+ /**
+ * getSolution.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String getSolution(WebSession s) {
+ String src = null;
+
+ try {
+ // System.out.println("Solution: " + getLessonSolutionFileName());
+ src = readFromFile(new BufferedReader(new FileReader(getLessonSolutionFileName())), false);
+ } catch (Exception e) {
+ logger.error("Could not find solution for {}", getLessonSolutionFileName());
+ s.setMessage("Could not find the solution file");
+ src = ("Could not find the solution file or solution file does not exist. "
+ + "Send this message to: " + s.getWebgoatContext()
+ .getFeedbackAddress() + " ");
+ }
+
+ // Solutions are html files
+ return src;
+ }
+
+ /**
+ * Returns the default "path" portion of a lesson's URL.
+ *
+ *
+ * Legacy webgoat lesson links are of the form
+ * "attack?Screen=Xmenu=Ystage=Z". This method returns the path portion of
+ * the url, i.e., "attack" in the string above.
+ *
+ * Newer, Spring-Controller-based classes will override this method to
+ * return "*.do"-styled paths.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ protected String getPath() {
+ return "#attack";
+ }
+
+ /**
+ * Get the link that can be used to request this screen.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getLink() {
+ StringBuffer link = new StringBuffer();
+
+ // mvc update:
+ link.append(getPath()).append("/");
+ link.append(getScreenId());
+ link.append("/");
+ link.append(getCategory().getRanking());
+
+ return link.toString();
+ }
+
+ /**
+ * Get the link to the jsp page used to render this screen.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String getPage(WebSession s) {
+ return null;
+ }
+
+ /**
+ * Get the link to the jsp template page used to render this screen.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String getTemplatePage(WebSession s) {
+ return null;
+ }
+
+ /**
+ * getCurrentAction.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public abstract String getCurrentAction(WebSession s);
+
+ /**
+ * setCurrentAction.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param lessonScreen a {@link java.lang.String} object.
+ */
+ public abstract void setCurrentAction(WebSession s, String lessonScreen);
+
+ /**
+ * Override this method to implement accesss control in a lesson.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param functionId a {@link java.lang.String} object.
+ * @param employeeId a int.
+ * @return a boolean.
+ */
+ public boolean isAuthorized(WebSession s, int employeeId, String functionId) {
+ return false;
+ }
+
+ /**
+ * Override this method to implement accesss control in a lesson.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param functionId a {@link java.lang.String} object.
+ * @param role a {@link java.lang.String} object.
+ * @return a boolean.
+ */
+ public boolean isAuthorized(WebSession s, String role, String functionId) {
+ logger.info("Checking if " + role + " authorized for: " + functionId);
+ boolean authorized = false;
+ try {
+ String query = "SELECT * FROM auth WHERE role = '" + role + "' and functionid = '" + functionId + "'";
+ try {
+ Statement answer_statement = WebSession.getConnection(s)
+ .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ ResultSet answer_results = answer_statement.executeQuery(query);
+ authorized = answer_results.first();
+ logger.info("authorized: " + authorized);
+ } catch (SQLException sqle) {
+ s.setMessage("Error authorizing");
+ logger.error("Error authorizing", sqle);
+ }
+ } catch (Exception e) {
+ s.setMessage("Error authorizing");
+ logger.error("Error authorizing", e);
+ }
+ return authorized;
+ }
+
+ /**
+ * getUserId.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a int.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public int getUserId(WebSession s) throws ParameterNotFoundException {
+ return -1;
+ }
+
+ /**
+ * getUserName.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public String getUserName(WebSession s) throws ParameterNotFoundException {
+ return null;
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param windowName Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static String makeWindowScript(String windowName) {
+ // FIXME: make this string static
+ StringBuffer script = new StringBuffer();
+ script.append("\n");
+
+ return script.toString();
+ }
+
+ /**
+ * Simply reads a url into an Element for display. CAUTION: you might want
+ * to tinker with any non-https links (href)
+ *
+ * @param url Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element readFromURL(String url) {
+ ElementContainer ec = new ElementContainer();
+
+ try {
+ URL u = new URL(url);
+ HttpURLConnection huc = (HttpURLConnection) u.openConnection();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(huc.getInputStream()));
+ String line;
+
+ while ((line = reader.readLine()) != null) {
+ ec.addElement(new StringElement(line));
+ }
+
+ reader.close();
+ } catch (Exception e) {
+ System.out.println(e);
+ e.printStackTrace();
+ }
+
+ return (ec);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param reader Description of the Parameter
+ * @param numbers Description of the Parameter
+ * @param methodName Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element readMethodFromFile(BufferedReader reader, String methodName, boolean numbers) {
+ PRE pre = new PRE().addElement(getFileMethod(reader, methodName, numbers));
+
+ return (pre);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s Description of the Parameter
+ */
+ public void handleRequest(WebSession s) {
+ // call createContent first so messages will go somewhere
+ Form form = new Form(getFormAction(), Form.POST).setName("form").setEncType("");
+ form.addElement(createContent(s));
+ setContent(form);
+ s.getRequest().getRequestURL();
+ }
+
+ /**
+ * getFormAction.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getFormAction() {
+ return getLink();
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ public String toString() {
+ return getTitle();
+ }
+
+ /**
+ * Getter for the field defaultLanguage
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getDefaultLanguage() {
+ return this.defaultLanguage;
+ }
+
+ /**
+ * Getter for the field lessonPlanFileName
.
+ *
+ * @param lang a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String getLessonPlanFileName(String lang) {
+ String ret = lessonPlanFileName.get(lang);
+ if (ret == null) {
+ ret = lessonPlanFileName.get(getDefaultLanguage());
+ }
+ return ret;
+ }
+
+ /**
+ * Setter for the field lessonPlanFileName
.
+ *
+ * @param lang a {@link java.lang.String} object.
+ * @param lessonPlanFileName a {@link java.lang.String} object.
+ */
+ public void setLessonPlanFileName(String lang, String lessonPlanFileName) {
+ this.lessonPlanFileName.put(lang, lessonPlanFileName);
+ this.availableLanguages.add(lang);
+ }
+
+ /**
+ * Getter for the field availableLanguages
.
+ *
+ * @return a {@link java.util.List} object.
+ */
+ public List getAvailableLanguages() {
+ return this.availableLanguages;
+ }
+
+ /**
+ * Getter for the field lessonSolutionFileName
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getLessonSolutionFileName() {
+ return lessonSolutionFileName;
+ }
+
+ /**
+ * Setter for the field lessonSolutionFileName
.
+ *
+ * @param lessonSolutionFileName a {@link java.lang.String} object.
+ */
+ public void setLessonSolutionFileName(String lessonSolutionFileName) {
+ this.lessonSolutionFileName = lessonSolutionFileName;
+ }
+
+ /**
+ * Getter for the field sourceFileName
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getSourceFileName() {
+ return sourceFileName;
+ }
+
+ /**
+ * Setter for the field sourceFileName
.
+ *
+ * @param sourceFileName a {@link java.lang.String} object.
+ */
+ public void setSourceFileName(String sourceFileName) {
+ logger.debug("Setting source file of lesson " + this + " to: " + sourceFileName);
+ this.sourceFileName = sourceFileName;
+ }
+
+ /**
+ * Getter for the field webgoatContext
.
+ *
+ * @return a {@link org.owasp.webgoat.session.WebgoatContext} object.
+ */
+ public WebgoatContext getWebgoatContext() {
+ return webgoatContext;
+ }
+
+ /**
+ * Setter for the field webgoatContext
.
+ *
+ * @param webgoatContext a {@link org.owasp.webgoat.session.WebgoatContext} object.
+ */
+ public void setWebgoatContext(WebgoatContext webgoatContext) {
+ this.webgoatContext = webgoatContext;
+ }
+
+ /**
+ * Getter for the field labelManager
.
+ *
+ * @return a {@link org.owasp.webgoat.util.LabelManager} object.
+ */
+ protected LabelManager getLabelManager() {
+ if (labelManager == null) {
+ labelManager = BeanProvider.getBean("labelManager", LabelManager.class);
+ }
+ return labelManager;
+ }
+
+ /**
+ * A reference from an image, script and link tag must include the context path.
+ *
+ * A reference in include directives are made from within the web application on the server.
+ * However, img tags (and the like) make references from the client browser.
+ * In such external references, the context path must be included.
+ *
+ * @param w a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param imgResourceName a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ */
+ protected final String buildImagePath(WebSession w, String imgResourceName) {
+ return w.getRequest()
+ .getContextPath() + "/plugin_extracted/plugin/" + getLessonName() + "/images/" + imgResourceName;
+ }
+
+
+ /**
+ *
buildJspPath.
+ *
+ * @param w a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param jspResourceName a {@link java.lang.String} object.
+ * @param includeContextPath a boolean.
+ * @return a {@link java.lang.String} object.
+ */
+ protected final String buildJspPath(WebSession w, String jspResourceName, boolean includeContextPath) {
+ String path = includeContextPath ? w.getContext().getContextPath() : "";
+ return path + "/plugin_extracted/plugin/" + getLessonName() + "/jsp/" + jspResourceName;
+ }
+
+ /**
+ * buildJsPath.
+ *
+ * @param w a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param jsResourceName a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ */
+ protected final String buildJsPath(WebSession w, String jsResourceName) {
+ return w.getRequest()
+ .getContextPath() + "/plugin_extracted/plugin/" + getLessonName() + "/js/" + jsResourceName;
+ }
+
+ /**
+ * getLessonDirectory.
+ *
+ * @param w a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.io.File} object.
+ */
+ protected final File getLessonDirectory(WebSession w) {
+ return new File(w.getContext().getRealPath("/plugin_extracted/plugin/" + getLessonName() + "/"));
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Category.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Category.java
index 2da348ff1..e79cbb032 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Category.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/Category.java
@@ -35,50 +35,72 @@ import java.util.List;
* For details, please see http://webgoat.github.io
*
* @author Bruce Mayhew WebGoat
- * @created October 28, 2003
+ * @since October 28, 2003
+ * @version $Id: $Id
*/
public class Category implements Comparable {
+ /** Constant INTRODUCTION
*/
public final static Category INTRODUCTION = new Category("Introduction", new Integer(5));
+ /** Constant GENERAL
*/
public final static Category GENERAL = new Category("General", new Integer(100));
+ /** Constant ACCESS_CONTROL
*/
public final static Category ACCESS_CONTROL = new Category("Access Control Flaws", new Integer(200));
+ /** Constant AJAX_SECURITY
*/
public final static Category AJAX_SECURITY = new Category("AJAX Security", new Integer(400));
+ /** Constant AUTHENTICATION
*/
public final static Category AUTHENTICATION = new Category("Authentication Flaws", new Integer(500));
+ /** Constant BUFFER_OVERFLOW
*/
public final static Category BUFFER_OVERFLOW = new Category("Buffer Overflows", new Integer(600));
+ /** Constant CODE_QUALITY
*/
public final static Category CODE_QUALITY = new Category("Code Quality", new Integer(700));
+ /** Constant CONCURRENCY
*/
public final static Category CONCURRENCY = new Category("Concurrency", new Integer(800));
+ /** Constant XSS
*/
public final static Category XSS = new Category("Cross-Site Scripting (XSS)", new Integer(900));
+ /** Constant ERROR_HANDLING
*/
public final static Category ERROR_HANDLING = new Category("Improper Error Handling", new Integer(1000));
+ /** Constant INJECTION
*/
public final static Category INJECTION = new Category("Injection Flaws", new Integer(1100));
+ /** Constant DOS
*/
public final static Category DOS = new Category("Denial of Service", new Integer(1200));
+ /** Constant INSECURE_COMMUNICATION
*/
public final static Category INSECURE_COMMUNICATION = new Category("Insecure Communication", new Integer(1300));
+ /** Constant INSECURE_CONFIGURATION
*/
public final static Category INSECURE_CONFIGURATION = new Category("Insecure Configuration", new Integer(1400));
+ /** Constant INSECURE_STORAGE
*/
public final static Category INSECURE_STORAGE = new Category("Insecure Storage", new Integer(1500));
+ /** Constant MALICIOUS_EXECUTION
*/
public final static Category MALICIOUS_EXECUTION = new Category("Malicious Execution", new Integer(1600));
+ /** Constant PARAMETER_TAMPERING
*/
public final static Category PARAMETER_TAMPERING = new Category("Parameter Tampering", new Integer(1700));
+ /** Constant SESSION_MANAGEMENT
*/
public final static Category SESSION_MANAGEMENT = new Category("Session Management Flaws", new Integer(1800));
+ /** Constant WEB_SERVICES
*/
public final static Category WEB_SERVICES = new Category("Web Services", new Integer(1900));
+ /** Constant ADMIN_FUNCTIONS
*/
public final static Category ADMIN_FUNCTIONS = new Category("Admin Functions", new Integer(2000));
+ /** Constant CHALLENGE
*/
public final static Category CHALLENGE = new Category("Challenge", new Integer(3000));
private static final List categories = new ArrayList();
@@ -111,10 +133,21 @@ public class Category implements Comparable {
categories.add(CHALLENGE);
}
+ /**
+ * addCategory.
+ *
+ * @param c a {@link org.owasp.webgoat.lessons.Category} object.
+ */
public static synchronized void addCategory(Category c) {
categories.add(c);
}
+ /**
+ * Getter for the field category
.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @return a {@link org.owasp.webgoat.lessons.Category} object.
+ */
public static synchronized Category getCategory(String name) {
Iterator it = categories.iterator();
while (it.hasNext()) {
@@ -126,11 +159,18 @@ public class Category implements Comparable {
return null;
}
+ /**
+ * Constructor for Category.
+ *
+ * @param category a {@link java.lang.String} object.
+ * @param ranking a {@link java.lang.Integer} object.
+ */
public Category(String category, Integer ranking) {
this.category = category;
this.ranking = ranking;
}
+ /** {@inheritDoc} */
@Override
public int compareTo(Object obj) {
int value = 1;
@@ -142,23 +182,41 @@ public class Category implements Comparable {
return value;
}
+ /**
+ * Getter for the field ranking
.
+ *
+ * @return a {@link java.lang.Integer} object.
+ */
public Integer getRanking() {
return ranking;
}
+ /**
+ * Setter for the field ranking
.
+ *
+ * @param ranking a {@link java.lang.Integer} object.
+ * @return a {@link java.lang.Integer} object.
+ */
public Integer setRanking(Integer ranking) {
return this.ranking = ranking;
}
+ /**
+ * getName.
+ *
+ * @return a {@link java.lang.String} object.
+ */
public String getName() {
return category;
}
+ /** {@inheritDoc} */
@Override
public boolean equals(Object obj) {
return (obj instanceof Category) && getName().equals(((Category) obj).getName());
}
+ /** {@inheritDoc} */
@Override
public String toString() {
return getName();
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonAdapter.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonAdapter.java
index 83258c855..e5afea907 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonAdapter.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/LessonAdapter.java
@@ -1,244 +1,270 @@
-package org.owasp.webgoat.lessons;
-
-import com.google.common.base.Joiner;
-import org.apache.commons.io.IOUtils;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.H3;
-import org.apache.ecs.html.P;
-import org.apache.ecs.html.PRE;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.session.WebSession;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce Mayhew WebGoat
- * @created October 28, 2003
- */
-public abstract class LessonAdapter extends AbstractLesson {
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s) {
- // Mark this lesson as completed.
- makeSuccess(s);
-
- ElementContainer ec = new ElementContainer();
-
- ec.addElement(new Center().addElement(new H3().addElement(new StringElement(
- "Detailed Lesson Creation Instructions."))));
- ec.addElement(new P());
- ec
- .addElement(new StringElement(
- "Lesson are simple to create and very little coding is required. "
- + "In fact, most lessons can be created by following the easy to use instructions in the "
- + "WebGoat User Guide. "
- + "If you would prefer, send your lesson ideas to "
- + getWebgoatContext().getFeedbackAddressHTML()));
-
- try (InputStream is = Thread.currentThread().getContextClassLoader()
- .getResourceAsStream("New Lesson Instructions.txt")) {
- if (is != null) {
- PRE pre = new PRE();
- pre.addElement(Joiner.on("\n").join(IOUtils.readLines(is)));
- ec.addElement(pre);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return (ec);
- }
-
- /**
- * Gets the category attribute of the LessonAdapter object. The default
- * category is "General" Only override this method if you wish to create a
- * new category or if you wish this lesson to reside within a category other
- * the "General"
- *
- * @return The category value
- */
- protected Category getDefaultCategory() {
- return Category.GENERAL;
- }
-
- protected boolean getDefaultHidden() {
- return false;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- protected Integer getDefaultRanking() {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the hintCount attribute of the LessonAdapter object
- *
- * @return The hintCount value
- */
- public int getHintCount(WebSession s) {
- return getHints(s).size();
- }
-
- /**
- * Fill in a minor hint that will help people who basically get it, but are
- * stuck on somthing silly. Hints will be returned to the user in the order
- * they appear below. The user must click on the "next hint" button before
- * the hint will be displayed.
- *
- * @return The hint1 value
- */
- protected List getHints(WebSession s) {
- List hints = new ArrayList();
- hints.add("There are no hints defined.");
- return hints;
- }
-
- /**
- * Gets the credits attribute of the AbstractLesson object
- *
- * @return The credits value
- * @deprecated Credits are in the about page. This method s no
- * longer called from WebGoat
- */
- public Element getCredits() {
- return new StringElement();
- }
-
- /**
- * Gets the instructions attribute of the LessonAdapter object. Instructions
- * will rendered as html and will appear below the control area and above
- * the actual lesson area. Instructions should provide the user with the
- * general setup and goal of the lesson.
- *
- * @return The instructions value
- */
- public String getInstructions(WebSession s) {
- StringBuffer buff = new StringBuffer();
- String lang = s.getCurrrentLanguage();
- try {
- String fileName = getLessonPlanFileName(lang);
- if (fileName != null) {
- BufferedReader in = new BufferedReader(new FileReader(fileName));
- String line = null;
- boolean startAppending = false;
- while ((line = in.readLine()) != null) {
- if (line.indexOf("") != -1) {
- startAppending = true;
- continue;
- }
- if (line.indexOf("") != -1) {
- startAppending = false;
- continue;
- }
- if (startAppending) {
- buff.append(line + "\n");
- }
- }
- }
- } catch (Exception e) {
- }
-
- return buff.toString();
-
- }
-
- /**
- * Fill in a descriptive title for this lesson. The title of the lesson.
- * This will appear above the control area at the top of the page. This
- * field will be rendered as html.
- *
- * @return The title value
- */
- public String getTitle() {
- return "Untitled Lesson " + getScreenId();
- }
-
- public String getCurrentAction(WebSession s) {
- return s.getLessonSession(this).getCurrentLessonScreen();
- }
-
- public void setCurrentAction(WebSession s, String lessonScreen) {
- s.getLessonSession(this).setCurrentLessonScreen(lessonScreen);
- }
-
- public Object getSessionAttribute(WebSession s, String key) {
- return s.getRequest().getSession().getAttribute(key);
- }
-
- public void setSessionAttribute(WebSession s, String key, Object value) {
- s.getRequest().getSession().setAttribute(key, value);
- }
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element makeSuccess(WebSession s) {
- getLessonTracker(s).setCompleted(true);
-
- s.setMessage(getLabelManager().get("LessonCompleted"));
-
- return (null);
- }
-
- /**
- * Gets the credits attribute of the AbstractLesson object
- *
- * @return The credits value
- */
- protected Element getCustomCredits(String text, Element e) {
- Table t = new Table().setCellSpacing(0).setCellPadding(0).setBorder(0).setWidth("90%").setAlign("RIGHT");
- TR tr = new TR();
- tr.addElement(new TD(text).setVAlign("MIDDLE").setAlign("RIGHT").setWidth("100%"));
- tr.addElement(new TD(e).setVAlign("MIDDLE").setAlign("RIGHT"));
- t.addElement(tr);
- return t;
- }
-
-}
+package org.owasp.webgoat.lessons;
+
+import com.google.common.base.Joiner;
+import org.apache.commons.io.IOUtils;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.StringElement;
+import org.apache.ecs.html.Center;
+import org.apache.ecs.html.H3;
+import org.apache.ecs.html.P;
+import org.apache.ecs.html.PRE;
+import org.apache.ecs.html.TD;
+import org.apache.ecs.html.TR;
+import org.apache.ecs.html.Table;
+import org.owasp.webgoat.session.WebSession;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce Mayhew WebGoat
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public abstract class LessonAdapter extends AbstractLesson {
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s) {
+ // Mark this lesson as completed.
+ makeSuccess(s);
+
+ ElementContainer ec = new ElementContainer();
+
+ ec.addElement(new Center().addElement(new H3().addElement(new StringElement(
+ "Detailed Lesson Creation Instructions."))));
+ ec.addElement(new P());
+ ec
+ .addElement(new StringElement(
+ "Lesson are simple to create and very little coding is required. "
+ + "In fact, most lessons can be created by following the easy to use instructions in the "
+ + "WebGoat User Guide. "
+ + "If you would prefer, send your lesson ideas to "
+ + getWebgoatContext().getFeedbackAddressHTML()));
+
+ try (InputStream is = Thread.currentThread().getContextClassLoader()
+ .getResourceAsStream("New Lesson Instructions.txt")) {
+ if (is != null) {
+ PRE pre = new PRE();
+ pre.addElement(Joiner.on("\n").join(IOUtils.readLines(is)));
+ ec.addElement(pre);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return (ec);
+ }
+
+ /**
+ * Gets the category attribute of the LessonAdapter object. The default
+ * category is "General" Only override this method if you wish to create a
+ * new category or if you wish this lesson to reside within a category other
+ * the "General"
+ *
+ * @return The category value
+ */
+ protected Category getDefaultCategory() {
+ return Category.GENERAL;
+ }
+
+ /**
+ * getDefaultHidden.
+ *
+ * @return a boolean.
+ */
+ protected boolean getDefaultHidden() {
+ return false;
+ }
+
+ private final static Integer DEFAULT_RANKING = new Integer(1000);
+
+ /**
+ * getDefaultRanking.
+ *
+ * @return a {@link java.lang.Integer} object.
+ */
+ protected Integer getDefaultRanking() {
+ return DEFAULT_RANKING;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Gets the hintCount attribute of the LessonAdapter object
+ */
+ public int getHintCount(WebSession s) {
+ return getHints(s).size();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Fill in a minor hint that will help people who basically get it, but are
+ * stuck on somthing silly. Hints will be returned to the user in the order
+ * they appear below. The user must click on the "next hint" button before
+ * the hint will be displayed.
+ */
+ protected List getHints(WebSession s) {
+ List hints = new ArrayList();
+ hints.add("There are no hints defined.");
+ return hints;
+ }
+
+ /**
+ * Gets the credits attribute of the AbstractLesson object
+ *
+ * @return The credits value
+ * @deprecated Credits are in the about page. This method s no
+ * longer called from WebGoat
+ */
+ public Element getCredits() {
+ return new StringElement();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Gets the instructions attribute of the LessonAdapter object. Instructions
+ * will rendered as html and will appear below the control area and above
+ * the actual lesson area. Instructions should provide the user with the
+ * general setup and goal of the lesson.
+ */
+ public String getInstructions(WebSession s) {
+ StringBuffer buff = new StringBuffer();
+ String lang = s.getCurrrentLanguage();
+ try {
+ String fileName = getLessonPlanFileName(lang);
+ if (fileName != null) {
+ BufferedReader in = new BufferedReader(new FileReader(fileName));
+ String line = null;
+ boolean startAppending = false;
+ while ((line = in.readLine()) != null) {
+ if (line.indexOf("") != -1) {
+ startAppending = true;
+ continue;
+ }
+ if (line.indexOf("") != -1) {
+ startAppending = false;
+ continue;
+ }
+ if (startAppending) {
+ buff.append(line + "\n");
+ }
+ }
+ }
+ } catch (Exception e) {
+ }
+
+ return buff.toString();
+
+ }
+
+ /**
+ * Fill in a descriptive title for this lesson. The title of the lesson.
+ * This will appear above the control area at the top of the page. This
+ * field will be rendered as html.
+ *
+ * @return The title value
+ */
+ public String getTitle() {
+ return "Untitled Lesson " + getScreenId();
+ }
+
+ /** {@inheritDoc} */
+ public String getCurrentAction(WebSession s) {
+ return s.getLessonSession(this).getCurrentLessonScreen();
+ }
+
+ /** {@inheritDoc} */
+ public void setCurrentAction(WebSession s, String lessonScreen) {
+ s.getLessonSession(this).setCurrentLessonScreen(lessonScreen);
+ }
+
+ /**
+ * getSessionAttribute.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param key a {@link java.lang.String} object.
+ * @return a {@link java.lang.Object} object.
+ */
+ public Object getSessionAttribute(WebSession s, String key) {
+ return s.getRequest().getSession().getAttribute(key);
+ }
+
+ /**
+ * setSessionAttribute.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param key a {@link java.lang.String} object.
+ * @param value a {@link java.lang.Object} object.
+ */
+ public void setSessionAttribute(WebSession s, String key, Object value) {
+ s.getRequest().getSession().setAttribute(key, value);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s Description of the Parameter
+ * @return Description of the Return Value
+ */
+ protected Element makeSuccess(WebSession s) {
+ getLessonTracker(s).setCompleted(true);
+
+ s.setMessage(getLabelManager().get("LessonCompleted"));
+
+ return (null);
+ }
+
+ /**
+ * Gets the credits attribute of the AbstractLesson object
+ *
+ * @return The credits value
+ * @param text a {@link java.lang.String} object.
+ * @param e a {@link org.apache.ecs.Element} object.
+ */
+ protected Element getCustomCredits(String text, Element e) {
+ Table t = new Table().setCellSpacing(0).setCellPadding(0).setBorder(0).setWidth("90%").setAlign("RIGHT");
+ TR tr = new TR();
+ tr.addElement(new TD(text).setVAlign("MIDDLE").setAlign("RIGHT").setWidth("100%"));
+ tr.addElement(new TD(e).setVAlign("MIDDLE").setAlign("RIGHT"));
+ t.addElement(tr);
+ return t;
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RandomLessonAdapter.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RandomLessonAdapter.java
index 092cf0579..b72ee620c 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RandomLessonAdapter.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/RandomLessonAdapter.java
@@ -1,99 +1,138 @@
-
-package org.owasp.webgoat.lessons;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import org.owasp.webgoat.session.CreateDB;
-import org.owasp.webgoat.session.DatabaseUtilities;
-import org.owasp.webgoat.session.LessonTracker;
-import org.owasp.webgoat.session.RandomLessonTracker;
-import org.owasp.webgoat.session.WebSession;
-
-
-public abstract class RandomLessonAdapter extends LessonAdapter
-{
-
- public abstract String[] getStages();
-
- public void setStage(WebSession s, String stage)
- {
- getLessonTracker(s).setStage(stage);
- try
- {
- Connection connection = DatabaseUtilities.getConnection(s);
-
- CreateDB db = new CreateDB();
- db.makeDB(connection);
- System.out.println("Successfully refreshed the database.");
-
- } catch (SQLException sqle)
- {
- System.out.println("Error refreshing the database!");
- sqle.printStackTrace();
- }
- }
-
- public String getStage(WebSession s)
- {
- return getLessonTracker(s).getStage();
- }
-
- public void setStageComplete(WebSession s, String stage)
- {
- RandomLessonTracker lt = getLessonTracker(s);
- lt.setStageComplete(stage, true);
- if (lt.getCompleted())
- {
- s.setMessage("Congratulations, you have completed this lab");
- }
- else
- {
- s.setMessage("You have completed Stage " + (lt.getStageNumber(stage) + 1) + ": " + stage + ".");
- if (!stage.equals(lt.getStage()))
- s.setMessage(" Welcome to Stage " + (lt.getStageNumber(lt.getStage()) + 1) + ": " + lt.getStage());
- }
- try
- {
- Connection connection = DatabaseUtilities.getConnection(s);
-
- CreateDB db = new CreateDB();
- db.makeDB(connection);
- System.out.println("Successfully refreshed the database.");
-
- } catch (SQLException sqle)
- {
- System.out.println("Error refreshing the database!");
- sqle.printStackTrace();
- }
- }
-
- public boolean isStageComplete(WebSession s, String stage)
- {
- return getLessonTracker(s).hasCompleted(stage);
- }
-
- @Override
- public RandomLessonTracker getLessonTracker(WebSession s)
- {
- return (RandomLessonTracker) super.getLessonTracker(s);
- }
-
- @Override
- public RandomLessonTracker getLessonTracker(WebSession s, AbstractLesson lesson)
- {
- return (RandomLessonTracker) super.getLessonTracker(s, lesson);
- }
-
- @Override
- public RandomLessonTracker getLessonTracker(WebSession s, String userNameOverride)
- {
- return (RandomLessonTracker) super.getLessonTracker(s, userNameOverride);
- }
-
- @Override
- public LessonTracker createLessonTracker()
- {
- return new RandomLessonTracker(getStages());
- }
-
-}
+
+package org.owasp.webgoat.lessons;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.owasp.webgoat.session.CreateDB;
+import org.owasp.webgoat.session.DatabaseUtilities;
+import org.owasp.webgoat.session.LessonTracker;
+import org.owasp.webgoat.session.RandomLessonTracker;
+import org.owasp.webgoat.session.WebSession;
+
+
+/**
+ * Abstract RandomLessonAdapter class.
+ *
+ * @version $Id: $Id
+ */
+public abstract class RandomLessonAdapter extends LessonAdapter
+{
+
+ /**
+ * getStages.
+ *
+ * @return an array of {@link java.lang.String} objects.
+ */
+ public abstract String[] getStages();
+
+ /**
+ * setStage.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param stage a {@link java.lang.String} object.
+ */
+ public void setStage(WebSession s, String stage)
+ {
+ getLessonTracker(s).setStage(stage);
+ try
+ {
+ Connection connection = DatabaseUtilities.getConnection(s);
+
+ CreateDB db = new CreateDB();
+ db.makeDB(connection);
+ System.out.println("Successfully refreshed the database.");
+
+ } catch (SQLException sqle)
+ {
+ System.out.println("Error refreshing the database!");
+ sqle.printStackTrace();
+ }
+ }
+
+ /**
+ * getStage.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String getStage(WebSession s)
+ {
+ return getLessonTracker(s).getStage();
+ }
+
+ /**
+ * setStageComplete.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param stage a {@link java.lang.String} object.
+ */
+ public void setStageComplete(WebSession s, String stage)
+ {
+ RandomLessonTracker lt = getLessonTracker(s);
+ lt.setStageComplete(stage, true);
+ if (lt.getCompleted())
+ {
+ s.setMessage("Congratulations, you have completed this lab");
+ }
+ else
+ {
+ s.setMessage("You have completed Stage " + (lt.getStageNumber(stage) + 1) + ": " + stage + ".");
+ if (!stage.equals(lt.getStage()))
+ s.setMessage(" Welcome to Stage " + (lt.getStageNumber(lt.getStage()) + 1) + ": " + lt.getStage());
+ }
+ try
+ {
+ Connection connection = DatabaseUtilities.getConnection(s);
+
+ CreateDB db = new CreateDB();
+ db.makeDB(connection);
+ System.out.println("Successfully refreshed the database.");
+
+ } catch (SQLException sqle)
+ {
+ System.out.println("Error refreshing the database!");
+ sqle.printStackTrace();
+ }
+ }
+
+ /**
+ * isStageComplete.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param stage a {@link java.lang.String} object.
+ * @return a boolean.
+ */
+ public boolean isStageComplete(WebSession s, String stage)
+ {
+ return getLessonTracker(s).hasCompleted(stage);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public RandomLessonTracker getLessonTracker(WebSession s)
+ {
+ return (RandomLessonTracker) super.getLessonTracker(s);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public RandomLessonTracker getLessonTracker(WebSession s, AbstractLesson lesson)
+ {
+ return (RandomLessonTracker) super.getLessonTracker(s, lesson);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public RandomLessonTracker getLessonTracker(WebSession s, String userNameOverride)
+ {
+ return (RandomLessonTracker) super.getLessonTracker(s, userNameOverride);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public LessonTracker createLessonTracker()
+ {
+ return new RandomLessonTracker(getStages());
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/SequentialLessonAdapter.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/SequentialLessonAdapter.java
index abb6ddaa4..c2932a453 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/SequentialLessonAdapter.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/SequentialLessonAdapter.java
@@ -1,138 +1,212 @@
-
-package org.owasp.webgoat.lessons;
-
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.owasp.webgoat.session.LessonTracker;
-import org.owasp.webgoat.session.SequentialLessonTracker;
-import org.owasp.webgoat.session.WebSession;
-
-
-public abstract class SequentialLessonAdapter extends LessonAdapter
-{
-
- public void setStage(WebSession s, int stage)
- {
- // System.out.println("Changed to stage " + stage);
- getLessonTracker(s).setStage(stage);
- }
-
- /*
- * By default returns 1 stage. (non-Javadoc)
- */
- public int getStageCount()
- {
- return 1;
- }
-
- public int getStage(WebSession s)
- {
- int stage = getLessonTracker(s).getStage();
-
- // System.out.println("In stage " + stage);
- return stage;
- }
-
- @Override
- public SequentialLessonTracker getLessonTracker(WebSession s)
- {
- return (SequentialLessonTracker) super.getLessonTracker(s);
- }
-
- @Override
- public SequentialLessonTracker getLessonTracker(WebSession s, AbstractLesson lesson)
- {
- return (SequentialLessonTracker) super.getLessonTracker(s, lesson);
- }
-
- @Override
- public SequentialLessonTracker getLessonTracker(WebSession s, String userNameOverride)
- {
- return (SequentialLessonTracker) super.getLessonTracker(s, userNameOverride);
- }
-
- @Override
- public LessonTracker createLessonTracker()
- {
- return new SequentialLessonTracker();
- }
-
- protected Element createStagedContent(WebSession s)
- {
- try
- {
- int stage = getLessonTracker(s).getStage();
- // int stage = Integer.parseInt(
- // getLessonTracker(s).getLessonProperties().getProperty(WebSession.STAGE,"1"));
-
- switch (stage)
- {
- case 1:
- return (doStage1(s));
- case 2:
- return (doStage2(s));
- case 3:
- return (doStage3(s));
- case 4:
- return (doStage4(s));
- case 5:
- return (doStage5(s));
- case 6:
- return (doStage6(s));
- default:
- throw new Exception("Invalid stage");
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- // System.out.println(e);
- e.printStackTrace();
- }
-
- return (new StringElement(""));
- }
-
- protected Element doStage1(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 1 Stub");
- return ec;
- }
-
- protected Element doStage2(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 2 Stub");
- return ec;
- }
-
- protected Element doStage3(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 3 Stub");
- return ec;
- }
-
- protected Element doStage4(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 4 Stub");
- return ec;
- }
-
- protected Element doStage5(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 5 Stub");
- return ec;
- }
-
- protected Element doStage6(WebSession s) throws Exception
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement("Stage 6 Stub");
- return ec;
- }
-
-}
+
+package org.owasp.webgoat.lessons;
+
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.StringElement;
+import org.owasp.webgoat.session.LessonTracker;
+import org.owasp.webgoat.session.SequentialLessonTracker;
+import org.owasp.webgoat.session.WebSession;
+
+
+/**
+ * Abstract SequentialLessonAdapter class.
+ *
+ * @version $Id: $Id
+ */
+public abstract class SequentialLessonAdapter extends LessonAdapter
+{
+
+ /**
+ * setStage.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param stage a int.
+ */
+ public void setStage(WebSession s, int stage)
+ {
+ // System.out.println("Changed to stage " + stage);
+ getLessonTracker(s).setStage(stage);
+ }
+
+ /*
+ * By default returns 1 stage. (non-Javadoc)
+ */
+ /**
+ * getStageCount.
+ *
+ * @return a int.
+ */
+ public int getStageCount()
+ {
+ return 1;
+ }
+
+ /**
+ * getStage.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a int.
+ */
+ public int getStage(WebSession s)
+ {
+ int stage = getLessonTracker(s).getStage();
+
+ // System.out.println("In stage " + stage);
+ return stage;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public SequentialLessonTracker getLessonTracker(WebSession s)
+ {
+ return (SequentialLessonTracker) super.getLessonTracker(s);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public SequentialLessonTracker getLessonTracker(WebSession s, AbstractLesson lesson)
+ {
+ return (SequentialLessonTracker) super.getLessonTracker(s, lesson);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public SequentialLessonTracker getLessonTracker(WebSession s, String userNameOverride)
+ {
+ return (SequentialLessonTracker) super.getLessonTracker(s, userNameOverride);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public LessonTracker createLessonTracker()
+ {
+ return new SequentialLessonTracker();
+ }
+
+ /**
+ * createStagedContent.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ */
+ protected Element createStagedContent(WebSession s)
+ {
+ try
+ {
+ int stage = getLessonTracker(s).getStage();
+ // int stage = Integer.parseInt(
+ // getLessonTracker(s).getLessonProperties().getProperty(WebSession.STAGE,"1"));
+
+ switch (stage)
+ {
+ case 1:
+ return (doStage1(s));
+ case 2:
+ return (doStage2(s));
+ case 3:
+ return (doStage3(s));
+ case 4:
+ return (doStage4(s));
+ case 5:
+ return (doStage5(s));
+ case 6:
+ return (doStage6(s));
+ default:
+ throw new Exception("Invalid stage");
+ }
+ } catch (Exception e)
+ {
+ s.setMessage("Error generating " + this.getClass().getName());
+ // System.out.println(e);
+ e.printStackTrace();
+ }
+
+ return (new StringElement(""));
+ }
+
+ /**
+ * doStage1.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ * @throws java.lang.Exception if any.
+ */
+ protected Element doStage1(WebSession s) throws Exception
+ {
+ ElementContainer ec = new ElementContainer();
+ ec.addElement("Stage 1 Stub");
+ return ec;
+ }
+
+ /**
+ * doStage2.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ * @throws java.lang.Exception if any.
+ */
+ protected Element doStage2(WebSession s) throws Exception
+ {
+ ElementContainer ec = new ElementContainer();
+ ec.addElement("Stage 2 Stub");
+ return ec;
+ }
+
+ /**
+ * doStage3.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ * @throws java.lang.Exception if any.
+ */
+ protected Element doStage3(WebSession s) throws Exception
+ {
+ ElementContainer ec = new ElementContainer();
+ ec.addElement("Stage 3 Stub");
+ return ec;
+ }
+
+ /**
+ * doStage4.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ * @throws java.lang.Exception if any.
+ */
+ protected Element doStage4(WebSession s) throws Exception
+ {
+ ElementContainer ec = new ElementContainer();
+ ec.addElement("Stage 4 Stub");
+ return ec;
+ }
+
+ /**
+ * doStage5.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ * @throws java.lang.Exception if any.
+ */
+ protected Element doStage5(WebSession s) throws Exception
+ {
+ ElementContainer ec = new ElementContainer();
+ ec.addElement("Stage 5 Stub");
+ return ec;
+ }
+
+ /**
+ * doStage6.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ * @throws java.lang.Exception if any.
+ */
+ protected Element doStage6(WebSession s) throws Exception
+ {
+ ElementContainer ec = new ElementContainer();
+ ec.addElement("Stage 6 Stub");
+ return ec;
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/WelcomeScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/WelcomeScreen.java
index 0342dd462..61723e933 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/WelcomeScreen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/WelcomeScreen.java
@@ -1,145 +1,161 @@
-
-package org.owasp.webgoat.lessons;
-
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.HtmlColor;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.Form;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.session.*;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- * @created October 28, 2003
- */
-public class WelcomeScreen extends Screen
-{
-
- /**
- * Constructor for the WelcomeScreen object
- *
- * @param s
- * Description of the Parameter
- */
- public WelcomeScreen(WebSession s)
- {
- setup(s);
- }
-
- /**
- * Constructor for the WelcomeScreen object
- */
- public WelcomeScreen()
- {
- }
-
- public void setup(WebSession s)
- {
- // call createContent first so messages will go somewhere
-
- Form form = new Form("attack", Form.POST).setName("form").setEncType("");
-
- form.addElement(wrapForm(s));
-
- TD lowerright = new TD().setHeight("100%").setVAlign("top").setAlign("left").addElement(form);
- TR row = new TR().addElement(lowerright);
- Table layout = new Table().setBgColor(HtmlColor.WHITE).setCellSpacing(0).setCellPadding(0).setBorder(0);
-
- layout.addElement(row);
-
- setContent(layout);
- }
-
- protected Element wrapForm(WebSession s)
- {
- if (s == null) { return new StringElement("Invalid Session"); }
-
- Table container = new Table().setWidth("100%").setCellSpacing(10).setCellPadding(0).setBorder(0);
-
- // CreateContent can generate error messages so you MUST call it before makeMessages()
- Element content = createContent(s);
- container.addElement(new TR().addElement(new TD().setColSpan(2).setVAlign("TOP").addElement(makeMessages(s))));
- container.addElement(new TR().addElement(new TD().setColSpan(2).addElement(content)));
- container.addElement(new TR());
-
- return (container);
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
- Element b = ECSFactory.makeButton("Start the Course!");
- ec.addElement(new Center(b));
-
- return (ec);
- }
-
- /**
- * Gets the instructions attribute of the WelcomeScreen object
- *
- * @return The instructions value
- */
- protected String getInstructions()
- {
- String instructions = "Enter your name and learn how HTTP really works!";
-
- return (instructions);
- }
-
- /**
- * Gets the title attribute of the WelcomeScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Welcome to the Penetration Testing Course");
- }
-
- /*
- * (non-Javadoc)
- * @see session.Screen#getRole()
- */
- public String getRole()
- {
- return AbstractLesson.USER_ROLE;
- }
-}
+
+package org.owasp.webgoat.lessons;
+
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.HtmlColor;
+import org.apache.ecs.StringElement;
+import org.apache.ecs.html.Center;
+import org.apache.ecs.html.Form;
+import org.apache.ecs.html.TD;
+import org.apache.ecs.html.TR;
+import org.apache.ecs.html.Table;
+import org.owasp.webgoat.session.*;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class WelcomeScreen extends Screen
+{
+
+ /**
+ * Constructor for the WelcomeScreen object
+ *
+ * @param s
+ * Description of the Parameter
+ */
+ public WelcomeScreen(WebSession s)
+ {
+ setup(s);
+ }
+
+ /**
+ * Constructor for the WelcomeScreen object
+ */
+ public WelcomeScreen()
+ {
+ }
+
+ /**
+ * setup.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ */
+ public void setup(WebSession s)
+ {
+ // call createContent first so messages will go somewhere
+
+ Form form = new Form("attack", Form.POST).setName("form").setEncType("");
+
+ form.addElement(wrapForm(s));
+
+ TD lowerright = new TD().setHeight("100%").setVAlign("top").setAlign("left").addElement(form);
+ TR row = new TR().addElement(lowerright);
+ Table layout = new Table().setBgColor(HtmlColor.WHITE).setCellSpacing(0).setCellPadding(0).setBorder(0);
+
+ layout.addElement(row);
+
+ setContent(layout);
+ }
+
+ /**
+ * wrapForm.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ */
+ protected Element wrapForm(WebSession s)
+ {
+ if (s == null) { return new StringElement("Invalid Session"); }
+
+ Table container = new Table().setWidth("100%").setCellSpacing(10).setCellPadding(0).setBorder(0);
+
+ // CreateContent can generate error messages so you MUST call it before makeMessages()
+ Element content = createContent(s);
+ container.addElement(new TR().addElement(new TD().setColSpan(2).setVAlign("TOP").addElement(makeMessages(s))));
+ container.addElement(new TR().addElement(new TD().setColSpan(2).addElement(content)));
+ container.addElement(new TR());
+
+ return (container);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+ Element b = ECSFactory.makeButton("Start the Course!");
+ ec.addElement(new Center(b));
+
+ return (ec);
+ }
+
+ /**
+ * Gets the instructions attribute of the WelcomeScreen object
+ *
+ * @return The instructions value
+ */
+ protected String getInstructions()
+ {
+ String instructions = "Enter your name and learn how HTTP really works!";
+
+ return (instructions);
+ }
+
+ /**
+ * Gets the title attribute of the WelcomeScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("Welcome to the Penetration Testing Course");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see session.Screen#getRole()
+ */
+ /**
+ * getRole.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getRole()
+ {
+ return AbstractLesson.USER_ROLE;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/AdminScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/AdminScreen.java
index bea43efcf..8808de8d8 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/AdminScreen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/AdminScreen.java
@@ -1,104 +1,111 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.session.Screen;
-import org.owasp.webgoat.session.WebSession;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- * @created October 28, 2003
- */
-public abstract class AdminScreen extends Screen
-{
-
- /**
- * Description of the Field
- */
- protected String query = null;
-
- /**
- * Constructor for the AdminScreen object
- *
- * @param s
- * Description of the Parameter
- * @param q
- * Description of the Parameter
- */
- public AdminScreen(WebSession s, String q)
- {
- setQuery(q);
-
- // setupAdmin(s); FIXME: what was this supposed to do?
- }
-
- /**
- * Constructor for the AdminScreen object
- *
- * @param s
- * Description of the Parameter
- */
- public AdminScreen(WebSession s)
- {
- }
-
- /**
- * Constructor for the AdminScreen object
- */
- public AdminScreen()
- {
- }
-
- /**
- * Gets the title attribute of the AdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Admin Information");
- }
-
- public String getRole()
- {
- return AbstractLesson.ADMIN_ROLE;
- }
-
- /**
- * Sets the query attribute of the AdminScreen object
- *
- * @param q
- * The new query value
- */
- public void setQuery(String q)
- {
- query = q;
- }
-}
+
+package org.owasp.webgoat.lessons.admin;
+
+import org.owasp.webgoat.lessons.AbstractLesson;
+import org.owasp.webgoat.session.Screen;
+import org.owasp.webgoat.session.WebSession;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public abstract class AdminScreen extends Screen
+{
+
+ /**
+ * Description of the Field
+ */
+ protected String query = null;
+
+ /**
+ * Constructor for the AdminScreen object
+ *
+ * @param s
+ * Description of the Parameter
+ * @param q
+ * Description of the Parameter
+ */
+ public AdminScreen(WebSession s, String q)
+ {
+ setQuery(q);
+
+ // setupAdmin(s); FIXME: what was this supposed to do?
+ }
+
+ /**
+ * Constructor for the AdminScreen object
+ *
+ * @param s
+ * Description of the Parameter
+ */
+ public AdminScreen(WebSession s)
+ {
+ }
+
+ /**
+ * Constructor for the AdminScreen object
+ */
+ public AdminScreen()
+ {
+ }
+
+ /**
+ * Gets the title attribute of the AdminScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("Admin Information");
+ }
+
+ /**
+ * getRole.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getRole()
+ {
+ return AbstractLesson.ADMIN_ROLE;
+ }
+
+ /**
+ * Sets the query attribute of the AdminScreen object
+ *
+ * @param q
+ * The new query value
+ */
+ public void setQuery(String q)
+ {
+ query = q;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ProductsAdminScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ProductsAdminScreen.java
index e88a608ab..cd15836a5 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ProductsAdminScreen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ProductsAdminScreen.java
@@ -1,121 +1,126 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.owasp.webgoat.lessons.Category;
-import org.owasp.webgoat.lessons.LessonAdapter;
-import org.owasp.webgoat.session.DatabaseUtilities;
-import org.owasp.webgoat.session.WebSession;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- * @created October 28, 2003
- */
-public class ProductsAdminScreen extends LessonAdapter
-{
-
- private final static String QUERY = "SELECT * FROM product_system_data";
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- try
- {
- Connection connection = DatabaseUtilities.getConnection(s);
-
- Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- ResultSet results = statement.executeQuery(QUERY);
-
- if (results != null)
- {
- makeSuccess(s);
- ResultSetMetaData resultsMetaData = results.getMetaData();
- ec.addElement(DatabaseUtilities.writeTable(results, resultsMetaData));
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Gets the category attribute of the ProductsAdminScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- /**
- * Gets the role attribute of the ProductsAdminScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return HACKED_ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the ProductsAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Product Information");
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-}
+
+package org.owasp.webgoat.lessons.admin;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.owasp.webgoat.lessons.Category;
+import org.owasp.webgoat.lessons.LessonAdapter;
+import org.owasp.webgoat.session.DatabaseUtilities;
+import org.owasp.webgoat.session.WebSession;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class ProductsAdminScreen extends LessonAdapter
+{
+
+ private final static String QUERY = "SELECT * FROM product_system_data";
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ try
+ {
+ Connection connection = DatabaseUtilities.getConnection(s);
+
+ Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+ ResultSet.CONCUR_READ_ONLY);
+ ResultSet results = statement.executeQuery(QUERY);
+
+ if (results != null)
+ {
+ makeSuccess(s);
+ ResultSetMetaData resultsMetaData = results.getMetaData();
+ ec.addElement(DatabaseUtilities.writeTable(results, resultsMetaData));
+ }
+ } catch (Exception e)
+ {
+ s.setMessage("Error generating " + this.getClass().getName());
+ e.printStackTrace();
+ }
+
+ return (ec);
+ }
+
+ /**
+ * Gets the category attribute of the ProductsAdminScreen object
+ *
+ * @return The category value
+ */
+ protected Category getDefaultCategory()
+ {
+ return Category.ADMIN_FUNCTIONS;
+ }
+
+ /**
+ * Gets the role attribute of the ProductsAdminScreen object
+ *
+ * @return The role value
+ */
+ public String getRole()
+ {
+ return HACKED_ADMIN_ROLE;
+ }
+
+ /**
+ * Gets the title attribute of the ProductsAdminScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("Product Information");
+ }
+
+ private final static Integer DEFAULT_RANKING = new Integer(1000);
+
+ /**
+ * getDefaultRanking.
+ *
+ * @return a {@link java.lang.Integer} object.
+ */
+ protected Integer getDefaultRanking()
+ {
+ return DEFAULT_RANKING;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/RefreshDBScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/RefreshDBScreen.java
index f9ca6ea12..db3a7e3bf 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/RefreshDBScreen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/RefreshDBScreen.java
@@ -1,157 +1,162 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.sql.Connection;
-import org.owasp.webgoat.lessons.*;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.A;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.session.*;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- * @created October 28, 2003
- */
-public class RefreshDBScreen extends LessonAdapter
-{
-
- private final static String REFRESH = "Refresh";
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- try
- {
- boolean refresh = s.getParser().getBooleanParameter(REFRESH, false);
-
- if (refresh)
- {
- refreshDB(s);
- ec.addElement(new StringElement("Successfully refreshed the database."));
- }
- else
- {
- Element label = new StringElement("Refresh the database? ");
- A link1 = ECSFactory.makeLink("Yes", REFRESH, true);
- A link2 = ECSFactory.makeLink("No", REFRESH, false);
- TD td1 = new TD().addElement(label);
- TD td2 = new TD().addElement(link1);
- TD td3 = new TD().addElement(link2);
- TR row = new TR().addElement(td1).addElement(td2).addElement(td3);
- Table t = new Table().setCellSpacing(40).setWidth("50%");
-
- if (s.isColor())
- {
- t.setBorder(1);
- }
-
- t.addElement(row);
- ec.addElement(t);
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Gets the category attribute of the RefreshDBScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the role attribute of the RefreshDBScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the RefreshDBScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Refresh Database");
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- */
- public void refreshDB(WebSession s)
- {
- try
- {
- Connection connection = DatabaseUtilities.getConnection(s);
-
- CreateDB db = new CreateDB();
- db.makeDB(connection);
- System.out.println("Successfully refreshed the database.");
- } catch (Exception e)
- {
- s.setMessage("Error refreshing database " + this.getClass().getName());
- e.printStackTrace();
- }
- }
-}
+
+package org.owasp.webgoat.lessons.admin;
+
+import java.sql.Connection;
+import org.owasp.webgoat.lessons.*;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.StringElement;
+import org.apache.ecs.html.A;
+import org.apache.ecs.html.TD;
+import org.apache.ecs.html.TR;
+import org.apache.ecs.html.Table;
+import org.owasp.webgoat.session.*;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class RefreshDBScreen extends LessonAdapter
+{
+
+ private final static String REFRESH = "Refresh";
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ try
+ {
+ boolean refresh = s.getParser().getBooleanParameter(REFRESH, false);
+
+ if (refresh)
+ {
+ refreshDB(s);
+ ec.addElement(new StringElement("Successfully refreshed the database."));
+ }
+ else
+ {
+ Element label = new StringElement("Refresh the database? ");
+ A link1 = ECSFactory.makeLink("Yes", REFRESH, true);
+ A link2 = ECSFactory.makeLink("No", REFRESH, false);
+ TD td1 = new TD().addElement(label);
+ TD td2 = new TD().addElement(link1);
+ TD td3 = new TD().addElement(link2);
+ TR row = new TR().addElement(td1).addElement(td2).addElement(td3);
+ Table t = new Table().setCellSpacing(40).setWidth("50%");
+
+ if (s.isColor())
+ {
+ t.setBorder(1);
+ }
+
+ t.addElement(row);
+ ec.addElement(t);
+ }
+ } catch (Exception e)
+ {
+ s.setMessage("Error generating " + this.getClass().getName());
+ e.printStackTrace();
+ }
+
+ return (ec);
+ }
+
+ /**
+ * Gets the category attribute of the RefreshDBScreen object
+ *
+ * @return The category value
+ */
+ protected Category getDefaultCategory()
+ {
+ return Category.ADMIN_FUNCTIONS;
+ }
+
+ private final static Integer DEFAULT_RANKING = new Integer(1000);
+
+ /**
+ * getDefaultRanking.
+ *
+ * @return a {@link java.lang.Integer} object.
+ */
+ protected Integer getDefaultRanking()
+ {
+ return DEFAULT_RANKING;
+ }
+
+ /**
+ * Gets the role attribute of the RefreshDBScreen object
+ *
+ * @return The role value
+ */
+ public String getRole()
+ {
+ return ADMIN_ROLE;
+ }
+
+ /**
+ * Gets the title attribute of the RefreshDBScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("Refresh Database");
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s
+ * Description of the Parameter
+ */
+ public void refreshDB(WebSession s)
+ {
+ try
+ {
+ Connection connection = DatabaseUtilities.getConnection(s);
+
+ CreateDB db = new CreateDB();
+ db.makeDB(connection);
+ System.out.println("Successfully refreshed the database.");
+ } catch (Exception e)
+ {
+ s.setMessage("Error refreshing database " + this.getClass().getName());
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ReportCardScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ReportCardScreen.java
index 0cadf0067..4e090758b 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ReportCardScreen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ReportCardScreen.java
@@ -1,294 +1,297 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.util.Iterator;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.HtmlColor;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.H2;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TH;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.lessons.Category;
-import org.owasp.webgoat.lessons.LessonAdapter;
-import org.owasp.webgoat.session.LessonTracker;
-import org.owasp.webgoat.session.Screen;
-import org.owasp.webgoat.session.UserTracker;
-import org.owasp.webgoat.session.WebSession;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce Mayhew WebGoat
- * @created October 28, 2003
- */
-public class ReportCardScreen extends LessonAdapter
-{
-
- /**
- * Description of the Field
- */
- protected final static String USERNAME = "Username";
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- String user = null;
-
- try
- {
- if (s.getRequest().isUserInRole(WebSession.WEBGOAT_ADMIN))
- {
- user = s.getParser().getRawParameter(USERNAME);
- }
- else
- {
- user = s.getUserName();
- }
- } catch (Exception e)
- {
- }
-
- if (user == null)
- {
- user = s.getUserName();
- }
-
- ec.addElement(makeFeedback(s));
- ec.addElement(makeReportCard(s, user));
-
- return ec;
- }
-
- private Element makeFeedback(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
- ec.addElement(new StringElement("Comments and suggestions are welcome. "
- + getWebgoatContext().getFeedbackAddressHTML() + " "));
-
- return ec;
- }
-
- /**
- * Gets the category attribute of the UserAdminScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the role attribute of the UserAdminScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return USER_ROLE;
- }
-
- /**
- * Gets the title attribute of the UserAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Report Card");
- }
-
- /**
- * Description of the Method
- *
- * @param screen
- * Description of the Parameter
- * @param s
- * Description of the Parameter
- * @param user
- * Description of the Parameter
- * @return Description of the Return Value
- */
- private TR makeLessonRow(WebSession s, String user, Screen screen)
- {
- LessonTracker lessonTracker = UserTracker.instance().getLessonTracker(s, user, screen);
- TR tr = new TR();
- if (lessonTracker.getCompleted())
- {
- tr.setBgColor(HtmlColor.LIGHTGREEN);
- }
- else if (lessonTracker.getNumVisits() == 0)
- {
- tr.setBgColor(HtmlColor.LIGHTBLUE);
- }
- else if (!lessonTracker.getCompleted() && lessonTracker.getNumVisits() > 10)
- {
- tr.setBgColor(HtmlColor.RED);
- }
- else
- {
- tr.setBgColor(HtmlColor.YELLOW);
- }
- tr.addElement(new TD().addElement(screen.getTitle()));
- tr.addElement(new TD().setAlign("CENTER").addElement(lessonTracker.getCompleted() ? "Y" : "N"));
- tr.addElement(new TD().setAlign("CENTER").addElement(Integer.toString(lessonTracker.getNumVisits())));
- tr.addElement(new TD().setAlign("CENTER").addElement(Integer.toString(lessonTracker.getMaxHintLevel())));
- return tr;
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element makeMessages(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- return (ec);
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @param user
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public Element makeReportCard(WebSession s, String user)
- {
- ElementContainer ec = new ElementContainer();
-
- ec.addElement(makeUser(s, user));
- Table t = new Table().setCellSpacing(0).setCellPadding(2).setBorder(1);
-
- if (s.isColor())
- {
- t.setBorder(1);
- }
- TR tr = new TR();
- t.addElement(makeUserHeaderRow());
-
- // These are all the user lesson
- tr = new TR();
- tr.addElement(new TD().setAlign("CENTER").setColSpan(9).addElement("Normal user lessons"));
- t.addElement(tr);
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.USER_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- Screen screen = (Screen) lessonIter.next();
- t.addElement(makeLessonRow(s, user, screen));
- }
-
- // The user figured out there was a hackable admin acocunt
- tr = new TR();
- tr.addElement(new TD().setAlign("CENTER").setColSpan(9).addElement("Hackable Admin Screens"));
- t.addElement(tr);
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.HACKED_ADMIN_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- Screen screen = (Screen) lessonIter.next();
- t.addElement(makeLessonRow(s, user, screen));
- }
-
- // The user figured out how to actually hack the admin acocunt
- tr = new TR();
- tr.addElement(new TD().setAlign("CENTER").setColSpan(9).addElement("Actual Admin Screens"));
- t.addElement(tr);
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.ADMIN_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- Screen screen = (Screen) lessonIter.next();
- t.addElement(makeLessonRow(s, user, screen));
- }
-
- ec.addElement(t);
- return (ec);
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @param user
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element makeUser(WebSession s, String user)
- {
- H2 h2 = new H2();
- // FIXME: The session is the current session, not the session of the user we are reporting.
- // String type = s.isAdmin() ? " [Administrative User]" : s.isHackedAdmin() ?
- // " [Normal User - Hacked Admin Access]" : " [Normal User]";
- String type = "";
- h2.addElement(new StringElement("Results for: " + user + type));
- return h2;
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- private TR makeUserHeaderRow()
- {
- TR tr = new TR();
-
- tr.addElement(new TH("Lesson"));
- tr.addElement(new TH("Complete"));
- tr.addElement(new TH("Visits"));
- tr.addElement(new TH("Hints"));
-
- return tr;
- }
-}
+
+package org.owasp.webgoat.lessons.admin;
+
+import java.util.Iterator;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.HtmlColor;
+import org.apache.ecs.StringElement;
+import org.apache.ecs.html.Center;
+import org.apache.ecs.html.H2;
+import org.apache.ecs.html.TD;
+import org.apache.ecs.html.TH;
+import org.apache.ecs.html.TR;
+import org.apache.ecs.html.Table;
+import org.owasp.webgoat.lessons.AbstractLesson;
+import org.owasp.webgoat.lessons.Category;
+import org.owasp.webgoat.lessons.LessonAdapter;
+import org.owasp.webgoat.session.LessonTracker;
+import org.owasp.webgoat.session.Screen;
+import org.owasp.webgoat.session.UserTracker;
+import org.owasp.webgoat.session.WebSession;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce Mayhew WebGoat
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class ReportCardScreen extends LessonAdapter
+{
+
+ /**
+ * Description of the Field
+ */
+ protected final static String USERNAME = "Username";
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ String user = null;
+
+ try
+ {
+ if (s.getRequest().isUserInRole(WebSession.WEBGOAT_ADMIN))
+ {
+ user = s.getParser().getRawParameter(USERNAME);
+ }
+ else
+ {
+ user = s.getUserName();
+ }
+ } catch (Exception e)
+ {
+ }
+
+ if (user == null)
+ {
+ user = s.getUserName();
+ }
+
+ ec.addElement(makeFeedback(s));
+ ec.addElement(makeReportCard(s, user));
+
+ return ec;
+ }
+
+ private Element makeFeedback(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+ ec.addElement(new StringElement("Comments and suggestions are welcome. "
+ + getWebgoatContext().getFeedbackAddressHTML() + " "));
+
+ return ec;
+ }
+
+ /**
+ * Gets the category attribute of the UserAdminScreen object
+ *
+ * @return The category value
+ */
+ protected Category getDefaultCategory()
+ {
+ return Category.ADMIN_FUNCTIONS;
+ }
+
+ private final static Integer DEFAULT_RANKING = new Integer(1000);
+
+ /**
+ * getDefaultRanking.
+ *
+ * @return a {@link java.lang.Integer} object.
+ */
+ protected Integer getDefaultRanking()
+ {
+ return DEFAULT_RANKING;
+ }
+
+ /**
+ * Gets the role attribute of the UserAdminScreen object
+ *
+ * @return The role value
+ */
+ public String getRole()
+ {
+ return USER_ROLE;
+ }
+
+ /**
+ * Gets the title attribute of the UserAdminScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("Report Card");
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param screen
+ * Description of the Parameter
+ * @param s
+ * Description of the Parameter
+ * @param user
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ private TR makeLessonRow(WebSession s, String user, Screen screen)
+ {
+ LessonTracker lessonTracker = UserTracker.instance().getLessonTracker(s, user, screen);
+ TR tr = new TR();
+ if (lessonTracker.getCompleted())
+ {
+ tr.setBgColor(HtmlColor.LIGHTGREEN);
+ }
+ else if (lessonTracker.getNumVisits() == 0)
+ {
+ tr.setBgColor(HtmlColor.LIGHTBLUE);
+ }
+ else if (!lessonTracker.getCompleted() && lessonTracker.getNumVisits() > 10)
+ {
+ tr.setBgColor(HtmlColor.RED);
+ }
+ else
+ {
+ tr.setBgColor(HtmlColor.YELLOW);
+ }
+ tr.addElement(new TD().addElement(screen.getTitle()));
+ tr.addElement(new TD().setAlign("CENTER").addElement(lessonTracker.getCompleted() ? "Y" : "N"));
+ tr.addElement(new TD().setAlign("CENTER").addElement(Integer.toString(lessonTracker.getNumVisits())));
+ tr.addElement(new TD().setAlign("CENTER").addElement(Integer.toString(lessonTracker.getMaxHintLevel())));
+ return tr;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element makeMessages(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ return (ec);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s
+ * Description of the Parameter
+ * @param user
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public Element makeReportCard(WebSession s, String user)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ ec.addElement(makeUser(s, user));
+ Table t = new Table().setCellSpacing(0).setCellPadding(2).setBorder(1);
+
+ if (s.isColor())
+ {
+ t.setBorder(1);
+ }
+ TR tr = new TR();
+ t.addElement(makeUserHeaderRow());
+
+ // These are all the user lesson
+ tr = new TR();
+ tr.addElement(new TD().setAlign("CENTER").setColSpan(9).addElement("Normal user lessons"));
+ t.addElement(tr);
+ for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.USER_ROLE).iterator(); lessonIter
+ .hasNext();)
+ {
+ Screen screen = (Screen) lessonIter.next();
+ t.addElement(makeLessonRow(s, user, screen));
+ }
+
+ // The user figured out there was a hackable admin acocunt
+ tr = new TR();
+ tr.addElement(new TD().setAlign("CENTER").setColSpan(9).addElement("Hackable Admin Screens"));
+ t.addElement(tr);
+ for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.HACKED_ADMIN_ROLE).iterator(); lessonIter
+ .hasNext();)
+ {
+ Screen screen = (Screen) lessonIter.next();
+ t.addElement(makeLessonRow(s, user, screen));
+ }
+
+ // The user figured out how to actually hack the admin acocunt
+ tr = new TR();
+ tr.addElement(new TD().setAlign("CENTER").setColSpan(9).addElement("Actual Admin Screens"));
+ t.addElement(tr);
+ for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.ADMIN_ROLE).iterator(); lessonIter
+ .hasNext();)
+ {
+ Screen screen = (Screen) lessonIter.next();
+ t.addElement(makeLessonRow(s, user, screen));
+ }
+
+ ec.addElement(t);
+ return (ec);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s
+ * Description of the Parameter
+ * @param user
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ protected Element makeUser(WebSession s, String user)
+ {
+ H2 h2 = new H2();
+ // FIXME: The session is the current session, not the session of the user we are reporting.
+ // String type = s.isAdmin() ? " [Administrative User]" : s.isHackedAdmin() ?
+ // " [Normal User - Hacked Admin Access]" : " [Normal User]";
+ String type = "";
+ h2.addElement(new StringElement("Results for: " + user + type));
+ return h2;
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ private TR makeUserHeaderRow()
+ {
+ TR tr = new TR();
+
+ tr.addElement(new TH("Lesson"));
+ tr.addElement(new TH("Complete"));
+ tr.addElement(new TH("Visits"));
+ tr.addElement(new TH("Hints"));
+
+ return tr;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/SummaryReportCardScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/SummaryReportCardScreen.java
index b9d46e41a..cf9717ac4 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/SummaryReportCardScreen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/SummaryReportCardScreen.java
@@ -1,314 +1,328 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.util.Enumeration;
-import java.util.Iterator;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.HtmlColor;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.Input;
-import org.apache.ecs.html.P;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TH;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.lessons.Category;
-import org.owasp.webgoat.lessons.LessonAdapter;
-import org.owasp.webgoat.session.LessonTracker;
-import org.owasp.webgoat.session.Screen;
-import org.owasp.webgoat.session.UserTracker;
-import org.owasp.webgoat.session.WebSession;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce mayhew WebGoat
- * @created October 28, 2003
- */
-public class SummaryReportCardScreen extends LessonAdapter
-{
-
- private int totalUsersNormalComplete = 0;
-
- private int totalUsersAdminComplete = 0;
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- String selectedUser = null;
-
- try
- {
- if (s.getRequest().isUserInRole(WebSession.WEBGOAT_ADMIN))
- {
- Enumeration e = s.getParser().getParameterNames();
-
- while (e.hasMoreElements())
- {
- String key = (String) e.nextElement();
- if (key.startsWith("View_"))
- {
- selectedUser = key.substring("View_".length());
- ReportCardScreen reportCard = new ReportCardScreen();
- return reportCard.makeReportCard(s, selectedUser);
- }
- if (key.startsWith("Delete_"))
- {
- selectedUser = key.substring("Delete_".length());
- deleteUser(selectedUser);
- }
- }
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- }
-
- ec.addElement(new Center().addElement(makeSummary(s)));
-
- ec.addElement(new P());
-
- Table t = new Table().setCellSpacing(0).setCellPadding(4).setBorder(1).setWidth("100%");
- if (s.isColor())
- {
- t.setBorder(1);
- }
- t.addElement(makeUserSummaryHeader());
-
- for (Iterator userIter = UserTracker.instance().getAllUsers(WebSession.WEBGOAT_USER).iterator(); userIter
- .hasNext();)
- {
-
- String user = userIter.next();
- t.addElement(makeUserSummaryRow(s, user));
- }
-
- ec.addElement(new Center().addElement(t));
-
- return ec;
- }
-
- protected Element makeSummary(WebSession s)
- {
- Table t = new Table().setCellSpacing(0).setCellPadding(2).setBorder(0).setWidth("100%");
- if (s.isColor())
- {
- t.setBorder(1);
- }
- TR tr = new TR();
- // tr.addElement( new TH().addElement( "Summary").setColSpan(1));
- // t.addElement( tr );
-
- tr = new TR();
- tr.addElement(new TD().setWidth("60%").addElement("Total number of users"));
- tr.addElement(new TD().setAlign("LEFT").addElement(
- Integer.toString(UserTracker.instance()
- .getAllUsers(WebSession.WEBGOAT_USER).size())));
- t.addElement(tr);
-
- tr = new TR();
- tr.addElement(new TD().setWidth("60%").addElement("Total number of users that completed all normal lessons"));
- tr.addElement(new TD().setAlign("LEFT").addElement(Integer.toString(totalUsersNormalComplete)));
- t.addElement(tr);
-
- tr = new TR();
- tr.addElement(new TD().setWidth("60%").addElement("Total number of users that completed all admin lessons"));
- tr.addElement(new TD().setAlign("LEFT").addElement(Integer.toString(totalUsersAdminComplete)));
- t.addElement(tr);
- return t;
- }
-
- private void deleteUser(String user)
- {
- UserTracker.instance().deleteUser(user);
- }
-
- /**
- * Gets the category attribute of the UserAdminScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the role attribute of the UserAdminScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the UserAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Summary Report Card");
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element makeMessages(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- return (ec);
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- protected Element makeUserSummaryHeader()
- {
- TR tr = new TR();
-
- tr.addElement(new TH("User Name"));
- tr.addElement(new TH("Normal Complete"));
- tr.addElement(new TH("Admin Complete"));
- tr.addElement(new TH("View"));
- tr.addElement(new TH("Delete"));
-
- return tr;
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @param user
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element makeUserSummaryRow(WebSession s, String user)
- {
- TR tr = new TR();
-
- tr.addElement(new TD().setAlign("LEFT").addElement(user));
- int lessonCount = 0;
- int passedCount = 0;
- boolean normalComplete = false;
- boolean adminComplete = false;
-
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.USER_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- lessonCount++;
- Screen screen = (Screen) lessonIter.next();
-
- LessonTracker lessonTracker = UserTracker.instance().getLessonTracker(s, user, screen);
- if (lessonTracker.getCompleted())
- {
- passedCount++;
- }
- }
- if (lessonCount == passedCount)
- {
- normalComplete = true;
- totalUsersNormalComplete++;
- }
- String text = Integer.toString(passedCount) + " of " + Integer.toString(lessonCount);
- tr.addElement(new TD().setAlign("CENTER").addElement(text));
-
- lessonCount = 0;
- passedCount = 0;
- for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.HACKED_ADMIN_ROLE).iterator(); lessonIter
- .hasNext();)
- {
- lessonCount++;
- Screen screen = (Screen) lessonIter.next();
-
- LessonTracker lessonTracker = UserTracker.instance().getLessonTracker(s, user, screen);
- if (lessonTracker.getCompleted())
- {
- passedCount++;
- }
- }
- if (lessonCount == passedCount)
- {
- adminComplete = true;
- totalUsersAdminComplete++;
- }
- text = Integer.toString(passedCount) + " of " + Integer.toString(lessonCount);
- tr.addElement(new TD().setAlign("CENTER").addElement(text));
-
- tr.addElement(new TD().setAlign("CENTER").addElement(new Input(Input.SUBMIT, "View_" + user, "View")));
- tr.addElement(new TD().setAlign("CENTER").addElement(new Input(Input.SUBMIT, "Delete_" + user, "Delete")));
-
- if (normalComplete && adminComplete)
- {
- tr.setBgColor(HtmlColor.GREEN);
- }
- else if (normalComplete)
- {
- tr.setBgColor(HtmlColor.LIGHTGREEN);
- }
- else
- {
- tr.setBgColor(HtmlColor.LIGHTBLUE);
- }
-
- return (tr);
- }
-
- public boolean isEnterprise()
- {
- return true;
- }
-}
+
+package org.owasp.webgoat.lessons.admin;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.HtmlColor;
+import org.apache.ecs.html.Center;
+import org.apache.ecs.html.Input;
+import org.apache.ecs.html.P;
+import org.apache.ecs.html.TD;
+import org.apache.ecs.html.TH;
+import org.apache.ecs.html.TR;
+import org.apache.ecs.html.Table;
+import org.owasp.webgoat.lessons.AbstractLesson;
+import org.owasp.webgoat.lessons.Category;
+import org.owasp.webgoat.lessons.LessonAdapter;
+import org.owasp.webgoat.session.LessonTracker;
+import org.owasp.webgoat.session.Screen;
+import org.owasp.webgoat.session.UserTracker;
+import org.owasp.webgoat.session.WebSession;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce mayhew WebGoat
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class SummaryReportCardScreen extends LessonAdapter
+{
+
+ private int totalUsersNormalComplete = 0;
+
+ private int totalUsersAdminComplete = 0;
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ String selectedUser = null;
+
+ try
+ {
+ if (s.getRequest().isUserInRole(WebSession.WEBGOAT_ADMIN))
+ {
+ Enumeration e = s.getParser().getParameterNames();
+
+ while (e.hasMoreElements())
+ {
+ String key = (String) e.nextElement();
+ if (key.startsWith("View_"))
+ {
+ selectedUser = key.substring("View_".length());
+ ReportCardScreen reportCard = new ReportCardScreen();
+ return reportCard.makeReportCard(s, selectedUser);
+ }
+ if (key.startsWith("Delete_"))
+ {
+ selectedUser = key.substring("Delete_".length());
+ deleteUser(selectedUser);
+ }
+ }
+ }
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ ec.addElement(new Center().addElement(makeSummary(s)));
+
+ ec.addElement(new P());
+
+ Table t = new Table().setCellSpacing(0).setCellPadding(4).setBorder(1).setWidth("100%");
+ if (s.isColor())
+ {
+ t.setBorder(1);
+ }
+ t.addElement(makeUserSummaryHeader());
+
+ for (Iterator userIter = UserTracker.instance().getAllUsers(WebSession.WEBGOAT_USER).iterator(); userIter
+ .hasNext();)
+ {
+
+ String user = userIter.next();
+ t.addElement(makeUserSummaryRow(s, user));
+ }
+
+ ec.addElement(new Center().addElement(t));
+
+ return ec;
+ }
+
+ /**
+ * makeSummary.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ */
+ protected Element makeSummary(WebSession s)
+ {
+ Table t = new Table().setCellSpacing(0).setCellPadding(2).setBorder(0).setWidth("100%");
+ if (s.isColor())
+ {
+ t.setBorder(1);
+ }
+ TR tr = new TR();
+ // tr.addElement( new TH().addElement( "Summary").setColSpan(1));
+ // t.addElement( tr );
+
+ tr = new TR();
+ tr.addElement(new TD().setWidth("60%").addElement("Total number of users"));
+ tr.addElement(new TD().setAlign("LEFT").addElement(
+ Integer.toString(UserTracker.instance()
+ .getAllUsers(WebSession.WEBGOAT_USER).size())));
+ t.addElement(tr);
+
+ tr = new TR();
+ tr.addElement(new TD().setWidth("60%").addElement("Total number of users that completed all normal lessons"));
+ tr.addElement(new TD().setAlign("LEFT").addElement(Integer.toString(totalUsersNormalComplete)));
+ t.addElement(tr);
+
+ tr = new TR();
+ tr.addElement(new TD().setWidth("60%").addElement("Total number of users that completed all admin lessons"));
+ tr.addElement(new TD().setAlign("LEFT").addElement(Integer.toString(totalUsersAdminComplete)));
+ t.addElement(tr);
+ return t;
+ }
+
+ private void deleteUser(String user)
+ {
+ UserTracker.instance().deleteUser(user);
+ }
+
+ /**
+ * Gets the category attribute of the UserAdminScreen object
+ *
+ * @return The category value
+ */
+ protected Category getDefaultCategory()
+ {
+ return Category.ADMIN_FUNCTIONS;
+ }
+
+ private final static Integer DEFAULT_RANKING = new Integer(1000);
+
+ /**
+ * getDefaultRanking.
+ *
+ * @return a {@link java.lang.Integer} object.
+ */
+ protected Integer getDefaultRanking()
+ {
+ return DEFAULT_RANKING;
+ }
+
+ /**
+ * Gets the role attribute of the UserAdminScreen object
+ *
+ * @return The role value
+ */
+ public String getRole()
+ {
+ return ADMIN_ROLE;
+ }
+
+ /**
+ * Gets the title attribute of the UserAdminScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("Summary Report Card");
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element makeMessages(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ return (ec);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ protected Element makeUserSummaryHeader()
+ {
+ TR tr = new TR();
+
+ tr.addElement(new TH("User Name"));
+ tr.addElement(new TH("Normal Complete"));
+ tr.addElement(new TH("Admin Complete"));
+ tr.addElement(new TH("View"));
+ tr.addElement(new TH("Delete"));
+
+ return tr;
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s
+ * Description of the Parameter
+ * @param user
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ protected Element makeUserSummaryRow(WebSession s, String user)
+ {
+ TR tr = new TR();
+
+ tr.addElement(new TD().setAlign("LEFT").addElement(user));
+ int lessonCount = 0;
+ int passedCount = 0;
+ boolean normalComplete = false;
+ boolean adminComplete = false;
+
+ for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.USER_ROLE).iterator(); lessonIter
+ .hasNext();)
+ {
+ lessonCount++;
+ Screen screen = (Screen) lessonIter.next();
+
+ LessonTracker lessonTracker = UserTracker.instance().getLessonTracker(s, user, screen);
+ if (lessonTracker.getCompleted())
+ {
+ passedCount++;
+ }
+ }
+ if (lessonCount == passedCount)
+ {
+ normalComplete = true;
+ totalUsersNormalComplete++;
+ }
+ String text = Integer.toString(passedCount) + " of " + Integer.toString(lessonCount);
+ tr.addElement(new TD().setAlign("CENTER").addElement(text));
+
+ lessonCount = 0;
+ passedCount = 0;
+ for (Iterator lessonIter = s.getCourse().getLessons(s, AbstractLesson.HACKED_ADMIN_ROLE).iterator(); lessonIter
+ .hasNext();)
+ {
+ lessonCount++;
+ Screen screen = (Screen) lessonIter.next();
+
+ LessonTracker lessonTracker = UserTracker.instance().getLessonTracker(s, user, screen);
+ if (lessonTracker.getCompleted())
+ {
+ passedCount++;
+ }
+ }
+ if (lessonCount == passedCount)
+ {
+ adminComplete = true;
+ totalUsersAdminComplete++;
+ }
+ text = Integer.toString(passedCount) + " of " + Integer.toString(lessonCount);
+ tr.addElement(new TD().setAlign("CENTER").addElement(text));
+
+ tr.addElement(new TD().setAlign("CENTER").addElement(new Input(Input.SUBMIT, "View_" + user, "View")));
+ tr.addElement(new TD().setAlign("CENTER").addElement(new Input(Input.SUBMIT, "Delete_" + user, "Delete")));
+
+ if (normalComplete && adminComplete)
+ {
+ tr.setBgColor(HtmlColor.GREEN);
+ }
+ else if (normalComplete)
+ {
+ tr.setBgColor(HtmlColor.LIGHTGREEN);
+ }
+ else
+ {
+ tr.setBgColor(HtmlColor.LIGHTBLUE);
+ }
+
+ return (tr);
+ }
+
+ /**
+ * isEnterprise.
+ *
+ * @return a boolean.
+ */
+ public boolean isEnterprise()
+ {
+ return true;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/UserAdminScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/UserAdminScreen.java
index 25af040ea..17e4e8d09 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/UserAdminScreen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/UserAdminScreen.java
@@ -1,121 +1,126 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.owasp.webgoat.lessons.Category;
-import org.owasp.webgoat.lessons.LessonAdapter;
-import org.owasp.webgoat.session.DatabaseUtilities;
-import org.owasp.webgoat.session.WebSession;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce Mayhew WebGoat
- * @created October 28, 2003
- */
-public class UserAdminScreen extends LessonAdapter
-{
-
- private final static String QUERY = "SELECT * FROM user_system_data";
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- try
- {
- Connection connection = DatabaseUtilities.getConnection(s);
-
- Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- ResultSet results = statement.executeQuery(QUERY);
-
- if (results != null)
- {
- makeSuccess(s);
- ResultSetMetaData resultsMetaData = results.getMetaData();
- ec.addElement(DatabaseUtilities.writeTable(results, resultsMetaData));
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Gets the category attribute of the UserAdminScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the role attribute of the UserAdminScreen object
- *
- * @return The role value
- */
- public String getRole()
- {
- return HACKED_ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the UserAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("User Information");
- }
-}
+
+package org.owasp.webgoat.lessons.admin;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.owasp.webgoat.lessons.Category;
+import org.owasp.webgoat.lessons.LessonAdapter;
+import org.owasp.webgoat.session.DatabaseUtilities;
+import org.owasp.webgoat.session.WebSession;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce Mayhew WebGoat
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class UserAdminScreen extends LessonAdapter
+{
+
+ private final static String QUERY = "SELECT * FROM user_system_data";
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ try
+ {
+ Connection connection = DatabaseUtilities.getConnection(s);
+
+ Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+ ResultSet.CONCUR_READ_ONLY);
+ ResultSet results = statement.executeQuery(QUERY);
+
+ if (results != null)
+ {
+ makeSuccess(s);
+ ResultSetMetaData resultsMetaData = results.getMetaData();
+ ec.addElement(DatabaseUtilities.writeTable(results, resultsMetaData));
+ }
+ } catch (Exception e)
+ {
+ s.setMessage("Error generating " + this.getClass().getName());
+ e.printStackTrace();
+ }
+
+ return (ec);
+ }
+
+ /**
+ * Gets the category attribute of the UserAdminScreen object
+ *
+ * @return The category value
+ */
+ protected Category getDefaultCategory()
+ {
+ return Category.ADMIN_FUNCTIONS;
+ }
+
+ private final static Integer DEFAULT_RANKING = new Integer(1000);
+
+ /**
+ * getDefaultRanking.
+ *
+ * @return a {@link java.lang.Integer} object.
+ */
+ protected Integer getDefaultRanking()
+ {
+ return DEFAULT_RANKING;
+ }
+
+ /**
+ * Gets the role attribute of the UserAdminScreen object
+ *
+ * @return The role value
+ */
+ public String getRole()
+ {
+ return HACKED_ADMIN_ROLE;
+ }
+
+ /**
+ * Gets the title attribute of the UserAdminScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("User Information");
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ViewDatabase.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ViewDatabase.java
index 5d1c40703..feabca8da 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ViewDatabase.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/ViewDatabase.java
@@ -1,162 +1,167 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-import org.owasp.webgoat.lessons.*;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Input;
-import org.owasp.webgoat.session.*;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- * @created October 28, 2003
- */
-public class ViewDatabase extends LessonAdapter
-{
-
- private final static String SQL = "sql";
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- try
- {
- ec.addElement(new StringElement("Enter a SQL statement: "));
-
- StringBuffer sqlStatement = new StringBuffer(s.getParser().getRawParameter(SQL, ""));
- Input input = new Input(Input.TEXT, SQL, sqlStatement.toString());
- ec.addElement(input);
-
- Element b = ECSFactory.makeButton("Go!");
- ec.addElement(b);
-
- Connection connection = DatabaseUtilities.getConnection(s);
-
- if (sqlStatement.length() > 0)
- {
-
- Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- ResultSet results = statement.executeQuery(sqlStatement.toString());
-
- if ((results != null) && (results.first() == true))
- {
- makeSuccess(s);
- ResultSetMetaData resultsMetaData = results.getMetaData();
- ec.addElement(DatabaseUtilities.writeTable(results, resultsMetaData));
- }
-
- }
- } catch (Exception e)
- {
- s.setMessage("Error generating " + this.getClass().getName());
- e.printStackTrace();
- }
-
- return (ec);
- }
-
- /**
- * Gets the category attribute of the DatabaseScreen object
- *
- * @return The category value
- */
- protected Category getDefaultCategory()
- {
- return Category.ADMIN_FUNCTIONS;
- }
-
- private final static Integer DEFAULT_RANKING = new Integer(1000);
-
- protected Integer getDefaultRanking()
- {
- return DEFAULT_RANKING;
- }
-
- /**
- * Gets the hints attribute of the DatabaseScreen object
- *
- * @return The hints value
- */
- protected List getHints(WebSession s)
- {
- List hints = new ArrayList();
- hints.add("There are no hints defined");
-
- return hints;
- }
-
- /**
- * Gets the instructions attribute of the ViewDatabase object
- *
- * @return The instructions value
- */
- public String getInstructions(WebSession s)
- {
- String instructions = "Please post a message to to the WebGoat forum. Your messages will be available for everyone to read.";
-
- return (instructions);
- }
-
- /**
- * Gets the role attribute of the ViewDatabase object
- *
- * @return The role value
- */
- public String getRole()
- {
- return HACKED_ADMIN_ROLE;
- }
-
- /**
- * Gets the title attribute of the DatabaseScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Adhoc Query");
- }
-}
+
+package org.owasp.webgoat.lessons.admin;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import org.owasp.webgoat.lessons.*;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.StringElement;
+import org.apache.ecs.html.Input;
+import org.owasp.webgoat.session.*;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class ViewDatabase extends LessonAdapter
+{
+
+ private final static String SQL = "sql";
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ try
+ {
+ ec.addElement(new StringElement("Enter a SQL statement: "));
+
+ StringBuffer sqlStatement = new StringBuffer(s.getParser().getRawParameter(SQL, ""));
+ Input input = new Input(Input.TEXT, SQL, sqlStatement.toString());
+ ec.addElement(input);
+
+ Element b = ECSFactory.makeButton("Go!");
+ ec.addElement(b);
+
+ Connection connection = DatabaseUtilities.getConnection(s);
+
+ if (sqlStatement.length() > 0)
+ {
+
+ Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+ ResultSet.CONCUR_READ_ONLY);
+ ResultSet results = statement.executeQuery(sqlStatement.toString());
+
+ if ((results != null) && (results.first() == true))
+ {
+ makeSuccess(s);
+ ResultSetMetaData resultsMetaData = results.getMetaData();
+ ec.addElement(DatabaseUtilities.writeTable(results, resultsMetaData));
+ }
+
+ }
+ } catch (Exception e)
+ {
+ s.setMessage("Error generating " + this.getClass().getName());
+ e.printStackTrace();
+ }
+
+ return (ec);
+ }
+
+ /**
+ * Gets the category attribute of the DatabaseScreen object
+ *
+ * @return The category value
+ */
+ protected Category getDefaultCategory()
+ {
+ return Category.ADMIN_FUNCTIONS;
+ }
+
+ private final static Integer DEFAULT_RANKING = new Integer(1000);
+
+ /**
+ * getDefaultRanking.
+ *
+ * @return a {@link java.lang.Integer} object.
+ */
+ protected Integer getDefaultRanking()
+ {
+ return DEFAULT_RANKING;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Gets the hints attribute of the DatabaseScreen object
+ */
+ protected List getHints(WebSession s)
+ {
+ List hints = new ArrayList();
+ hints.add("There are no hints defined");
+
+ return hints;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Gets the instructions attribute of the ViewDatabase object
+ */
+ public String getInstructions(WebSession s)
+ {
+ String instructions = "Please post a message to to the WebGoat forum. Your messages will be available for everyone to read.";
+
+ return (instructions);
+ }
+
+ /**
+ * Gets the role attribute of the ViewDatabase object
+ *
+ * @return The role value
+ */
+ public String getRole()
+ {
+ return HACKED_ADMIN_ROLE;
+ }
+
+ /**
+ * Gets the title attribute of the DatabaseScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("Adhoc Query");
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/WelcomeAdminScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/WelcomeAdminScreen.java
index 3295c01d4..4b86cd26d 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/WelcomeAdminScreen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/admin/WelcomeAdminScreen.java
@@ -1,89 +1,89 @@
-
-package org.owasp.webgoat.lessons.admin;
-
-import org.owasp.webgoat.lessons.WelcomeScreen;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.html.Center;
-import org.apache.ecs.html.H1;
-import org.owasp.webgoat.session.WebSession;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- * @created October 28, 2003
- */
-public class WelcomeAdminScreen extends WelcomeScreen
-{
-
- /**
- * Constructor for the WelcomeAdminScreen object
- *
- * @param s
- * Description of the Parameter
- */
- public WelcomeAdminScreen(WebSession s)
- {
- super(s);
- }
-
- /**
- * Constructor for the WelcomeAdminScreen object
- */
- public WelcomeAdminScreen()
- {
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s)
- {
- ElementContainer ec = new ElementContainer();
-
- ec.addElement(new Center(new H1("You are logged on as an administrator")));
- ec.addElement(super.createContent(s));
-
- return (ec);
- }
-
- /**
- * Gets the title attribute of the WelcomeAdminScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Admin Welcome");
- }
-}
+
+package org.owasp.webgoat.lessons.admin;
+
+import org.owasp.webgoat.lessons.WelcomeScreen;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.html.Center;
+import org.apache.ecs.html.H1;
+import org.owasp.webgoat.session.WebSession;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class WelcomeAdminScreen extends WelcomeScreen
+{
+
+ /**
+ * Constructor for the WelcomeAdminScreen object
+ *
+ * @param s
+ * Description of the Parameter
+ */
+ public WelcomeAdminScreen(WebSession s)
+ {
+ super(s);
+ }
+
+ /**
+ * Constructor for the WelcomeAdminScreen object
+ */
+ public WelcomeAdminScreen()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s)
+ {
+ ElementContainer ec = new ElementContainer();
+
+ ec.addElement(new Center(new H1("You are logged on as an administrator")));
+ ec.addElement(super.createContent(s));
+
+ return (ec);
+ }
+
+ /**
+ * Gets the title attribute of the WelcomeAdminScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("Admin Welcome");
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/Hint.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/Hint.java
index 81f6ccbd2..41abb5532 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/Hint.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/Hint.java
@@ -28,8 +28,10 @@
package org.owasp.webgoat.lessons.model;
/**
+ * Hint class.
*
* @author rlawson
+ * @version $Id: $Id
*/
public class Hint {
@@ -38,6 +40,8 @@ public class Hint {
private int number;
/**
+ * Getter for the field hint
.
+ *
* @return the hint
*/
public String getHint() {
@@ -45,6 +49,8 @@ public class Hint {
}
/**
+ * Setter for the field hint
.
+ *
* @param hint the hint to set
*/
public void setHint(String hint) {
@@ -52,6 +58,8 @@ public class Hint {
}
/**
+ * Getter for the field lesson
.
+ *
* @return the lesson
*/
public String getLesson() {
@@ -59,6 +67,8 @@ public class Hint {
}
/**
+ * Setter for the field lesson
.
+ *
* @param lesson the lesson to set
*/
public void setLesson(String lesson) {
@@ -66,6 +76,8 @@ public class Hint {
}
/**
+ * Getter for the field number
.
+ *
* @return the number
*/
public int getNumber() {
@@ -73,6 +85,8 @@ public class Hint {
}
/**
+ * Setter for the field number
.
+ *
* @param number the number to set
*/
public void setNumber(int number) {
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/HttpBasicsModel.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/HttpBasicsModel.java
index 83e5d1b51..e5eec8968 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/HttpBasicsModel.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/HttpBasicsModel.java
@@ -1,48 +1,59 @@
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-package org.owasp.webgoat.lessons.model;
-
-/**
- * Model component for the Http Basics lesson. Using a model
- * for that simple lesson is architectural overkill. We do it anyway
- * for illustrative purposes - to demonstrate the pattern that we will
- * use for more complex lessons.
- *
- */
-public class HttpBasicsModel {
-
- private String personName;
-
- public String getPersonName() {
- return personName;
- }
-
- public void setPersonName(String personName) {
- this.personName = personName;
- }
-}
+/***************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ */
+package org.owasp.webgoat.lessons.model;
+
+/**
+ * Model component for the Http Basics lesson. Using a model
+ * for that simple lesson is architectural overkill. We do it anyway
+ * for illustrative purposes - to demonstrate the pattern that we will
+ * use for more complex lessons.
+ *
+ * @version $Id: $Id
+ */
+public class HttpBasicsModel {
+
+ private String personName;
+
+ /**
+ * Getter for the field personName
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getPersonName() {
+ return personName;
+ }
+
+ /**
+ * Setter for the field personName
.
+ *
+ * @param personName a {@link java.lang.String} object.
+ */
+ public void setPersonName(String personName) {
+ this.personName = personName;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonMenuItem.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonMenuItem.java
index 6fe0be737..f45df8ead 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonMenuItem.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonMenuItem.java
@@ -34,8 +34,10 @@ import java.util.ArrayList;
import java.util.List;
/**
+ * LessonMenuItem class.
*
* @author rlawson
+ * @version $Id: $Id
*/
public class LessonMenuItem {
@@ -48,6 +50,8 @@ public class LessonMenuItem {
private boolean showHints = true;
/**
+ * Getter for the field name
.
+ *
* @return the name
*/
public String getName() {
@@ -55,6 +59,8 @@ public class LessonMenuItem {
}
/**
+ * Setter for the field name
.
+ *
* @param name the name to set
*/
public void setName(String name) {
@@ -62,6 +68,8 @@ public class LessonMenuItem {
}
/**
+ * Getter for the field children
.
+ *
* @return the children
*/
public List getChildren() {
@@ -69,6 +77,8 @@ public class LessonMenuItem {
}
/**
+ * Setter for the field children
.
+ *
* @param children the children to set
*/
public void setChildren(List children) {
@@ -76,6 +86,8 @@ public class LessonMenuItem {
}
/**
+ * Getter for the field type
.
+ *
* @return the type
*/
public LessonMenuItemType getType() {
@@ -83,16 +95,24 @@ public class LessonMenuItem {
}
/**
+ * Setter for the field type
.
+ *
* @param type the type to set
*/
public void setType(LessonMenuItemType type) {
this.type = type;
}
+ /**
+ * addChild.
+ *
+ * @param child a {@link org.owasp.webgoat.lessons.model.LessonMenuItem} object.
+ */
public void addChild(LessonMenuItem child) {
children.add(child);
}
+ /** {@inheritDoc} */
@Override
public String toString() {
StringBuilder bldr = new StringBuilder();
@@ -102,6 +122,8 @@ public class LessonMenuItem {
}
/**
+ * isComplete.
+ *
* @return the complete
*/
public boolean isComplete() {
@@ -109,6 +131,8 @@ public class LessonMenuItem {
}
/**
+ * Setter for the field complete
.
+ *
* @param complete the complete to set
*/
public void setComplete(boolean complete) {
@@ -116,6 +140,8 @@ public class LessonMenuItem {
}
/**
+ * Getter for the field link
.
+ *
* @return the link
*/
public String getLink() {
@@ -123,6 +149,8 @@ public class LessonMenuItem {
}
/**
+ * Setter for the field link
.
+ *
* @param link the link to set
*/
public void setLink(String link) {
@@ -130,6 +158,8 @@ public class LessonMenuItem {
}
/**
+ * isShowSource.
+ *
* @return the showSource
*/
public boolean isShowSource() {
@@ -137,6 +167,8 @@ public class LessonMenuItem {
}
/**
+ * Setter for the field showSource
.
+ *
* @param showSource the showSource to set
*/
public void setShowSource(boolean showSource) {
@@ -144,6 +176,8 @@ public class LessonMenuItem {
}
/**
+ * isShowHints.
+ *
* @return the showHints
*/
public boolean isShowHints() {
@@ -151,6 +185,8 @@ public class LessonMenuItem {
}
/**
+ * Setter for the field showHints
.
+ *
* @param showHints the showHints to set
*/
public void setShowHints(boolean showHints) {
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonMenuItemType.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonMenuItemType.java
index c639c659f..e73368cec 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonMenuItemType.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/LessonMenuItemType.java
@@ -29,8 +29,10 @@
package org.owasp.webgoat.lessons.model;
/**
+ * LessonMenuItemType class.
*
* @author rlawson
+ * @version $Id: $Id
*/
public enum LessonMenuItemType {
CATEGORY,
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/RequestParameter.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/RequestParameter.java
index 3b7b4775a..0d720285a 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/RequestParameter.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/RequestParameter.java
@@ -1,66 +1,79 @@
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
- * For details, please see http://webgoat.github.io
- */
-package org.owasp.webgoat.lessons.model;
-
-/**
- *
- * @author rlawson
- */
-public class RequestParameter implements Comparable {
-
- private final String name;
- private final String value;
-
- public RequestParameter(String name, String value) {
- this.name = name;
- this.value = value;
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @return the values
- */
- public String getValue() {
- return value;
- }
-
- @Override
- public int compareTo(RequestParameter o) {
- return this.name.compareTo(o.getName());
- }
-
-}
+/**
+ * *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project
+ * utility. For details, please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
+ * for free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ */
+package org.owasp.webgoat.lessons.model;
+
+/**
+ * RequestParameter class.
+ *
+ * @author rlawson
+ * @version $Id: $Id
+ */
+public class RequestParameter implements Comparable {
+
+ private final String name;
+ private final String value;
+
+ /**
+ * Constructor for RequestParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @param value a {@link java.lang.String} object.
+ */
+ public RequestParameter(String name, String value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ /**
+ * Getter for the field name
.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Getter for the field value
.
+ *
+ * @return the values
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int compareTo(RequestParameter o) {
+ return this.name.compareTo(o.getName());
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/SourceListing.java b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/SourceListing.java
index 7833d2776..0e7e3272c 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/SourceListing.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/lessons/model/SourceListing.java
@@ -1,31 +1,37 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.owasp.webgoat.lessons.model;
-
-/**
- *
- * @author rlawson
- */
-public class SourceListing {
-
- private String source;
-
- /**
- * @return the source
- */
- public String getSource() {
- return source;
- }
-
- /**
- * @param source the source to set
- */
- public void setSource(String source) {
- this.source = source;
- }
-
-}
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.owasp.webgoat.lessons.model;
+
+/**
+ * SourceListing class.
+ *
+ * @author rlawson
+ * @version $Id: $Id
+ */
+public class SourceListing {
+
+ private String source;
+
+ /**
+ * Getter for the field source
.
+ *
+ * @return the source
+ */
+ public String getSource() {
+ return source;
+ }
+
+ /**
+ * Setter for the field source
.
+ *
+ * @param source the source to set
+ */
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/LegacyLoader.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/LegacyLoader.java
index d946eacb4..bdd3dd273 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/LegacyLoader.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/LegacyLoader.java
@@ -1,256 +1,262 @@
-package org.owasp.webgoat.plugins;
-
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.owasp.webgoat.session.WebgoatContext;
-import org.owasp.webgoat.session.WebgoatProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.ServletContext;
-import java.io.File;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce Mayhew WebGoat
- * @created October 28, 2003
- */
-public class LegacyLoader {
-
- final Logger logger = LoggerFactory.getLogger(LegacyLoader.class);
-
- private final List files = new LinkedList();
-
- public LegacyLoader() {
- }
-
- /**
- * Take an absolute file and return the filename.
- *
- * Ex. /etc/password becomes password
- *
- * @param s
- * @return the file name
- */
- private static String getFileName(String s) {
- String fileName = new File(s).getName();
-
- if (fileName.contains("/")) {
- fileName = fileName.substring(fileName.lastIndexOf("/"), fileName.length());
- }
-
- if (fileName.contains(".")) {
- fileName = fileName.substring(0, fileName.indexOf("."));
- }
-
- return fileName;
- }
-
- /**
- * Take a class name and return the equivalent file name
- *
- * Ex. org.owasp.webgoat becomes org/owasp/webgoat.java
- *
- * @param className
- * @return
- */
- private static String getSourceFile(String className) {
- StringBuilder sb = new StringBuilder();
-
- sb.append(className.replace(".", "/"));
- sb.append(".java");
-
- return sb.toString();
- }
-
- /**
- * Takes a file name and builds the class file name
- *
- * @param fileName Description of the Parameter
- * @param path Description of the Parameter
- * @return Description of the Return Value
- */
- private static String getClassFile(String fileName, String path) {
- String ext = ".class";
- fileName = fileName.trim();
-
- /**
- * We do not handle directories. We do not handle files with different
- * extensions
- */
- if (fileName.endsWith("/") || !fileName.endsWith(ext)) {
- return null;
- }
-
- // skip over plugins and/or extracted plugins
- if ( fileName.indexOf("lessons/plugin") >= 0 || fileName.indexOf("plugin_extracted") >= 0) {
- return null;
- }
-
- // if the file is in /WEB-INF/classes strip the dir info off
- int index = fileName.indexOf("/WEB-INF/classes/");
- if (index != -1) {
- fileName = fileName.substring(index + "/WEB-INF/classes/".length(), fileName.length() - ext.length());
- fileName = fileName.replace('/', '.');
- fileName = fileName.replace('\\', '.');
- } else {
- // Strip off the leading path info
- fileName = fileName.substring(path.length(), fileName.length() - ext.length());
- }
-
- return fileName;
- }
-
-
-
- /**
- * Load all of the filenames into a temporary cache
- *
- * @param context
- * @param path
- */
- public void loadFiles(ServletContext context, String path) {
- logger.debug("Loading files into cache, path: " + path);
- Set resourcePaths = context.getResourcePaths(path);
- if (resourcePaths == null) {
- logger.error("Unable to load file cache for courses, this is probably a bug or configuration issue");
- return;
- }
- Iterator itr = resourcePaths.iterator();
-
- while (itr.hasNext()) {
- String file = (String) itr.next();
-
- if (file.length() != 1 && file.endsWith("/")) {
- loadFiles(context, file);
- } else {
- files.add(file);
- }
- }
- }
-
- /**
- * Instantiate all the lesson objects into a cache
- *
- * @param path
- * @param context
- */
- public List loadLessons(WebgoatContext webgoatContext, ServletContext context, String path, WebgoatProperties properties ) {
-
- loadFiles(context, path);
-
- List lessons = new LinkedList();
-
- for (String file : files) {
- String className = getClassFile(file, path);
-
- if (className != null && !className.endsWith("_i") && className.startsWith("org.owasp.webgoat.lessons.admin")) {
- try {
- Class c = Class.forName(className);
- Object o = c.newInstance();
-
- if (o instanceof AbstractLesson) {
- AbstractLesson lesson = (AbstractLesson) o;
- lesson.setWebgoatContext(webgoatContext);
-
- lesson.update(properties);
-
- if (lesson.getHidden() == false) {
- lessons.add(lesson);
- }
- }
- } catch (Exception e) {
- // Bruce says:
- // I don't think we want to log the exception here. We could
- // be potentially showing a lot of exceptions that don't matter.
- // We would only care if the lesson extended AbstractLesson and we
- // can't tell that because it threw the exception. Catch 22
- // logger.error("Error in loadLessons: ", e);
- }
- }
- }
- loadResources(lessons);
- return lessons;
- }
-
- 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 langStr;
- }
-
- /**
- * For each lesson, set the source file and lesson file
- * @param lessons
- */
- public void loadResources(List lessons ) {
- for (AbstractLesson lesson : lessons) {
- logger.info("Loading resources for lesson -> " + lesson.getName());
- String className = lesson.getClass().getName();
- String classFile = getSourceFile(className);
- logger.info("Lesson classname: " + className);
- logger.info("Lesson java file: " + classFile);
-
- for (String absoluteFile : files) {
- String fileName = getFileName(absoluteFile);
- //logger.debug("Course: looking at file: " + absoluteFile);
-
- if (absoluteFile.endsWith(classFile)) {
- logger.info("Set source file for " + classFile);
- lesson.setSourceFileName(absoluteFile);
- }
-
- if (absoluteFile.startsWith("/lesson_plans") && absoluteFile.endsWith(".html")
- && className.endsWith(fileName)) {
- logger.info("setting lesson plan file " + absoluteFile + " for lesson "
- + lesson.getClass().getName());
- logger.info("fileName: " + fileName + " == className: " + className);
- String language = getLanguageFromFileName("/lesson_plans", absoluteFile);
- lesson.setLessonPlanFileName(language, absoluteFile);
- }
- if (absoluteFile.startsWith("/lesson_solutions") && absoluteFile.endsWith(".html")
- && className.endsWith(fileName)) {
- logger.info("setting lesson solution file " + absoluteFile + " for lesson "
- + lesson.getClass().getName());
- logger.info("fileName: " + fileName + " == className: " + className);
- lesson.setLessonSolutionFileName(absoluteFile);
- }
- }
- }
- }
-
-
-}
+package org.owasp.webgoat.plugins;
+
+import org.owasp.webgoat.lessons.AbstractLesson;
+import org.owasp.webgoat.session.WebgoatContext;
+import org.owasp.webgoat.session.WebgoatProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce Mayhew WebGoat
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class LegacyLoader {
+
+ final Logger logger = LoggerFactory.getLogger(LegacyLoader.class);
+
+ private final List files = new LinkedList();
+
+ /**
+ * Constructor for LegacyLoader.
+ */
+ public LegacyLoader() {
+ }
+
+ /**
+ * Take an absolute file and return the filename.
+ *
+ * Ex. /etc/password becomes password
+ *
+ * @param s
+ * @return the file name
+ */
+ private static String getFileName(String s) {
+ String fileName = new File(s).getName();
+
+ if (fileName.contains("/")) {
+ fileName = fileName.substring(fileName.lastIndexOf("/"), fileName.length());
+ }
+
+ if (fileName.contains(".")) {
+ fileName = fileName.substring(0, fileName.indexOf("."));
+ }
+
+ return fileName;
+ }
+
+ /**
+ * Take a class name and return the equivalent file name
+ *
+ * Ex. org.owasp.webgoat becomes org/owasp/webgoat.java
+ *
+ * @param className
+ * @return
+ */
+ private static String getSourceFile(String className) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(className.replace(".", "/"));
+ sb.append(".java");
+
+ return sb.toString();
+ }
+
+ /**
+ * Takes a file name and builds the class file name
+ *
+ * @param fileName Description of the Parameter
+ * @param path Description of the Parameter
+ * @return Description of the Return Value
+ */
+ private static String getClassFile(String fileName, String path) {
+ String ext = ".class";
+ fileName = fileName.trim();
+
+ /**
+ * We do not handle directories. We do not handle files with different
+ * extensions
+ */
+ if (fileName.endsWith("/") || !fileName.endsWith(ext)) {
+ return null;
+ }
+
+ // skip over plugins and/or extracted plugins
+ if ( fileName.indexOf("lessons/plugin") >= 0 || fileName.indexOf("plugin_extracted") >= 0) {
+ return null;
+ }
+
+ // if the file is in /WEB-INF/classes strip the dir info off
+ int index = fileName.indexOf("/WEB-INF/classes/");
+ if (index != -1) {
+ fileName = fileName.substring(index + "/WEB-INF/classes/".length(), fileName.length() - ext.length());
+ fileName = fileName.replace('/', '.');
+ fileName = fileName.replace('\\', '.');
+ } else {
+ // Strip off the leading path info
+ fileName = fileName.substring(path.length(), fileName.length() - ext.length());
+ }
+
+ return fileName;
+ }
+
+
+
+ /**
+ * Load all of the filenames into a temporary cache
+ *
+ * @param context a {@link javax.servlet.ServletContext} object.
+ * @param path a {@link java.lang.String} object.
+ */
+ public void loadFiles(ServletContext context, String path) {
+ logger.debug("Loading files into cache, path: " + path);
+ Set resourcePaths = context.getResourcePaths(path);
+ if (resourcePaths == null) {
+ logger.error("Unable to load file cache for courses, this is probably a bug or configuration issue");
+ return;
+ }
+ Iterator itr = resourcePaths.iterator();
+
+ while (itr.hasNext()) {
+ String file = (String) itr.next();
+
+ if (file.length() != 1 && file.endsWith("/")) {
+ loadFiles(context, file);
+ } else {
+ files.add(file);
+ }
+ }
+ }
+
+ /**
+ * Instantiate all the lesson objects into a cache
+ *
+ * @param path a {@link java.lang.String} object.
+ * @param context a {@link javax.servlet.ServletContext} object.
+ * @param webgoatContext a {@link org.owasp.webgoat.session.WebgoatContext} object.
+ * @param properties a {@link org.owasp.webgoat.session.WebgoatProperties} object.
+ * @return a {@link java.util.List} object.
+ */
+ public List loadLessons(WebgoatContext webgoatContext, ServletContext context, String path, WebgoatProperties properties ) {
+
+ loadFiles(context, path);
+
+ List lessons = new LinkedList();
+
+ for (String file : files) {
+ String className = getClassFile(file, path);
+
+ if (className != null && !className.endsWith("_i") && className.startsWith("org.owasp.webgoat.lessons.admin")) {
+ try {
+ Class c = Class.forName(className);
+ Object o = c.newInstance();
+
+ if (o instanceof AbstractLesson) {
+ AbstractLesson lesson = (AbstractLesson) o;
+ lesson.setWebgoatContext(webgoatContext);
+
+ lesson.update(properties);
+
+ if (lesson.getHidden() == false) {
+ lessons.add(lesson);
+ }
+ }
+ } catch (Exception e) {
+ // Bruce says:
+ // I don't think we want to log the exception here. We could
+ // be potentially showing a lot of exceptions that don't matter.
+ // We would only care if the lesson extended AbstractLesson and we
+ // can't tell that because it threw the exception. Catch 22
+ // logger.error("Error in loadLessons: ", e);
+ }
+ }
+ }
+ loadResources(lessons);
+ return lessons;
+ }
+
+ 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 langStr;
+ }
+
+ /**
+ * For each lesson, set the source file and lesson file
+ *
+ * @param lessons a {@link java.util.List} object.
+ */
+ public void loadResources(List lessons ) {
+ for (AbstractLesson lesson : lessons) {
+ logger.info("Loading resources for lesson -> " + lesson.getName());
+ String className = lesson.getClass().getName();
+ String classFile = getSourceFile(className);
+ logger.info("Lesson classname: " + className);
+ logger.info("Lesson java file: " + classFile);
+
+ for (String absoluteFile : files) {
+ String fileName = getFileName(absoluteFile);
+ //logger.debug("Course: looking at file: " + absoluteFile);
+
+ if (absoluteFile.endsWith(classFile)) {
+ logger.info("Set source file for " + classFile);
+ lesson.setSourceFileName(absoluteFile);
+ }
+
+ if (absoluteFile.startsWith("/lesson_plans") && absoluteFile.endsWith(".html")
+ && className.endsWith(fileName)) {
+ logger.info("setting lesson plan file " + absoluteFile + " for lesson "
+ + lesson.getClass().getName());
+ logger.info("fileName: " + fileName + " == className: " + className);
+ String language = getLanguageFromFileName("/lesson_plans", absoluteFile);
+ lesson.setLessonPlanFileName(language, absoluteFile);
+ }
+ if (absoluteFile.startsWith("/lesson_solutions") && absoluteFile.endsWith(".html")
+ && className.endsWith(fileName)) {
+ logger.info("setting lesson solution file " + absoluteFile + " for lesson "
+ + lesson.getClass().getName());
+ logger.info("fileName: " + fileName + " == className: " + className);
+ lesson.setLessonSolutionFileName(absoluteFile);
+ }
+ }
+ }
+ }
+
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java
index 39cf58235..5d501541e 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/Plugin.java
@@ -20,6 +20,11 @@ import static org.owasp.webgoat.plugins.PluginFileUtils.fileEndsWith;
import static org.owasp.webgoat.plugins.PluginFileUtils.hasParentDirectoryWithName;
import static org.owasp.webgoat.plugins.PluginFileUtils.replaceInFiles;
+/**
+ * Plugin class.
+ *
+ * @version $Id: $Id
+ */
public class Plugin {
private static final String NAME_LESSON_SOLUTION_DIRECTORY = "lessonSolutions";
@@ -32,12 +37,23 @@ public class Plugin {
private List pluginFiles = Lists.newArrayList();
private File lessonSourceFile;
+ /**
+ * Constructor for Plugin.
+ *
+ * @param pluginDirectory a {@link java.nio.file.Path} object.
+ */
public Plugin(Path pluginDirectory) {
Preconditions.checkNotNull(pluginDirectory, "plugin directory cannot be null");
Preconditions.checkArgument(Files.exists(pluginDirectory), "directory %s does not exists", pluginDirectory);
this.pluginDirectory = pluginDirectory;
}
+ /**
+ * Constructor for Plugin.
+ *
+ * @param pluginDirectory a {@link java.nio.file.Path} object.
+ * @param classes a {@link java.util.List} object.
+ */
public Plugin(Path pluginDirectory, List classes) {
this(pluginDirectory);
findLesson(classes);
@@ -65,6 +81,11 @@ public class Plugin {
}
}
+ /**
+ * loadProperties.
+ *
+ * @param properties a {@link java.util.List} object.
+ */
public void loadProperties(List properties) {
for (Path propertyFile : properties) {
LabelProvider.updatePluginResources(propertyFile);
@@ -72,6 +93,12 @@ public class Plugin {
}
}
+ /**
+ * loadFiles.
+ *
+ * @param files a {@link java.util.List} object.
+ * @param reload a boolean.
+ */
public void loadFiles(List files, boolean reload) {
for (Path file : files) {
if (fileEndsWith(file, ".html") && hasParentDirectoryWithName(file, NAME_LESSON_SOLUTION_DIRECTORY)) {
@@ -90,6 +117,11 @@ public class Plugin {
}
}
+ /**
+ * rewritePaths.
+ *
+ * @param pluginTarget a {@link java.nio.file.Path} object.
+ */
public void rewritePaths(Path pluginTarget) {
try {
replaceInFiles(this.lesson.getSimpleName() + "_files",
@@ -125,6 +157,8 @@ public class Plugin {
/**
* Lesson is optional, it is also possible that the supplied jar contains only helper classes.
+ *
+ * @return a {@link com.google.common.base.Optional} object.
*/
public Optional getLesson() {
try {
@@ -137,18 +171,39 @@ public class Plugin {
return Optional.absent();
}
+ /**
+ * getLessonSolution.
+ *
+ * @param language a {@link java.lang.String} object.
+ * @return a {@link com.google.common.base.Optional} object.
+ */
public Optional getLessonSolution(String language) {
return Optional.fromNullable(this.solutionLanguageFiles.get(language));
}
+ /**
+ * getLessonSolutions.
+ *
+ * @return a {@link java.util.Map} object.
+ */
public Map getLessonSolutions() {
return this.solutionLanguageFiles;
}
+ /**
+ * getLessonSource.
+ *
+ * @return a {@link com.google.common.base.Optional} object.
+ */
public Optional getLessonSource() {
return Optional.fromNullable(lessonSourceFile);
}
+ /**
+ * getLessonPlans.
+ *
+ * @return a {@link java.util.Map} object.
+ */
public Map getLessonPlans() {
return this.lessonPlansLanguageFiles;
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginBackgroundLoader.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginBackgroundLoader.java
index 675370605..5b9c03c14 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginBackgroundLoader.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginBackgroundLoader.java
@@ -9,10 +9,16 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@WebListener
+/**
+ * PluginBackgroundLoader class.
+ *
+ * @version $Id: $Id
+ */
public class PluginBackgroundLoader implements ServletContextListener {
private ScheduledExecutorService scheduler;
+ /** {@inheritDoc} */
@Override
public void contextInitialized(ServletContextEvent event) {
String pluginPath = event.getServletContext().getRealPath("plugin_lessons");
@@ -22,6 +28,7 @@ public class PluginBackgroundLoader implements ServletContextListener {
scheduler.scheduleAtFixedRate(new PluginsLoader(Paths.get(pluginPath), Paths.get(targetPath)), 0, 5, TimeUnit.MINUTES);
}
+ /** {@inheritDoc} */
@Override
public void contextDestroyed(ServletContextEvent event) {
scheduler.shutdownNow();
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginExtractor.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginExtractor.java
index e955610e2..0cd62840d 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginExtractor.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginExtractor.java
@@ -25,6 +25,8 @@ import static org.owasp.webgoat.plugins.PluginFileUtils.hasParentDirectoryWithNa
/**
* Extract the jar file and place them in the system temp directory in the folder webgoat and collect the files
* and classes.
+ *
+ * @version $Id: $Id
*/
public class PluginExtractor {
@@ -34,10 +36,20 @@ public class PluginExtractor {
private final List files = new ArrayList<>();
private final List properties = new ArrayList<>();
+ /**
+ * Constructor for PluginExtractor.
+ *
+ * @param pluginArchive a {@link java.nio.file.Path} object.
+ */
public PluginExtractor(Path pluginArchive) {
this.pluginArchive = pluginArchive;
}
+ /**
+ * extract.
+ *
+ * @param target a {@link java.nio.file.Path} object.
+ */
public void extract(final Path target) {
try (FileSystem zip = createZipFileSystem()) {
final Path root = zip.getPath("/");
@@ -63,14 +75,29 @@ public class PluginExtractor {
}
}
+ /**
+ * Getter for the field classes
.
+ *
+ * @return a {@link java.util.List} object.
+ */
public List getClasses() {
return this.classes;
}
+ /**
+ * Getter for the field files
.
+ *
+ * @return a {@link java.util.List} object.
+ */
public List getFiles() {
return this.files;
}
+ /**
+ * Getter for the field properties
.
+ *
+ * @return a {@link java.util.List} object.
+ */
public List getProperties() {
return this.properties;
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginFileUtils.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginFileUtils.java
index e4ae25c35..798fd7af0 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginFileUtils.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginFileUtils.java
@@ -14,12 +14,31 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+/**
+ * PluginFileUtils class.
+ *
+ * @version $Id: $Id
+ */
public class PluginFileUtils {
+ /**
+ * fileEndsWith.
+ *
+ * @param p a {@link java.nio.file.Path} object.
+ * @param s a {@link java.lang.String} object.
+ * @return a boolean.
+ */
public static boolean fileEndsWith(Path p, String s) {
return p.getFileName().toString().endsWith(s);
}
+ /**
+ * fileEndsWith.
+ *
+ * @param p a {@link java.nio.file.Path} object.
+ * @param suffixes a {@link java.lang.String} object.
+ * @return a boolean.
+ */
public static boolean fileEndsWith(Path p, String... suffixes) {
for (String suffix : suffixes) {
if (fileEndsWith(p, suffix)) {
@@ -29,6 +48,13 @@ public class PluginFileUtils {
return false;
}
+ /**
+ * hasParentDirectoryWithName.
+ *
+ * @param p a {@link java.nio.file.Path} object.
+ * @param s a {@link java.lang.String} object.
+ * @return a boolean.
+ */
public static boolean hasParentDirectoryWithName(Path p, String s) {
if (p == null || p.getParent() == null || p.getParent().equals(p.getRoot())) {
return false;
@@ -39,6 +65,13 @@ public class PluginFileUtils {
return hasParentDirectoryWithName(p.getParent(), s);
}
+ /**
+ * createDirsIfNotExists.
+ *
+ * @param p a {@link java.nio.file.Path} object.
+ * @return a {@link java.nio.file.Path} object.
+ * @throws java.io.IOException if any.
+ */
public static Path createDirsIfNotExists(Path p) throws IOException {
if (Files.notExists(p)) {
Files.createDirectories(p);
@@ -46,6 +79,13 @@ public class PluginFileUtils {
return p;
}
+ /**
+ * getFilesInDirectory.
+ *
+ * @param directory a {@link java.nio.file.Path} object.
+ * @return a {@link java.util.List} object.
+ * @throws java.io.IOException if any.
+ */
public static List getFilesInDirectory(Path directory) throws IOException {
List files = new ArrayList<>();
DirectoryStream dirStream;
@@ -57,6 +97,14 @@ public class PluginFileUtils {
return files;
}
+ /**
+ * replaceInFiles.
+ *
+ * @param replace a {@link java.lang.String} object.
+ * @param with a {@link java.lang.String} object.
+ * @param files a {@link java.util.Collection} object.
+ * @throws java.io.IOException if any.
+ */
public static void replaceInFiles(String replace, String with, Collection files) throws IOException {
Preconditions.checkNotNull(replace);
Preconditions.checkNotNull(with);
@@ -67,6 +115,14 @@ public class PluginFileUtils {
}
}
+ /**
+ * replaceInFile.
+ *
+ * @param replace a {@link java.lang.String} object.
+ * @param with a {@link java.lang.String} object.
+ * @param file a {@link java.nio.file.Path} object.
+ * @throws java.io.IOException if any.
+ */
public static void replaceInFile(String replace, String with, Path file) throws IOException {
Preconditions.checkNotNull(replace);
Preconditions.checkNotNull(with);
@@ -78,6 +134,14 @@ public class PluginFileUtils {
Files.write(file, fileAsString.getBytes());
}
+ /**
+ * writeFile.
+ *
+ * @param targetFile a {@link java.nio.file.Path} object.
+ * @param bytes an array of byte.
+ * @param options a {@link java.nio.file.OpenOption} object.
+ * @throws java.io.IOException if any.
+ */
public static void writeFile(Path targetFile, byte[] bytes, OpenOption... options) throws IOException {
createDirsIfNotExists(targetFile.getParent());
if (!Files.exists(targetFile)) {
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginLoadingFailure.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginLoadingFailure.java
index b3099e8a4..c47edf4dd 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginLoadingFailure.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginLoadingFailure.java
@@ -1,7 +1,18 @@
package org.owasp.webgoat.plugins;
+/**
+ * PluginLoadingFailure class.
+ *
+ * @version $Id: $Id
+ */
public class PluginLoadingFailure extends RuntimeException {
+ /**
+ * Constructor for PluginLoadingFailure.
+ *
+ * @param message a {@link java.lang.String} object.
+ * @param e a {@link java.lang.Exception} object.
+ */
public PluginLoadingFailure(String message, Exception e) {
super(message, e);
}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java
index 5093b291d..9f6519f58 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java
@@ -22,14 +22,26 @@ import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+/**
+ * PluginsLoader class.
+ *
+ * @version $Id: $Id
+ */
public class PluginsLoader implements Runnable {
+ /** Constant WEBGOAT_PLUGIN_EXTENSION="jar"
*/
protected static final String WEBGOAT_PLUGIN_EXTENSION = "jar";
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Path pluginSource;
private Path pluginTarget;
+ /**
+ * Constructor for PluginsLoader.
+ *
+ * @param pluginSource a {@link java.nio.file.Path} object.
+ * @param pluginTarget a {@link java.nio.file.Path} object.
+ */
public PluginsLoader(Path pluginSource, Path pluginTarget) {
Preconditions.checkNotNull(pluginSource, "plugin source cannot be null");
Preconditions.checkNotNull(pluginTarget, "plugin target cannot be null");
@@ -38,6 +50,12 @@ public class PluginsLoader implements Runnable {
this.pluginTarget = pluginTarget;
}
+ /**
+ * loadPlugins.
+ *
+ * @param reload a boolean.
+ * @return a {@link java.util.List} object.
+ */
public List loadPlugins(final boolean reload) {
final PluginClassLoader cl = (PluginClassLoader) Thread.currentThread().getContextClassLoader();
List plugins = Lists.newArrayList();
@@ -109,6 +127,7 @@ public class PluginsLoader implements Runnable {
return extractorCallables;
}
+ /** {@inheritDoc} */
@Override
public void run() {
loadPlugins(true);
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/ApplicationService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/ApplicationService.java
index 188620c24..90094f45f 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/ApplicationService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/ApplicationService.java
@@ -37,8 +37,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
+ * ApplicationService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class ApplicationService extends BaseService {
@@ -46,8 +48,8 @@ public class ApplicationService extends BaseService {
/**
* Returns global application info
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link org.owasp.webgoat.application.Application} object.
*/
@RequestMapping(value = "/application.mvc", produces = "application/json")
public @ResponseBody
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/BaseService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/BaseService.java
index 1232e57b8..e85fadebc 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/BaseService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/BaseService.java
@@ -44,14 +44,23 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
+ * Abstract BaseService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@RequestMapping("/service")
public abstract class BaseService {
private static final Logger logger = LoggerFactory.getLogger(BaseService.class);
+ /**
+ * handleException.
+ *
+ * @param request a {@link javax.servlet.http.HttpServletRequest} object.
+ * @param ex a {@link java.lang.Exception} object.
+ * @return a {@link org.owasp.webgoat.service.ExceptionInfo} object.
+ */
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.I_AM_A_TEAPOT)
public @ResponseBody
@@ -66,6 +75,12 @@ public abstract class BaseService {
return response;
}
+ /**
+ * getWebSession.
+ *
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link org.owasp.webgoat.session.WebSession} object.
+ */
public WebSession getWebSession(HttpSession session) {
WebSession ws;
Object o = session.getAttribute(WebSession.SESSION);
@@ -79,6 +94,12 @@ public abstract class BaseService {
return ws;
}
+ /**
+ * getStringStackTrace.
+ *
+ * @param t a {@link java.lang.Throwable} object.
+ * @return a {@link java.lang.String} object.
+ */
public String getStringStackTrace(Throwable t){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java
index f780e6bca..402fde5d6 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/CookieService.java
@@ -42,8 +42,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
/**
+ * CookieService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class CookieService extends BaseService {
@@ -51,8 +53,8 @@ public class CookieService extends BaseService {
/**
* Returns cookies for last attack
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link java.util.List} object.
*/
@RequestMapping(value = "/cookie.mvc", produces = "application/json")
public @ResponseBody
@@ -65,8 +67,8 @@ public class CookieService extends BaseService {
/**
* Returns cookies and params for current lesson
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link org.springframework.web.servlet.ModelAndView} object.
*/
@RequestMapping(value = "/cookies_widget.mvc", produces = "text/html")
public ModelAndView showCookiesAndParamsAsHtml(HttpSession session) {
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/DummyService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/DummyService.java
index b57e8c1ae..5291d5848 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/DummyService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/DummyService.java
@@ -34,12 +34,19 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
+ * DummyService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class DummyService extends BaseService{
+ /**
+ * firstNames.
+ *
+ * @return a {@link java.util.List} object.
+ */
@RequestMapping(value = "/first.mvc", produces = "application/json")
public @ResponseBody
List firstNames() {
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/ExceptionInfo.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/ExceptionInfo.java
index 04479ccd3..ac661fd1b 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/ExceptionInfo.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/ExceptionInfo.java
@@ -1,54 +1,76 @@
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-package org.owasp.webgoat.service;
-
-/**
- *
- * @author rlawson
- */
-public class ExceptionInfo {
-
- private String url;
- private String message;
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-}
+/***************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ */
+package org.owasp.webgoat.service;
+
+/**
+ * ExceptionInfo class.
+ *
+ * @author rlawson
+ * @version $Id: $Id
+ */
+public class ExceptionInfo {
+
+ private String url;
+ private String message;
+
+ /**
+ * Getter for the field url
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * Setter for the field url
.
+ *
+ * @param url a {@link java.lang.String} object.
+ */
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ /**
+ * Getter for the field message
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * Setter for the field message
.
+ *
+ * @param message a {@link java.lang.String} object.
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/HintService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/HintService.java
index 84869fca8..76793ad65 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/HintService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/HintService.java
@@ -17,8 +17,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
/**
+ * HintService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class HintService extends BaseService {
@@ -26,8 +28,8 @@ public class HintService extends BaseService {
/**
* Returns hints for current lesson
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link java.util.List} object.
*/
@RequestMapping(value = "/hint.mvc", produces = "application/json")
public @ResponseBody
@@ -55,6 +57,12 @@ public class HintService extends BaseService {
return listHints;
}
+ /**
+ * showHintsAsHtml.
+ *
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link org.springframework.web.servlet.ModelAndView} object.
+ */
@RequestMapping(value = "/hint_widget.mvc", produces = "text/html")
public
ModelAndView showHintsAsHtml(HttpSession session) {
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonMenuService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonMenuService.java
index 562feb20e..d981716ad 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonMenuService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonMenuService.java
@@ -47,8 +47,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
+ * LessonMenuService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class LessonMenuService extends BaseService {
@@ -58,8 +60,8 @@ public class LessonMenuService extends BaseService {
/**
* Returns the lesson menu which is used to build the left nav
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link java.util.List} object.
*/
@RequestMapping(value = "/lessonmenu.mvc", produces = "application/json")
public @ResponseBody
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonPlanService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonPlanService.java
index 7f48f3b4b..bf4d85eb6 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonPlanService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonPlanService.java
@@ -42,8 +42,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
+ * LessonPlanService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class LessonPlanService extends BaseService {
@@ -51,8 +53,8 @@ public class LessonPlanService extends BaseService {
/**
* Returns source for current attack
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link java.lang.String} object.
*/
@RequestMapping(value = "/lessonplan.mvc", produces = "application/html")
public @ResponseBody
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonTitleService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonTitleService.java
index 938a06850..67508fed5 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonTitleService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/LessonTitleService.java
@@ -10,13 +10,18 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
+/**
+ * LessonTitleService class.
+ *
+ * @version $Id: $Id
+ */
public class LessonTitleService extends BaseService {
- /**
+ /**
* Returns the title for the current attack
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link java.lang.String} object.
*/
@RequestMapping(value = "/lessontitle.mvc", produces = "application/html")
public @ResponseBody
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/ParameterService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/ParameterService.java
index 506b89c36..84c1229b3 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/ParameterService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/ParameterService.java
@@ -43,8 +43,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
+ * ParameterService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class ParameterService extends BaseService {
@@ -54,8 +56,8 @@ public class ParameterService extends BaseService {
/**
* Returns request parameters for last attack
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link java.util.List} object.
*/
@RequestMapping(value = "/parameter.mvc", produces = "application/json")
public @ResponseBody
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/RestartLessonService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/RestartLessonService.java
index 1f0c994ed..ba5ab3099 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/RestartLessonService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/RestartLessonService.java
@@ -34,8 +34,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
+ * RestartLessonService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class RestartLessonService extends BaseService {
@@ -43,8 +45,8 @@ public class RestartLessonService extends BaseService {
/**
* Returns current lesson
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link java.lang.String} object.
*/
@RequestMapping(value = "/restartlesson.mvc", produces = "text/text")
public @ResponseBody
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/SessionService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/SessionService.java
index 6d5810e5b..caec4f34d 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/SessionService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/SessionService.java
@@ -17,8 +17,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
+ * SessionService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class SessionService extends BaseService {
@@ -26,8 +28,9 @@ public class SessionService extends BaseService {
/**
* Returns hints for current lesson
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @param request a {@link javax.servlet.http.HttpServletRequest} object.
+ * @return a {@link java.lang.String} object.
*/
@RequestMapping(value = "/session.mvc", produces = "application/json")
public @ResponseBody
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/SolutionService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/SolutionService.java
index d9db4c626..04a3bf3f7 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/SolutionService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/SolutionService.java
@@ -39,8 +39,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
+ * SolutionService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class SolutionService extends BaseService {
@@ -48,8 +50,8 @@ public class SolutionService extends BaseService {
/**
* Returns solution for current attack
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link java.lang.String} object.
*/
@RequestMapping(value = "/solution.mvc", produces = "text/html")
public @ResponseBody
@@ -59,6 +61,12 @@ public class SolutionService extends BaseService {
return source;
}
+ /**
+ * getSolution.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
protected String getSolution(WebSession s) {
String source = null;
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/service/SourceService.java b/webgoat-container/src/main/java/org/owasp/webgoat/service/SourceService.java
index daf2e922d..5f010423f 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/service/SourceService.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/service/SourceService.java
@@ -44,8 +44,10 @@ import static org.owasp.webgoat.LessonSource.END_SOURCE_SKIP;
import static org.owasp.webgoat.LessonSource.START_SOURCE_SKIP;
/**
+ * SourceService class.
*
* @author rlawson
+ * @version $Id: $Id
*/
@Controller
public class SourceService extends BaseService {
@@ -53,8 +55,8 @@ public class SourceService extends BaseService {
/**
* Returns source for current attack
*
- * @param session
- * @return
+ * @param session a {@link javax.servlet.http.HttpSession} object.
+ * @return a {@link java.lang.String} object.
*/
@RequestMapping(value = "/source.mvc", produces = "application/text")
public @ResponseBody
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/servlets/Controller.java b/webgoat-container/src/main/java/org/owasp/webgoat/servlets/Controller.java
index 002140196..9c694b4cf 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/servlets/Controller.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/servlets/Controller.java
@@ -1 +1,72 @@
-package org.owasp.webgoat.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* *************************************************************************************************
*
*
* This file is part of WebGoat, an Open Web Application Security Project
* utility. For details, please see http://www.owasp.org/
*
* Copyright (c) 2002 - 20014 Bruce Mayhew
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Getting Source ==============
*
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
* for free software projects.
*
* For details, please see http://webgoat.github.io
*/
public class Controller extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
String userAgent = request.getHeader("user-agent");
String clientBrowser = "Not known!";
if (userAgent != null) {
clientBrowser = userAgent;
}
request.setAttribute("client.browser", clientBrowser);
request.getRequestDispatcher("/view.jsp").forward(request, response);
}
}
\ No newline at end of file
+package org.owasp.webgoat.servlets;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project
+ * utility. For details, please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
+ * for free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public class Controller extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ /** {@inheritDoc} */
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+ doPost(request, response);
+
+ }
+
+ /** {@inheritDoc} */
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+ IOException {
+
+ String userAgent = request.getHeader("user-agent");
+
+ String clientBrowser = "Not known!";
+
+ if (userAgent != null) {
+
+ clientBrowser = userAgent;
+
+ }
+
+ request.setAttribute("client.browser", clientBrowser);
+
+ request.getRequestDispatcher("/view.jsp").forward(request, response);
+
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/Authorization.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/Authorization.java
index cb17ee4af..46df247b1 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/Authorization.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/Authorization.java
@@ -1,53 +1,72 @@
-
-package org.owasp.webgoat.session;
-
-import java.util.Hashtable;
-import java.util.Map;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public class Authorization
-{
-
- Map permissions = new Hashtable();
-
- public Authorization()
- {
- }
-
- public void setPermission(int userId, int functionId)
- {
- permissions.put(new Integer(userId), new Integer(functionId));
- }
-
- public boolean isAllowed(int userId, int functionId)
- {
- return (permissions.get(new Integer(userId)) != null);
- }
-}
+
+package org.owasp.webgoat.session;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * * @version $Id: $Id
+ */
+public class Authorization
+{
+
+ Map permissions = new Hashtable();
+
+ /**
+ * Constructor for Authorization.
+ */
+ public Authorization()
+ {
+ }
+
+ /**
+ * setPermission.
+ *
+ * @param userId a int.
+ * @param functionId a int.
+ */
+ public void setPermission(int userId, int functionId)
+ {
+ permissions.put(new Integer(userId), new Integer(functionId));
+ }
+
+ /**
+ * isAllowed.
+ *
+ * @param userId a int.
+ * @param functionId a int.
+ * @return a boolean.
+ */
+ public boolean isAllowed(int userId, int functionId)
+ {
+ return (permissions.get(new Integer(userId)) != null);
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/Course.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/Course.java
index b381ba71c..cb3c1a188 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/Course.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/Course.java
@@ -30,37 +30,36 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
* Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
* Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
* For details, please see http://webgoat.github.io
*
* @author Bruce Mayhew WebGoat
- * @created October 28, 2003
+ * @since October 28, 2003
+ * @version $Id: $Id
*/
public class Course {
@@ -76,6 +75,9 @@ public class Course {
private WebgoatContext webgoatContext;
+ /**
+ * Constructor for Course.
+ */
public Course() {
try {
properties = new WebgoatProperties(PROPERTIES_FILENAME);
@@ -86,7 +88,7 @@ public class Course {
/**
* Take an absolute file and return the filename.
- *
+ *
* Ex. /etc/password becomes password
*
* @param s
@@ -108,7 +110,7 @@ public class Course {
/**
* Take a class name and return the equivalent file name
- *
+ *
* Ex. org.owasp.webgoat becomes org/owasp/webgoat.java
*
* @param className
@@ -190,9 +192,9 @@ public class Course {
/**
* Gets the lesson attribute of the Course object
*
- * @param s
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
* @param lessonId Description of the Parameter
- * @param roles
+ * @param roles a {@link java.util.List} object.
* @return The lesson value
*/
public AbstractLesson getLesson(WebSession s, int lessonId, List roles) {
@@ -214,12 +216,27 @@ public class Course {
return null;
}
+ /**
+ * getLesson.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param lessonId a int.
+ * @param role a {@link java.lang.String} object.
+ * @return a {@link org.owasp.webgoat.lessons.AbstractLesson} object.
+ */
public AbstractLesson getLesson(WebSession s, int lessonId, String role) {
List roles = new ArrayList();
roles.add(role);
return getLesson(s, lessonId, roles);
}
+ /**
+ * Getter for the field lessons
.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param role a {@link java.lang.String} object.
+ * @return a {@link java.util.List} object.
+ */
public List getLessons(WebSession s, String role) {
List roles = new ArrayList();
roles.add(role);
@@ -229,8 +246,8 @@ public class Course {
/**
* Gets the lessons attribute of the Course object
*
- * @param s
- * @param roles
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param roles a {@link java.util.List} object.
* @return The lessons value
*/
public List getLessons(WebSession s, List roles) {
@@ -266,12 +283,28 @@ public class Course {
return lessonList;
}
+ /**
+ * Getter for the field lessons
.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param category a {@link org.owasp.webgoat.lessons.Category} object.
+ * @param role a {@link java.lang.String} object.
+ * @return a {@link java.util.List} object.
+ */
public List getLessons(WebSession s, Category category, String role) {
List roles = new ArrayList();
roles.add(role);
return getLessons(s, category, roles);
}
+ /**
+ * Getter for the field lessons
.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param category a {@link org.owasp.webgoat.lessons.Category} object.
+ * @param roles a {@link java.util.List} object.
+ * @return a {@link java.util.List} object.
+ */
public List getLessons(WebSession s, Category category, List roles) {
if (s.isHackedAdmin()) {
roles.add(AbstractLesson.HACKED_ADMIN_ROLE);
@@ -279,6 +312,12 @@ public class Course {
return getLessons(category, roles);
}
+ /**
+ * getLesson.
+ *
+ * @param lessonId a int.
+ * @return a {@link org.owasp.webgoat.lessons.AbstractLesson} object.
+ */
public AbstractLesson getLesson(int lessonId) {
for (AbstractLesson l : lessons) {
if (l.getScreenId() == lessonId) {
@@ -326,7 +365,7 @@ public class Course {
/**
* Description of the Method
*
- * @param webgoatContext
+ * @param webgoatContext a {@link org.owasp.webgoat.session.WebgoatContext} object.
* @param path Description of the Parameter
* @param context Description of the Parameter
*/
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/CreateDB.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/CreateDB.java
index 0e04b2033..0d6ceef2f 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/CreateDB.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/CreateDB.java
@@ -1,1038 +1,1040 @@
-
-package org.owasp.webgoat.session;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-import org.owasp.webgoat.lessons.AbstractLesson;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- */
-public class CreateDB
-{
-
- /**
- * Description of the Method
- *
- * @param connection
- * Description of the Parameter
- *
- * @exception SQLException
- * Description of the Exception
- */
- private void createMessageTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Drop admin user table
- try
- {
- String dropTable = "DROP TABLE messages";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop message database");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE messages (" + "num int not null," + "title varchar(50),"
- + "message varchar(200)," + "user_name varchar(50) not null, " + "lesson_type varchar(50) not null"
- + ")";
- statement.executeUpdate(createTableStatement);
- } catch (SQLException e)
- {
- System.out.println("Error creating message database " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Description of the Method
- *
- * @param connection Description of the Parameter
- *
- * @exception SQLException Description of the Exception
- */
- private void createMFEImagesTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Drop mfe_images table
- try
- {
- String dropTable = "DROP TABLE mfe_images";
- statement.executeUpdate(dropTable);
- }
- catch (SQLException e)
- {
- System.out.println("Info - Could not drop mfe_images table from database");
- }
-
- // Create the new mfe_images table
- try
- {
- String createTableStatement = "CREATE TABLE mfe_images ("
- + "user_name varchar(50) not null, "
- + "image_relative_url varchar(50) not null"
- + ")";
- statement.executeUpdate(createTableStatement);
- }
- catch (SQLException e)
- {
- System.out.println("Error creating mfe_images table in database " + e.getLocalizedMessage());
- }
-
- }
-
- /**
- * Description of the Method
- *
- * @param connection
- * Description of the Parameter
- *
- * @exception SQLException
- * Description of the Exception
- */
- private void createProductTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Drop admin user table
- try
- {
- String dropTable = "DROP TABLE product_system_data";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop product table");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE product_system_data ("
- + "productid varchar(6) not null primary key," + "product_name varchar(20)," + "price varchar(10)"
- + ")";
- statement.executeUpdate(createTableStatement);
- } catch (SQLException e)
- {
- System.out.println("Error creating product table " + e.getLocalizedMessage());
- }
-
- // Populate
- String insertData1 = "INSERT INTO product_system_data VALUES ('32226','Dog Bone','$1.99')";
- String insertData2 = "INSERT INTO product_system_data VALUES ('35632','DVD Player','$214.99')";
- String insertData3 = "INSERT INTO product_system_data VALUES ('24569','60 GB Hard Drive','$149.99')";
- String insertData4 = "INSERT INTO product_system_data VALUES ('56970','80 GB Hard Drive','$179.99')";
- String insertData5 = "INSERT INTO product_system_data VALUES ('14365','56 inch HDTV','$6999.99')";
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData5);
- }
-
- /**
- * Description of the Method
- *
- * @param connection
- * Description of the Parameter
- *
- * @exception SQLException
- * Description of the Exception
- */
- private void createUserAdminTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Drop admin user table
- try
- {
- String dropTable = "DROP TABLE user_system_data";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop user admin table");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE user_system_data (" + "userid varchar(5) not null primary key,"
- + "user_name varchar(12)," + "password varchar(10)," + "cookie varchar(30)" + ")";
- statement.executeUpdate(createTableStatement);
- } catch (SQLException e)
- {
- System.out.println("Error creating user admin table " + e.getLocalizedMessage());
- }
-
- // Populate
- String insertData1 = "INSERT INTO user_system_data VALUES ('101','jsnow','passwd1', '')";
- String insertData2 = "INSERT INTO user_system_data VALUES ('102','jdoe','passwd2', '')";
- String insertData3 = "INSERT INTO user_system_data VALUES ('103','jplane','passwd3', '')";
- String insertData4 = "INSERT INTO user_system_data VALUES ('104','jeff','jeff', '')";
- String insertData5 = "INSERT INTO user_system_data VALUES ('105','dave','dave', '')";
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData5);
- }
-
- /**
- * Description of the Method
- *
- * @param connection
- * Description of the Parameter
- *
- * @exception SQLException
- * Description of the Exception
- */
- private void createUserDataTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Delete table if there is one
- try
- {
- String dropTable = "DROP TABLE user_data";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop user table");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE user_data (" + "userid int not null,"
- + "first_name varchar(20)," + "last_name varchar(20)," + "cc_number varchar(30),"
- + "cc_type varchar(10)," + "cookie varchar(20)," + "login_count int" + ")";
- statement.executeUpdate(createTableStatement);
- } catch (SQLException e)
- {
- System.out.println("Error creating user table " + e.getLocalizedMessage());
- }
-
- // Populate it
- String insertData1 = "INSERT INTO user_data VALUES (101,'Joe','Snow','987654321','VISA',' ',0)";
- String insertData2 = "INSERT INTO user_data VALUES (101,'Joe','Snow','2234200065411','MC',' ',0)";
- String insertData3 = "INSERT INTO user_data VALUES (102,'John','Smith','2435600002222','MC',' ',0)";
- String insertData4 = "INSERT INTO user_data VALUES (102,'John','Smith','4352209902222','AMEX',' ',0)";
- String insertData5 = "INSERT INTO user_data VALUES (103,'Jane','Plane','123456789','MC',' ',0)";
- String insertData6 = "INSERT INTO user_data VALUES (103,'Jane','Plane','333498703333','AMEX',' ',0)";
- String insertData7 = "INSERT INTO user_data VALUES (10312,'Jolly','Hershey','176896789','MC',' ',0)";
- String insertData8 = "INSERT INTO user_data VALUES (10312,'Jolly','Hershey','333300003333','AMEX',' ',0)";
- String insertData9 = "INSERT INTO user_data VALUES (10323,'Grumpy','youaretheweakestlink','673834489','MC',' ',0)";
- String insertData10 = "INSERT INTO user_data VALUES (10323,'Grumpy','youaretheweakestlink','33413003333','AMEX',' ',0)";
- String insertData11 = "INSERT INTO user_data VALUES (15603,'Peter','Sand','123609789','MC',' ',0)";
- String insertData12 = "INSERT INTO user_data VALUES (15603,'Peter','Sand','338893453333','AMEX',' ',0)";
- String insertData13 = "INSERT INTO user_data VALUES (15613,'Joesph','Something','33843453533','AMEX',' ',0)";
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData5);
- statement.executeUpdate(insertData6);
- statement.executeUpdate(insertData7);
- statement.executeUpdate(insertData8);
- statement.executeUpdate(insertData9);
- statement.executeUpdate(insertData10);
- statement.executeUpdate(insertData11);
- statement.executeUpdate(insertData12);
- statement.executeUpdate(insertData13);
-
- }
-
- private void createLoginTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Delete table if there is one
- try
- {
- String dropTable = "DROP TABLE user_login";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop user_login table");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE user_login (" + "userid varchar(5),"
- + "webgoat_user varchar(20)" + ")";
- statement.executeUpdate(createTableStatement);
- } catch (SQLException e)
- {
- System.out.println("Error creating user_login table " + e.getLocalizedMessage());
- }
-
- }
-
- // creates the table pins which is used in the blind sql injection lesson
- private void createBlindSQLLessonTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Delete table if there is one
- try
- {
- String dropTable = "DROP TABLE pins";
- statement.executeUpdate(dropTable);
- }
- catch (SQLException e)
- {
- System.out.println("Info - Could not drop pins table");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE pins ("
- + "cc_number varchar(30),"
- + "pin int,"
- + "name varchar(20)"
- + ")";
- statement.executeUpdate(createTableStatement);
- }
- catch (SQLException e)
- {
- System.out.println("Error creating pins table " + e.getLocalizedMessage());
- }
-
- // Populate it
- String insertData1 = "INSERT INTO pins VALUES ('987654321098765', 1234, 'Joe')";
- String insertData2 = "INSERT INTO pins VALUES ('1234567890123456', 4567, 'Jack')";
- String insertData3 = "INSERT INTO pins VALUES ('4321432143214321', 4321, 'Jill')";
- String insertData4 = "INSERT INTO pins VALUES ('1111111111111111', 7777, 'Jim')";
- String insertData5 = "INSERT INTO pins VALUES ('1111222233334444', 2364, 'John')";
-
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData5);
-
- }
-
- // creates the table salaries which is used in the lessons
- // which add or modify data using sql injection
- private void createModifyWithSQLLessonTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Delete table if there is one
- try
- {
- String dropTable = "DROP TABLE salaries";
- statement.executeUpdate(dropTable);
- }
- catch (SQLException e)
- {
- System.out.println("Info - Could not drop salaries table");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE salaries ("
- + "userid varchar(50),"
- + "salary int"
- + ")";
- statement.executeUpdate(createTableStatement);
- }
- catch (SQLException e)
- {
- System.out.println("Error creating salaries table " + e.getLocalizedMessage());
- }
-
- // Populate it
- String insertData1 = "INSERT INTO salaries VALUES ('jsmith', 20000)";
- String insertData2 = "INSERT INTO salaries VALUES ('lsmith', 45000)";
- String insertData3 = "INSERT INTO salaries VALUES ('wgoat', 100000)";
- String insertData4 = "INSERT INTO salaries VALUES ('rjones', 777777)";
- String insertData5 = "INSERT INTO salaries VALUES ('manderson', 65000)";
-
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData5);
-
- }
-
- /**
- * Description of the Method
- *
- * @param connection
- * Description of the Parameter
- *
- * @exception SQLException
- * Description of the Exception
- */
- private void createWeatherDataTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Delete table if there is one
- try
- {
- String dropTable = "DROP TABLE weather_data";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop weather table");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE weather_data (" + "station int not null,"
- + "name varchar(20) not null," + "state char(2) not null," + "min_temp int not null,"
- + "max_temp int not null" + ")";
- statement.executeUpdate(createTableStatement);
- } catch (SQLException e)
- {
- System.out.println("Error creating weather table " + e.getLocalizedMessage());
- }
-
- // Populate it
- String insertData1 = "INSERT INTO weather_data VALUES (101,'Columbia','MD',-10,102)";
- String insertData2 = "INSERT INTO weather_data VALUES (102,'Seattle','WA',-15,90)";
- String insertData3 = "INSERT INTO weather_data VALUES (103,'New York','NY',-10,110)";
- String insertData4 = "INSERT INTO weather_data VALUES (104,'Houston','TX',20,120)";
- String insertData5 = "INSERT INTO weather_data VALUES (10001,'Camp David','MD',-10,100)";
- String insertData6 = "INSERT INTO weather_data VALUES (11001,'Ice Station Zebra','NA',-60,30)";
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData5);
- statement.executeUpdate(insertData6);
- }
-
- /**
- * Create users with tans
- *
- * @param connection
- * @throws SQLException
- */
- private void createTanUserDataTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Delete table if there is one
- try
- {
- String dropTable = "DROP TABLE user_data_tan";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop user_data_tan table");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE user_data_tan (" + "userid int not null,"
- + "first_name varchar(20)," + "last_name varchar(20)," + "cc_number varchar(30),"
- + "cc_type varchar(10)," + "cookie varchar(20)," + "login_count int," + "password varchar(20)"
- + ")";
- statement.executeUpdate(createTableStatement);
- } catch (SQLException e)
- {
- System.out.println("Error creating user_data_tan table " + e.getLocalizedMessage());
- }
-
- // Populate it
- String insertData1 = "INSERT INTO user_data_tan VALUES (101,'Joe','Snow','987654321','VISA',' ',0, 'banana')";
- String insertData2 = "INSERT INTO user_data_tan VALUES (102,'Jane','Plane','74589864','MC',' ',0, 'tarzan')";
- String insertData3 = "INSERT INTO user_data_tan VALUES (103,'Jack','Sparrow','68659365','MC',' ',0, 'sniffy')";
-
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- }
-
- /**
- * Create the Table for the tans
- *
- * @param connection
- * @throws SQLException
- */
- private void createTanTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- // Delete table if there is one
- try
- {
- String dropTable = "DROP TABLE tan";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop tan table");
- }
-
- // Create the new table
- try
- {
- String createTableStatement = "CREATE TABLE tan (" + "userid int not null," + "tanNr int," + "tanValue int"
- + ")";
- statement.executeUpdate(createTableStatement);
- } catch (SQLException e)
- {
- System.out.println("Error creating tan table " + e.getLocalizedMessage());
- }
-
- // Populate it
- String insertData1 = "INSERT INTO tan VALUES (101,1,15161)";
- String insertData2 = "INSERT INTO tan VALUES (101,2,4894)";
- String insertData3 = "INSERT INTO tan VALUES (101,3,18794)";
- String insertData4 = "INSERT INTO tan VALUES (101,4,1564)";
- String insertData5 = "INSERT INTO tan VALUES (101,5,45751)";
-
- String insertData6 = "INSERT INTO tan VALUES (102,1,15648)";
- String insertData7 = "INSERT INTO tan VALUES (102,2,92156)";
- String insertData8 = "INSERT INTO tan VALUES (102,3,4879)";
- String insertData9 = "INSERT INTO tan VALUES (102,4,9458)";
- String insertData10 = "INSERT INTO tan VALUES (102,5,4879)";
-
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData5);
- statement.executeUpdate(insertData6);
- statement.executeUpdate(insertData7);
- statement.executeUpdate(insertData8);
- statement.executeUpdate(insertData9);
- statement.executeUpdate(insertData10);
-
- }
-
- // --------------------------------------------------------------------------
- // --------------------------------------------------------------------------
- //
- // The tables below are for WebGoat Financials
- //
- // DO NOT MODIFY THESE TABLES - unless you change the org chart
- // and access control matrix documents
- //
- // --------------------------------------------------------------------------
- // --------------------------------------------------------------------------
-
- private void createEmployeeTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- try
- {
- String dropTable = "DROP TABLE employee";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop employee table");
- }
-
- // Create Table
- try
- {
- String createTable = "CREATE TABLE employee ("
- // + "userid INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,"
- + "userid INT NOT NULL PRIMARY KEY," + "first_name VARCHAR(20)," + "last_name VARCHAR(20),"
- + "ssn VARCHAR(12)," + "password VARCHAR(10)," + "title VARCHAR(20)," + "phone VARCHAR(13),"
- + "address1 VARCHAR(80)," + "address2 VARCHAR(80)," + "manager INT," + "start_date CHAR(8),"
- + "salary INT," + "ccn VARCHAR(30)," + "ccn_limit INT," + "email VARCHAR(30)," // reason
- // for the recent write-up
- + "disciplined_date CHAR(8)," // date of write up, NA otherwise
- + "disciplined_notes VARCHAR(60)," // reason for the recent write-up
- + "personal_description VARCHAR(60)" // We can be rude here
- // + ",CONSTRAINT fl UNIQUE NONCLUSTERED (first_name, last_name)"
- + ")";
-
- statement.executeUpdate(createTable);
- } catch (SQLException e)
- {
- System.out.println("Error: unable to create employee table " + e.getLocalizedMessage());
- }
-
- String insertData1 = "INSERT INTO employee VALUES (101, 'Larry', 'Stooge', '386-09-5451', 'larry',"
- + "'Technician','443-689-0192','9175 Guilford Rd','New York, NY', 102, 01012000,55000,'2578546969853547',"
- + "5000,'larry@stooges.com',010106,'Constantly harassing coworkers','Does not work well with others')";
-
- String insertData2 = "INSERT INTO employee VALUES (102, 'Moe', 'Stooge', '936-18-4524','moe',"
- + "'CSO','443-938-5301', '3013 AMD Ave', 'New York, NY', 112, 03082003, 140000, 'NA', 0, 'moe@stooges.com', 0101013, "
- + "'Hit Curly over head', 'Very dominating over Larry and Curly')";
-
- String insertData3 = "INSERT INTO employee VALUES (103, 'Curly', 'Stooge', '961-08-0047','curly',"
- + "'Technician','410-667-6654', '1112 Crusoe Lane', 'New York, NY', 102, 02122001, 50000, 'NA', 0, 'curly@stooges.com', 0101014, "
- + "'Hit Moe back', 'Owes three-thousand to company for fradulent purchases')";
-
- String insertData4 = "INSERT INTO employee VALUES (104, 'Eric', 'Walker', '445-66-5565','eric',"
- + "'Engineer','410-887-1193', '1160 Prescott Rd', 'New York, NY', 107, 12152005, 13000, 'NA', 0, 'eric@modelsrus.com',0101013, "
- + "'Bothering Larry about webgoat problems', 'Late. Always needs help. Too intern-ish.')";
-
- String insertData5 = "INSERT INTO employee VALUES (105, 'Tom', 'Cat', '792-14-6364','tom',"
- + "'Engineer','443-599-0762', '2211 HyperThread Rd.', 'New York, NY', 106, 01011999, 80000, '5481360857968521', 30000, 'tom@wb.com', 0, "
- + "'NA', 'Co-Owner.')";
-
- String insertData6 = "INSERT INTO employee VALUES (106, 'Jerry', 'Mouse', '858-55-4452','jerry',"
- + "'Human Resources','443-699-3366', '3011 Unix Drive', 'New York, NY', 102, 01011999, 70000, '6981754825013564', 20000, 'jerry@wb.com', 0, "
- + "'NA', 'Co-Owner.')";
-
- String insertData7 = "INSERT INTO employee VALUES (107, 'David', 'Giambi', '439-20-9405','david',"
- + "'Human Resources','610-521-8413', '5132 DIMM Avenue', 'New York, NY', 102, 05011999, 100000, '6981754825018101', 10000, 'david@modelsrus.com', 061402, "
- + "'Hacked into accounting server. Modified personal pay.', 'Strong work habbit. Questionable ethics.')";
-
- String insertData8 = "INSERT INTO employee VALUES (108, 'Bruce', 'McGuirre', '707-95-9482','bruce',"
- + "'Engineer','610-282-1103', '8899 FreeBSD Drive ', 'New York, NY', 107, 03012000, 110000, '6981754825854136', 30000, 'bruce@modelsrus.com', 061502, "
- + "'Tortuous Boot Camp workout at 5am. Employees felt sick.', 'Enjoys watching others struggle in exercises.')";
-
- String insertData9 = "INSERT INTO employee VALUES (109, 'Sean', 'Livingston', '136-55-1046','sean',"
- + "'Engineer','610-878-9549', '6422 dFlyBSD Road', 'New York, NY', 107, 06012003, 130000, '6981754825014510', 5000, 'sean@modelsrus.com', 072804, "
- + "'Late to work 30 days in row due to excessive Halo 2', 'Has some fascination with Steelers. Go Ravens.')";
-
- String insertData10 = "INSERT INTO employee VALUES (110, 'Joanne', 'McDougal', '789-54-2413','joanne',"
- + "'Human Resources','610-213-6341', '5567 Broadband Lane', 'New York, NY', 106, 01012001, 90000, '6981754825081054', 300, 'joanne@modelsrus.com', 112005, "
- + "'Used company cc to purchase new car. Limit adjusted.', 'Finds it necessary to leave early every day.')";
-
- String insertData11 = "INSERT INTO employee VALUES (111, 'John', 'Wayne', '129-69-4572', 'john',"
- + "'CTO','610-213-1134', '129 Third St', 'New York, NY', 112, 01012001, 200000, '4437334565679921', 300, 'john@guns.com', 112005, "
- + "'', '')";
- String insertData12 = "INSERT INTO employee VALUES (112, 'Neville', 'Bartholomew', '111-111-1111', 'socks',"
- + "'CEO','408-587-0024', '1 Corporate Headquarters', 'San Jose, CA', 112, 03012000, 450000, '4803389267684109', 300000, 'neville@modelsrus.com', 112005, "
- + "'', '')";
-
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData5);
- statement.executeUpdate(insertData6);
- statement.executeUpdate(insertData7);
- statement.executeUpdate(insertData8);
- statement.executeUpdate(insertData9);
- statement.executeUpdate(insertData10);
- statement.executeUpdate(insertData11);
- statement.executeUpdate(insertData12);
-
- }
-
- private void createRolesTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- try
- {
- String dropTable = "DROP TABLE roles";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop roles table");
- }
-
- try
- {
- String createTable = "CREATE TABLE roles (" + "userid INT NOT NULL," + "role VARCHAR(10) NOT NULL,"
- + "PRIMARY KEY (userid, role)" + ")";
-
- statement.executeUpdate(createTable);
- } catch (SQLException e)
- {
- System.out.println("Error: Unable to create role table: " + e.getLocalizedMessage());
- }
-
- String insertData1 = "INSERT INTO roles VALUES (101, 'employee')";
- String insertData2 = "INSERT INTO roles VALUES (102, 'manager')";
- String insertData3 = "INSERT INTO roles VALUES (103, 'employee')";
- String insertData4 = "INSERT INTO roles VALUES (104, 'employee')";
- String insertData5 = "INSERT INTO roles VALUES (105, 'employee')";
- String insertData6 = "INSERT INTO roles VALUES (106, 'hr')";
- String insertData7 = "INSERT INTO roles VALUES (107, 'manager')";
- String insertData8 = "INSERT INTO roles VALUES (108, 'employee')";
- String insertData9 = "INSERT INTO roles VALUES (109, 'employee')";
- String insertData10 = "INSERT INTO roles VALUES (110, 'hr')";
- String insertData11 = "INSERT INTO roles VALUES (111, 'admin')";
- String insertData12 = "INSERT INTO roles VALUES (112, 'admin')";
-
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData5);
- statement.executeUpdate(insertData6);
- statement.executeUpdate(insertData7);
- statement.executeUpdate(insertData8);
- statement.executeUpdate(insertData9);
- statement.executeUpdate(insertData10);
- statement.executeUpdate(insertData11);
- statement.executeUpdate(insertData12);
- }
-
- private void createAuthTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- try
- {
- String dropTable = "DROP TABLE auth";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop auth table");
- }
-
- try
- {
- String createTable = "CREATE TABLE auth (" + "role VARCHAR(10) NOT NULL,"
- + "functionid VARCHAR(20) NOT NULL," + "PRIMARY KEY (role, functionid)" + ")";
-
- statement.executeUpdate(createTable);
- } catch (SQLException e)
- {
- System.out.println("Error: unable to create auth table: " + e.getLocalizedMessage());
- }
-
- String insertData1 = "INSERT INTO auth VALUES('employee', 'Logout')";
- String insertData2 = "INSERT INTO auth VALUES('employee', 'ListStaff')";
- String insertData3 = "INSERT INTO auth VALUES('employee', 'ViewProfile')";
- String insertData4 = "INSERT INTO auth VALUES('employee', 'EditProfile')";
- String insertData4_1 = "INSERT INTO auth VALUES('employee', 'SearchStaff')";
- String insertData4_2 = "INSERT INTO auth VALUES('employee', 'FindProfile')";
- String insertData5 = "INSERT INTO auth VALUES('manager', 'Logout')";
- String insertData6 = "INSERT INTO auth VALUES('manager', 'ListStaff')";
- String insertData7 = "INSERT INTO auth VALUES('manager', 'ViewProfile')";
- String insertData7_1 = "INSERT INTO auth VALUES('manager', 'SearchStaff')";
- String insertData7_2 = "INSERT INTO auth VALUES('manager', 'FindProfile')";
- // String insertData8 = "INSERT INTO auth VALUES('manager', 'EditProfile')";
- // String insertData9 = "INSERT INTO auth VALUES('manager', 'CreateProfile')";
- // String insertData10 = "INSERT INTO auth VALUES('manager', 'DeleteProfile')";
- // String insertData11 = "INSERT INTO auth VALUES('manager', 'UpdateProfile')";
- String insertData12 = "INSERT INTO auth VALUES('hr', 'Logout')";
- String insertData13 = "INSERT INTO auth VALUES('hr', 'ListStaff')";
- String insertData14 = "INSERT INTO auth VALUES('hr', 'ViewProfile')";
- String insertData15 = "INSERT INTO auth VALUES('hr', 'EditProfile')";
- String insertData16 = "INSERT INTO auth VALUES('hr', 'CreateProfile')";
- String insertData17 = "INSERT INTO auth VALUES('hr', 'DeleteProfile')";
- String insertData18 = "INSERT INTO auth VALUES('hr', 'UpdateProfile')";
- String insertData18_1 = "INSERT INTO auth VALUES('hr', 'SearchStaff')";
- String insertData18_2 = "INSERT INTO auth VALUES('hr', 'FindProfile')";
- String insertData19 = "INSERT INTO auth VALUES('admin', 'Logout')";
- String insertData20 = "INSERT INTO auth VALUES('admin', 'ListStaff')";
- String insertData21 = "INSERT INTO auth VALUES('admin', 'ViewProfile')";
- String insertData22 = "INSERT INTO auth VALUES('admin', 'EditProfile')";
- String insertData23 = "INSERT INTO auth VALUES('admin', 'CreateProfile')";
- String insertData24 = "INSERT INTO auth VALUES('admin', 'DeleteProfile')";
- String insertData25 = "INSERT INTO auth VALUES('admin', 'UpdateProfile')";
- String insertData25_1 = "INSERT INTO auth VALUES('admin', 'SearchStaff')";
- String insertData25_2 = "INSERT INTO auth VALUES('admin', 'FindProfile')";
-
- // Add a permission for the webgoat role to see the source.
- // The challenge(s) will change the default role to "challenge"
- String insertData26 = "INSERT INTO auth VALUES('" + AbstractLesson.USER_ROLE + "','" + WebSession.SHOWSOURCE
- + "')";
- String insertData27 = "INSERT INTO auth VALUES('" + AbstractLesson.USER_ROLE + "','" + WebSession.SHOWHINTS
- + "')";
- // Add a permission for the webgoat role to see the solution.
- // The challenge(s) will change the default role to "challenge"
- String insertData28 = "INSERT INTO auth VALUES('" + AbstractLesson.USER_ROLE + "','" + WebSession.SHOWSOLUTION
- + "')";
-
- statement.executeUpdate(insertData1);
- statement.executeUpdate(insertData2);
- statement.executeUpdate(insertData3);
- statement.executeUpdate(insertData4);
- statement.executeUpdate(insertData4_1);
- statement.executeUpdate(insertData4_2);
- statement.executeUpdate(insertData5);
- statement.executeUpdate(insertData6);
- statement.executeUpdate(insertData7);
- statement.executeUpdate(insertData7_1);
- statement.executeUpdate(insertData7_2);
- // statement.executeUpdate(insertData8);
- // statement.executeUpdate(insertData9);
- // statement.executeUpdate(insertData10);
- // statement.executeUpdate(insertData11);
- statement.executeUpdate(insertData12);
- statement.executeUpdate(insertData13);
- statement.executeUpdate(insertData14);
- statement.executeUpdate(insertData15);
- statement.executeUpdate(insertData16);
- statement.executeUpdate(insertData17);
- statement.executeUpdate(insertData18);
- statement.executeUpdate(insertData18_1);
- statement.executeUpdate(insertData18_2);
- statement.executeUpdate(insertData19);
- statement.executeUpdate(insertData20);
- statement.executeUpdate(insertData21);
- statement.executeUpdate(insertData22);
- statement.executeUpdate(insertData23);
- statement.executeUpdate(insertData24);
- statement.executeUpdate(insertData25);
- statement.executeUpdate(insertData25_1);
- statement.executeUpdate(insertData25_2);
- statement.executeUpdate(insertData26);
- statement.executeUpdate(insertData27);
- statement.executeUpdate(insertData28);
- }
-
- private void createOwnershipTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- try
- {
- String dropTable = "DROP TABLE ownership";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop ownership table");
- }
-
- try
- {
- String createTable = "CREATE TABLE ownership (" + "employer_id INT NOT NULL," + "employee_id INT NOT NULL,"
- + "PRIMARY KEY (employee_id, employer_id)" + ")";
-
- statement.executeUpdate(createTable);
- } catch (SQLException e)
- {
- System.out.println("Error: unable to create ownership table: " + e.getLocalizedMessage());
- }
-
- String inputData = "INSERT INTO ownership VALUES (112, 101)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 102)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 103)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 104)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 105)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 106)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 107)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 108)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 109)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 110)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 111)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (112, 112)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (102, 101)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 102)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 103)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 104)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 105)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 106)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 107)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 108)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 109)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 110)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (102, 111)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (111, 101)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 102)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 103)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 104)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 105)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 106)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 107)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 108)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 109)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 110)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (111, 111)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (106, 105)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (106, 106)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (106, 110)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (101, 101)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (103, 103)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (107, 104)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (107, 108)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (107, 109)";
- statement.executeUpdate(inputData);
- inputData = "INSERT INTO ownership VALUES (107, 107)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (105, 105)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (110, 110)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (104, 104)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (108, 108)";
- statement.executeUpdate(inputData);
-
- inputData = "INSERT INTO ownership VALUES (109, 109)";
- statement.executeUpdate(inputData);
-
- }
-
- // --------------------------------------------------------------------------
- //
- // End of WebGoat Financials
- //
- // --------------------------------------------------------------------------
-
- /**
- * Start creation of data for WebServices labs
- */
-
- private void createTransactionTable(Connection connection) throws SQLException
- {
- Statement statement = connection.createStatement();
-
- try
- {
- String dropTable = "DROP TABLE transactions";
- statement.executeUpdate(dropTable);
- } catch (SQLException e)
- {
- System.out.println("Info - Could not drop transactions table");
- }
-
- try
- {
- String createTable = "CREATE TABLE Transactions (" + "userName VARCHAR(16) NOT NULL, "
- + "sequence INTEGER NOT NULL, " + "from_account VARCHAR(16) NOT NULL, "
- + "to_account VARCHAR(16) NOT NULL, " + "transactionDate TIMESTAMP NOT NULL, "
- + "description VARCHAR(255) NOT NULL, " + "amount INTEGER NOT NULL" + ")";
-
- statement.executeUpdate(createTable);
- } catch (SQLException e)
- {
- System.out.println("Error: unable to create transactions table: " + e.getLocalizedMessage());
- throw e;
- }
-
- String[] data = new String[] {
- "'dave', 0, '238-4723-4024', '324-7635-9867', '2008-02-06 21:40:00', 'Mortgage', '150'",
- "'dave', 1, '238-4723-4024', '324-7635-9867', '2008-02-12 21:41:00', 'Car', '150'",
- "'dave', 2, '238-4723-4024', '324-7635-9867', '2008-02-20 21:42:00', 'School fees', '150'",
- "'CEO', 3, '348-6324-9872', '345-3490-8345', '2008-02-15 21:40:00', 'Rolls Royce', '-150000'",
- "'CEO', 4, '348-6324-9872', '342-5893-4503', '2008-02-25 21:41:00', 'Mansion', '-150000'",
- "'CEO', 5, '348-6324-9872', '980-2344-5492', '2008-02-27 21:42:00', 'Vacation', '-150000'",
- "'jeff', 6, '934-2002-3485', '783-2409-8234', '2008-02-01 21:40:00', 'Vet', '250'",
- "'jeff', 7, '934-2002-3485', '634-5879-0345', '2008-02-19 21:41:00', 'Doctor', '800'",
- "'jeff', 8, '934-2002-3485', '435-4325-3358', '2008-02-20 21:42:00', 'X-rays', '200'", };
- try
- {
- for (int i = 0; i < data.length; i++)
- {
- statement.executeUpdate("INSERT INTO Transactions VALUES (" + data[i] + ");");
- }
- } catch (SQLException sqle)
- {
- System.out.println("Error: Unable to insert transactions: " + sqle.getLocalizedMessage());
- int errorCode = sqle.getErrorCode();
- System.out.println("Error Code: " + errorCode);
- // ignore exceptions for Oracle and SQL Server
- if (errorCode != 911 && errorCode != 273) { throw sqle; }
- }
- }
-
- /**
- * Description of the Method
- *
- * @param connection
- * Description of the Parameter
- *
- * @exception SQLException
- * Description of the Exception
- */
- public void makeDB(Connection connection) throws SQLException
- {
- System.out.println("Successful connection to database");
- createUserDataTable(connection);
- createLoginTable(connection);
- createBlindSQLLessonTable(connection);
- createUserAdminTable(connection);
- createProductTable(connection);
- createMessageTable(connection);
- createEmployeeTable(connection);
- createRolesTable(connection);
- createAuthTable(connection);
- createOwnershipTable(connection);
- createWeatherDataTable(connection);
- createTransactionTable(connection);
- createTanUserDataTable(connection);
- createTanTable(connection);
- createMFEImagesTable(connection);
- createModifyWithSQLLessonTable(connection);
- System.out.println("Success: creating tables.");
- }
-}
+
+package org.owasp.webgoat.session;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import org.owasp.webgoat.lessons.AbstractLesson;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @version $Id: $Id
+ */
+public class CreateDB
+{
+
+ /**
+ * Description of the Method
+ *
+ * @param connection
+ * Description of the Parameter
+ *
+ * @exception SQLException
+ * Description of the Exception
+ */
+ private void createMessageTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Drop admin user table
+ try
+ {
+ String dropTable = "DROP TABLE messages";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop message database");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE messages (" + "num int not null," + "title varchar(50),"
+ + "message varchar(200)," + "user_name varchar(50) not null, " + "lesson_type varchar(50) not null"
+ + ")";
+ statement.executeUpdate(createTableStatement);
+ } catch (SQLException e)
+ {
+ System.out.println("Error creating message database " + e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param connection Description of the Parameter
+ *
+ * @exception SQLException Description of the Exception
+ */
+ private void createMFEImagesTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Drop mfe_images table
+ try
+ {
+ String dropTable = "DROP TABLE mfe_images";
+ statement.executeUpdate(dropTable);
+ }
+ catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop mfe_images table from database");
+ }
+
+ // Create the new mfe_images table
+ try
+ {
+ String createTableStatement = "CREATE TABLE mfe_images ("
+ + "user_name varchar(50) not null, "
+ + "image_relative_url varchar(50) not null"
+ + ")";
+ statement.executeUpdate(createTableStatement);
+ }
+ catch (SQLException e)
+ {
+ System.out.println("Error creating mfe_images table in database " + e.getLocalizedMessage());
+ }
+
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param connection
+ * Description of the Parameter
+ *
+ * @exception SQLException
+ * Description of the Exception
+ */
+ private void createProductTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Drop admin user table
+ try
+ {
+ String dropTable = "DROP TABLE product_system_data";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop product table");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE product_system_data ("
+ + "productid varchar(6) not null primary key," + "product_name varchar(20)," + "price varchar(10)"
+ + ")";
+ statement.executeUpdate(createTableStatement);
+ } catch (SQLException e)
+ {
+ System.out.println("Error creating product table " + e.getLocalizedMessage());
+ }
+
+ // Populate
+ String insertData1 = "INSERT INTO product_system_data VALUES ('32226','Dog Bone','$1.99')";
+ String insertData2 = "INSERT INTO product_system_data VALUES ('35632','DVD Player','$214.99')";
+ String insertData3 = "INSERT INTO product_system_data VALUES ('24569','60 GB Hard Drive','$149.99')";
+ String insertData4 = "INSERT INTO product_system_data VALUES ('56970','80 GB Hard Drive','$179.99')";
+ String insertData5 = "INSERT INTO product_system_data VALUES ('14365','56 inch HDTV','$6999.99')";
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData5);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param connection
+ * Description of the Parameter
+ *
+ * @exception SQLException
+ * Description of the Exception
+ */
+ private void createUserAdminTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Drop admin user table
+ try
+ {
+ String dropTable = "DROP TABLE user_system_data";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop user admin table");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE user_system_data (" + "userid varchar(5) not null primary key,"
+ + "user_name varchar(12)," + "password varchar(10)," + "cookie varchar(30)" + ")";
+ statement.executeUpdate(createTableStatement);
+ } catch (SQLException e)
+ {
+ System.out.println("Error creating user admin table " + e.getLocalizedMessage());
+ }
+
+ // Populate
+ String insertData1 = "INSERT INTO user_system_data VALUES ('101','jsnow','passwd1', '')";
+ String insertData2 = "INSERT INTO user_system_data VALUES ('102','jdoe','passwd2', '')";
+ String insertData3 = "INSERT INTO user_system_data VALUES ('103','jplane','passwd3', '')";
+ String insertData4 = "INSERT INTO user_system_data VALUES ('104','jeff','jeff', '')";
+ String insertData5 = "INSERT INTO user_system_data VALUES ('105','dave','dave', '')";
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData5);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param connection
+ * Description of the Parameter
+ *
+ * @exception SQLException
+ * Description of the Exception
+ */
+ private void createUserDataTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Delete table if there is one
+ try
+ {
+ String dropTable = "DROP TABLE user_data";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop user table");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE user_data (" + "userid int not null,"
+ + "first_name varchar(20)," + "last_name varchar(20)," + "cc_number varchar(30),"
+ + "cc_type varchar(10)," + "cookie varchar(20)," + "login_count int" + ")";
+ statement.executeUpdate(createTableStatement);
+ } catch (SQLException e)
+ {
+ System.out.println("Error creating user table " + e.getLocalizedMessage());
+ }
+
+ // Populate it
+ String insertData1 = "INSERT INTO user_data VALUES (101,'Joe','Snow','987654321','VISA',' ',0)";
+ String insertData2 = "INSERT INTO user_data VALUES (101,'Joe','Snow','2234200065411','MC',' ',0)";
+ String insertData3 = "INSERT INTO user_data VALUES (102,'John','Smith','2435600002222','MC',' ',0)";
+ String insertData4 = "INSERT INTO user_data VALUES (102,'John','Smith','4352209902222','AMEX',' ',0)";
+ String insertData5 = "INSERT INTO user_data VALUES (103,'Jane','Plane','123456789','MC',' ',0)";
+ String insertData6 = "INSERT INTO user_data VALUES (103,'Jane','Plane','333498703333','AMEX',' ',0)";
+ String insertData7 = "INSERT INTO user_data VALUES (10312,'Jolly','Hershey','176896789','MC',' ',0)";
+ String insertData8 = "INSERT INTO user_data VALUES (10312,'Jolly','Hershey','333300003333','AMEX',' ',0)";
+ String insertData9 = "INSERT INTO user_data VALUES (10323,'Grumpy','youaretheweakestlink','673834489','MC',' ',0)";
+ String insertData10 = "INSERT INTO user_data VALUES (10323,'Grumpy','youaretheweakestlink','33413003333','AMEX',' ',0)";
+ String insertData11 = "INSERT INTO user_data VALUES (15603,'Peter','Sand','123609789','MC',' ',0)";
+ String insertData12 = "INSERT INTO user_data VALUES (15603,'Peter','Sand','338893453333','AMEX',' ',0)";
+ String insertData13 = "INSERT INTO user_data VALUES (15613,'Joesph','Something','33843453533','AMEX',' ',0)";
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData5);
+ statement.executeUpdate(insertData6);
+ statement.executeUpdate(insertData7);
+ statement.executeUpdate(insertData8);
+ statement.executeUpdate(insertData9);
+ statement.executeUpdate(insertData10);
+ statement.executeUpdate(insertData11);
+ statement.executeUpdate(insertData12);
+ statement.executeUpdate(insertData13);
+
+ }
+
+ private void createLoginTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Delete table if there is one
+ try
+ {
+ String dropTable = "DROP TABLE user_login";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop user_login table");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE user_login (" + "userid varchar(5),"
+ + "webgoat_user varchar(20)" + ")";
+ statement.executeUpdate(createTableStatement);
+ } catch (SQLException e)
+ {
+ System.out.println("Error creating user_login table " + e.getLocalizedMessage());
+ }
+
+ }
+
+ // creates the table pins which is used in the blind sql injection lesson
+ private void createBlindSQLLessonTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Delete table if there is one
+ try
+ {
+ String dropTable = "DROP TABLE pins";
+ statement.executeUpdate(dropTable);
+ }
+ catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop pins table");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE pins ("
+ + "cc_number varchar(30),"
+ + "pin int,"
+ + "name varchar(20)"
+ + ")";
+ statement.executeUpdate(createTableStatement);
+ }
+ catch (SQLException e)
+ {
+ System.out.println("Error creating pins table " + e.getLocalizedMessage());
+ }
+
+ // Populate it
+ String insertData1 = "INSERT INTO pins VALUES ('987654321098765', 1234, 'Joe')";
+ String insertData2 = "INSERT INTO pins VALUES ('1234567890123456', 4567, 'Jack')";
+ String insertData3 = "INSERT INTO pins VALUES ('4321432143214321', 4321, 'Jill')";
+ String insertData4 = "INSERT INTO pins VALUES ('1111111111111111', 7777, 'Jim')";
+ String insertData5 = "INSERT INTO pins VALUES ('1111222233334444', 2364, 'John')";
+
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData5);
+
+ }
+
+ // creates the table salaries which is used in the lessons
+ // which add or modify data using sql injection
+ private void createModifyWithSQLLessonTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Delete table if there is one
+ try
+ {
+ String dropTable = "DROP TABLE salaries";
+ statement.executeUpdate(dropTable);
+ }
+ catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop salaries table");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE salaries ("
+ + "userid varchar(50),"
+ + "salary int"
+ + ")";
+ statement.executeUpdate(createTableStatement);
+ }
+ catch (SQLException e)
+ {
+ System.out.println("Error creating salaries table " + e.getLocalizedMessage());
+ }
+
+ // Populate it
+ String insertData1 = "INSERT INTO salaries VALUES ('jsmith', 20000)";
+ String insertData2 = "INSERT INTO salaries VALUES ('lsmith', 45000)";
+ String insertData3 = "INSERT INTO salaries VALUES ('wgoat', 100000)";
+ String insertData4 = "INSERT INTO salaries VALUES ('rjones', 777777)";
+ String insertData5 = "INSERT INTO salaries VALUES ('manderson', 65000)";
+
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData5);
+
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param connection
+ * Description of the Parameter
+ *
+ * @exception SQLException
+ * Description of the Exception
+ */
+ private void createWeatherDataTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Delete table if there is one
+ try
+ {
+ String dropTable = "DROP TABLE weather_data";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop weather table");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE weather_data (" + "station int not null,"
+ + "name varchar(20) not null," + "state char(2) not null," + "min_temp int not null,"
+ + "max_temp int not null" + ")";
+ statement.executeUpdate(createTableStatement);
+ } catch (SQLException e)
+ {
+ System.out.println("Error creating weather table " + e.getLocalizedMessage());
+ }
+
+ // Populate it
+ String insertData1 = "INSERT INTO weather_data VALUES (101,'Columbia','MD',-10,102)";
+ String insertData2 = "INSERT INTO weather_data VALUES (102,'Seattle','WA',-15,90)";
+ String insertData3 = "INSERT INTO weather_data VALUES (103,'New York','NY',-10,110)";
+ String insertData4 = "INSERT INTO weather_data VALUES (104,'Houston','TX',20,120)";
+ String insertData5 = "INSERT INTO weather_data VALUES (10001,'Camp David','MD',-10,100)";
+ String insertData6 = "INSERT INTO weather_data VALUES (11001,'Ice Station Zebra','NA',-60,30)";
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData5);
+ statement.executeUpdate(insertData6);
+ }
+
+ /**
+ * Create users with tans
+ *
+ * @param connection
+ * @throws SQLException
+ */
+ private void createTanUserDataTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Delete table if there is one
+ try
+ {
+ String dropTable = "DROP TABLE user_data_tan";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop user_data_tan table");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE user_data_tan (" + "userid int not null,"
+ + "first_name varchar(20)," + "last_name varchar(20)," + "cc_number varchar(30),"
+ + "cc_type varchar(10)," + "cookie varchar(20)," + "login_count int," + "password varchar(20)"
+ + ")";
+ statement.executeUpdate(createTableStatement);
+ } catch (SQLException e)
+ {
+ System.out.println("Error creating user_data_tan table " + e.getLocalizedMessage());
+ }
+
+ // Populate it
+ String insertData1 = "INSERT INTO user_data_tan VALUES (101,'Joe','Snow','987654321','VISA',' ',0, 'banana')";
+ String insertData2 = "INSERT INTO user_data_tan VALUES (102,'Jane','Plane','74589864','MC',' ',0, 'tarzan')";
+ String insertData3 = "INSERT INTO user_data_tan VALUES (103,'Jack','Sparrow','68659365','MC',' ',0, 'sniffy')";
+
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ }
+
+ /**
+ * Create the Table for the tans
+ *
+ * @param connection
+ * @throws SQLException
+ */
+ private void createTanTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ // Delete table if there is one
+ try
+ {
+ String dropTable = "DROP TABLE tan";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop tan table");
+ }
+
+ // Create the new table
+ try
+ {
+ String createTableStatement = "CREATE TABLE tan (" + "userid int not null," + "tanNr int," + "tanValue int"
+ + ")";
+ statement.executeUpdate(createTableStatement);
+ } catch (SQLException e)
+ {
+ System.out.println("Error creating tan table " + e.getLocalizedMessage());
+ }
+
+ // Populate it
+ String insertData1 = "INSERT INTO tan VALUES (101,1,15161)";
+ String insertData2 = "INSERT INTO tan VALUES (101,2,4894)";
+ String insertData3 = "INSERT INTO tan VALUES (101,3,18794)";
+ String insertData4 = "INSERT INTO tan VALUES (101,4,1564)";
+ String insertData5 = "INSERT INTO tan VALUES (101,5,45751)";
+
+ String insertData6 = "INSERT INTO tan VALUES (102,1,15648)";
+ String insertData7 = "INSERT INTO tan VALUES (102,2,92156)";
+ String insertData8 = "INSERT INTO tan VALUES (102,3,4879)";
+ String insertData9 = "INSERT INTO tan VALUES (102,4,9458)";
+ String insertData10 = "INSERT INTO tan VALUES (102,5,4879)";
+
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData5);
+ statement.executeUpdate(insertData6);
+ statement.executeUpdate(insertData7);
+ statement.executeUpdate(insertData8);
+ statement.executeUpdate(insertData9);
+ statement.executeUpdate(insertData10);
+
+ }
+
+ // --------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
+ //
+ // The tables below are for WebGoat Financials
+ //
+ // DO NOT MODIFY THESE TABLES - unless you change the org chart
+ // and access control matrix documents
+ //
+ // --------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
+
+ private void createEmployeeTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ try
+ {
+ String dropTable = "DROP TABLE employee";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop employee table");
+ }
+
+ // Create Table
+ try
+ {
+ String createTable = "CREATE TABLE employee ("
+ // + "userid INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,"
+ + "userid INT NOT NULL PRIMARY KEY," + "first_name VARCHAR(20)," + "last_name VARCHAR(20),"
+ + "ssn VARCHAR(12)," + "password VARCHAR(10)," + "title VARCHAR(20)," + "phone VARCHAR(13),"
+ + "address1 VARCHAR(80)," + "address2 VARCHAR(80)," + "manager INT," + "start_date CHAR(8),"
+ + "salary INT," + "ccn VARCHAR(30)," + "ccn_limit INT," + "email VARCHAR(30)," // reason
+ // for the recent write-up
+ + "disciplined_date CHAR(8)," // date of write up, NA otherwise
+ + "disciplined_notes VARCHAR(60)," // reason for the recent write-up
+ + "personal_description VARCHAR(60)" // We can be rude here
+ // + ",CONSTRAINT fl UNIQUE NONCLUSTERED (first_name, last_name)"
+ + ")";
+
+ statement.executeUpdate(createTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Error: unable to create employee table " + e.getLocalizedMessage());
+ }
+
+ String insertData1 = "INSERT INTO employee VALUES (101, 'Larry', 'Stooge', '386-09-5451', 'larry',"
+ + "'Technician','443-689-0192','9175 Guilford Rd','New York, NY', 102, 01012000,55000,'2578546969853547',"
+ + "5000,'larry@stooges.com',010106,'Constantly harassing coworkers','Does not work well with others')";
+
+ String insertData2 = "INSERT INTO employee VALUES (102, 'Moe', 'Stooge', '936-18-4524','moe',"
+ + "'CSO','443-938-5301', '3013 AMD Ave', 'New York, NY', 112, 03082003, 140000, 'NA', 0, 'moe@stooges.com', 0101013, "
+ + "'Hit Curly over head', 'Very dominating over Larry and Curly')";
+
+ String insertData3 = "INSERT INTO employee VALUES (103, 'Curly', 'Stooge', '961-08-0047','curly',"
+ + "'Technician','410-667-6654', '1112 Crusoe Lane', 'New York, NY', 102, 02122001, 50000, 'NA', 0, 'curly@stooges.com', 0101014, "
+ + "'Hit Moe back', 'Owes three-thousand to company for fradulent purchases')";
+
+ String insertData4 = "INSERT INTO employee VALUES (104, 'Eric', 'Walker', '445-66-5565','eric',"
+ + "'Engineer','410-887-1193', '1160 Prescott Rd', 'New York, NY', 107, 12152005, 13000, 'NA', 0, 'eric@modelsrus.com',0101013, "
+ + "'Bothering Larry about webgoat problems', 'Late. Always needs help. Too intern-ish.')";
+
+ String insertData5 = "INSERT INTO employee VALUES (105, 'Tom', 'Cat', '792-14-6364','tom',"
+ + "'Engineer','443-599-0762', '2211 HyperThread Rd.', 'New York, NY', 106, 01011999, 80000, '5481360857968521', 30000, 'tom@wb.com', 0, "
+ + "'NA', 'Co-Owner.')";
+
+ String insertData6 = "INSERT INTO employee VALUES (106, 'Jerry', 'Mouse', '858-55-4452','jerry',"
+ + "'Human Resources','443-699-3366', '3011 Unix Drive', 'New York, NY', 102, 01011999, 70000, '6981754825013564', 20000, 'jerry@wb.com', 0, "
+ + "'NA', 'Co-Owner.')";
+
+ String insertData7 = "INSERT INTO employee VALUES (107, 'David', 'Giambi', '439-20-9405','david',"
+ + "'Human Resources','610-521-8413', '5132 DIMM Avenue', 'New York, NY', 102, 05011999, 100000, '6981754825018101', 10000, 'david@modelsrus.com', 061402, "
+ + "'Hacked into accounting server. Modified personal pay.', 'Strong work habbit. Questionable ethics.')";
+
+ String insertData8 = "INSERT INTO employee VALUES (108, 'Bruce', 'McGuirre', '707-95-9482','bruce',"
+ + "'Engineer','610-282-1103', '8899 FreeBSD Drive ', 'New York, NY', 107, 03012000, 110000, '6981754825854136', 30000, 'bruce@modelsrus.com', 061502, "
+ + "'Tortuous Boot Camp workout at 5am. Employees felt sick.', 'Enjoys watching others struggle in exercises.')";
+
+ String insertData9 = "INSERT INTO employee VALUES (109, 'Sean', 'Livingston', '136-55-1046','sean',"
+ + "'Engineer','610-878-9549', '6422 dFlyBSD Road', 'New York, NY', 107, 06012003, 130000, '6981754825014510', 5000, 'sean@modelsrus.com', 072804, "
+ + "'Late to work 30 days in row due to excessive Halo 2', 'Has some fascination with Steelers. Go Ravens.')";
+
+ String insertData10 = "INSERT INTO employee VALUES (110, 'Joanne', 'McDougal', '789-54-2413','joanne',"
+ + "'Human Resources','610-213-6341', '5567 Broadband Lane', 'New York, NY', 106, 01012001, 90000, '6981754825081054', 300, 'joanne@modelsrus.com', 112005, "
+ + "'Used company cc to purchase new car. Limit adjusted.', 'Finds it necessary to leave early every day.')";
+
+ String insertData11 = "INSERT INTO employee VALUES (111, 'John', 'Wayne', '129-69-4572', 'john',"
+ + "'CTO','610-213-1134', '129 Third St', 'New York, NY', 112, 01012001, 200000, '4437334565679921', 300, 'john@guns.com', 112005, "
+ + "'', '')";
+ String insertData12 = "INSERT INTO employee VALUES (112, 'Neville', 'Bartholomew', '111-111-1111', 'socks',"
+ + "'CEO','408-587-0024', '1 Corporate Headquarters', 'San Jose, CA', 112, 03012000, 450000, '4803389267684109', 300000, 'neville@modelsrus.com', 112005, "
+ + "'', '')";
+
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData5);
+ statement.executeUpdate(insertData6);
+ statement.executeUpdate(insertData7);
+ statement.executeUpdate(insertData8);
+ statement.executeUpdate(insertData9);
+ statement.executeUpdate(insertData10);
+ statement.executeUpdate(insertData11);
+ statement.executeUpdate(insertData12);
+
+ }
+
+ private void createRolesTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ try
+ {
+ String dropTable = "DROP TABLE roles";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop roles table");
+ }
+
+ try
+ {
+ String createTable = "CREATE TABLE roles (" + "userid INT NOT NULL," + "role VARCHAR(10) NOT NULL,"
+ + "PRIMARY KEY (userid, role)" + ")";
+
+ statement.executeUpdate(createTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Error: Unable to create role table: " + e.getLocalizedMessage());
+ }
+
+ String insertData1 = "INSERT INTO roles VALUES (101, 'employee')";
+ String insertData2 = "INSERT INTO roles VALUES (102, 'manager')";
+ String insertData3 = "INSERT INTO roles VALUES (103, 'employee')";
+ String insertData4 = "INSERT INTO roles VALUES (104, 'employee')";
+ String insertData5 = "INSERT INTO roles VALUES (105, 'employee')";
+ String insertData6 = "INSERT INTO roles VALUES (106, 'hr')";
+ String insertData7 = "INSERT INTO roles VALUES (107, 'manager')";
+ String insertData8 = "INSERT INTO roles VALUES (108, 'employee')";
+ String insertData9 = "INSERT INTO roles VALUES (109, 'employee')";
+ String insertData10 = "INSERT INTO roles VALUES (110, 'hr')";
+ String insertData11 = "INSERT INTO roles VALUES (111, 'admin')";
+ String insertData12 = "INSERT INTO roles VALUES (112, 'admin')";
+
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData5);
+ statement.executeUpdate(insertData6);
+ statement.executeUpdate(insertData7);
+ statement.executeUpdate(insertData8);
+ statement.executeUpdate(insertData9);
+ statement.executeUpdate(insertData10);
+ statement.executeUpdate(insertData11);
+ statement.executeUpdate(insertData12);
+ }
+
+ private void createAuthTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ try
+ {
+ String dropTable = "DROP TABLE auth";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop auth table");
+ }
+
+ try
+ {
+ String createTable = "CREATE TABLE auth (" + "role VARCHAR(10) NOT NULL,"
+ + "functionid VARCHAR(20) NOT NULL," + "PRIMARY KEY (role, functionid)" + ")";
+
+ statement.executeUpdate(createTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Error: unable to create auth table: " + e.getLocalizedMessage());
+ }
+
+ String insertData1 = "INSERT INTO auth VALUES('employee', 'Logout')";
+ String insertData2 = "INSERT INTO auth VALUES('employee', 'ListStaff')";
+ String insertData3 = "INSERT INTO auth VALUES('employee', 'ViewProfile')";
+ String insertData4 = "INSERT INTO auth VALUES('employee', 'EditProfile')";
+ String insertData4_1 = "INSERT INTO auth VALUES('employee', 'SearchStaff')";
+ String insertData4_2 = "INSERT INTO auth VALUES('employee', 'FindProfile')";
+ String insertData5 = "INSERT INTO auth VALUES('manager', 'Logout')";
+ String insertData6 = "INSERT INTO auth VALUES('manager', 'ListStaff')";
+ String insertData7 = "INSERT INTO auth VALUES('manager', 'ViewProfile')";
+ String insertData7_1 = "INSERT INTO auth VALUES('manager', 'SearchStaff')";
+ String insertData7_2 = "INSERT INTO auth VALUES('manager', 'FindProfile')";
+ // String insertData8 = "INSERT INTO auth VALUES('manager', 'EditProfile')";
+ // String insertData9 = "INSERT INTO auth VALUES('manager', 'CreateProfile')";
+ // String insertData10 = "INSERT INTO auth VALUES('manager', 'DeleteProfile')";
+ // String insertData11 = "INSERT INTO auth VALUES('manager', 'UpdateProfile')";
+ String insertData12 = "INSERT INTO auth VALUES('hr', 'Logout')";
+ String insertData13 = "INSERT INTO auth VALUES('hr', 'ListStaff')";
+ String insertData14 = "INSERT INTO auth VALUES('hr', 'ViewProfile')";
+ String insertData15 = "INSERT INTO auth VALUES('hr', 'EditProfile')";
+ String insertData16 = "INSERT INTO auth VALUES('hr', 'CreateProfile')";
+ String insertData17 = "INSERT INTO auth VALUES('hr', 'DeleteProfile')";
+ String insertData18 = "INSERT INTO auth VALUES('hr', 'UpdateProfile')";
+ String insertData18_1 = "INSERT INTO auth VALUES('hr', 'SearchStaff')";
+ String insertData18_2 = "INSERT INTO auth VALUES('hr', 'FindProfile')";
+ String insertData19 = "INSERT INTO auth VALUES('admin', 'Logout')";
+ String insertData20 = "INSERT INTO auth VALUES('admin', 'ListStaff')";
+ String insertData21 = "INSERT INTO auth VALUES('admin', 'ViewProfile')";
+ String insertData22 = "INSERT INTO auth VALUES('admin', 'EditProfile')";
+ String insertData23 = "INSERT INTO auth VALUES('admin', 'CreateProfile')";
+ String insertData24 = "INSERT INTO auth VALUES('admin', 'DeleteProfile')";
+ String insertData25 = "INSERT INTO auth VALUES('admin', 'UpdateProfile')";
+ String insertData25_1 = "INSERT INTO auth VALUES('admin', 'SearchStaff')";
+ String insertData25_2 = "INSERT INTO auth VALUES('admin', 'FindProfile')";
+
+ // Add a permission for the webgoat role to see the source.
+ // The challenge(s) will change the default role to "challenge"
+ String insertData26 = "INSERT INTO auth VALUES('" + AbstractLesson.USER_ROLE + "','" + WebSession.SHOWSOURCE
+ + "')";
+ String insertData27 = "INSERT INTO auth VALUES('" + AbstractLesson.USER_ROLE + "','" + WebSession.SHOWHINTS
+ + "')";
+ // Add a permission for the webgoat role to see the solution.
+ // The challenge(s) will change the default role to "challenge"
+ String insertData28 = "INSERT INTO auth VALUES('" + AbstractLesson.USER_ROLE + "','" + WebSession.SHOWSOLUTION
+ + "')";
+
+ statement.executeUpdate(insertData1);
+ statement.executeUpdate(insertData2);
+ statement.executeUpdate(insertData3);
+ statement.executeUpdate(insertData4);
+ statement.executeUpdate(insertData4_1);
+ statement.executeUpdate(insertData4_2);
+ statement.executeUpdate(insertData5);
+ statement.executeUpdate(insertData6);
+ statement.executeUpdate(insertData7);
+ statement.executeUpdate(insertData7_1);
+ statement.executeUpdate(insertData7_2);
+ // statement.executeUpdate(insertData8);
+ // statement.executeUpdate(insertData9);
+ // statement.executeUpdate(insertData10);
+ // statement.executeUpdate(insertData11);
+ statement.executeUpdate(insertData12);
+ statement.executeUpdate(insertData13);
+ statement.executeUpdate(insertData14);
+ statement.executeUpdate(insertData15);
+ statement.executeUpdate(insertData16);
+ statement.executeUpdate(insertData17);
+ statement.executeUpdate(insertData18);
+ statement.executeUpdate(insertData18_1);
+ statement.executeUpdate(insertData18_2);
+ statement.executeUpdate(insertData19);
+ statement.executeUpdate(insertData20);
+ statement.executeUpdate(insertData21);
+ statement.executeUpdate(insertData22);
+ statement.executeUpdate(insertData23);
+ statement.executeUpdate(insertData24);
+ statement.executeUpdate(insertData25);
+ statement.executeUpdate(insertData25_1);
+ statement.executeUpdate(insertData25_2);
+ statement.executeUpdate(insertData26);
+ statement.executeUpdate(insertData27);
+ statement.executeUpdate(insertData28);
+ }
+
+ private void createOwnershipTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ try
+ {
+ String dropTable = "DROP TABLE ownership";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop ownership table");
+ }
+
+ try
+ {
+ String createTable = "CREATE TABLE ownership (" + "employer_id INT NOT NULL," + "employee_id INT NOT NULL,"
+ + "PRIMARY KEY (employee_id, employer_id)" + ")";
+
+ statement.executeUpdate(createTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Error: unable to create ownership table: " + e.getLocalizedMessage());
+ }
+
+ String inputData = "INSERT INTO ownership VALUES (112, 101)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 102)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 103)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 104)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 105)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 106)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 107)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 108)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 109)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 110)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 111)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (112, 112)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (102, 101)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 102)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 103)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 104)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 105)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 106)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 107)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 108)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 109)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 110)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (102, 111)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (111, 101)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 102)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 103)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 104)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 105)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 106)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 107)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 108)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 109)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 110)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (111, 111)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (106, 105)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (106, 106)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (106, 110)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (101, 101)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (103, 103)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (107, 104)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (107, 108)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (107, 109)";
+ statement.executeUpdate(inputData);
+ inputData = "INSERT INTO ownership VALUES (107, 107)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (105, 105)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (110, 110)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (104, 104)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (108, 108)";
+ statement.executeUpdate(inputData);
+
+ inputData = "INSERT INTO ownership VALUES (109, 109)";
+ statement.executeUpdate(inputData);
+
+ }
+
+ // --------------------------------------------------------------------------
+ //
+ // End of WebGoat Financials
+ //
+ // --------------------------------------------------------------------------
+
+ /**
+ * Start creation of data for WebServices labs
+ */
+
+ private void createTransactionTable(Connection connection) throws SQLException
+ {
+ Statement statement = connection.createStatement();
+
+ try
+ {
+ String dropTable = "DROP TABLE transactions";
+ statement.executeUpdate(dropTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Info - Could not drop transactions table");
+ }
+
+ try
+ {
+ String createTable = "CREATE TABLE Transactions (" + "userName VARCHAR(16) NOT NULL, "
+ + "sequence INTEGER NOT NULL, " + "from_account VARCHAR(16) NOT NULL, "
+ + "to_account VARCHAR(16) NOT NULL, " + "transactionDate TIMESTAMP NOT NULL, "
+ + "description VARCHAR(255) NOT NULL, " + "amount INTEGER NOT NULL" + ")";
+
+ statement.executeUpdate(createTable);
+ } catch (SQLException e)
+ {
+ System.out.println("Error: unable to create transactions table: " + e.getLocalizedMessage());
+ throw e;
+ }
+
+ String[] data = new String[] {
+ "'dave', 0, '238-4723-4024', '324-7635-9867', '2008-02-06 21:40:00', 'Mortgage', '150'",
+ "'dave', 1, '238-4723-4024', '324-7635-9867', '2008-02-12 21:41:00', 'Car', '150'",
+ "'dave', 2, '238-4723-4024', '324-7635-9867', '2008-02-20 21:42:00', 'School fees', '150'",
+ "'CEO', 3, '348-6324-9872', '345-3490-8345', '2008-02-15 21:40:00', 'Rolls Royce', '-150000'",
+ "'CEO', 4, '348-6324-9872', '342-5893-4503', '2008-02-25 21:41:00', 'Mansion', '-150000'",
+ "'CEO', 5, '348-6324-9872', '980-2344-5492', '2008-02-27 21:42:00', 'Vacation', '-150000'",
+ "'jeff', 6, '934-2002-3485', '783-2409-8234', '2008-02-01 21:40:00', 'Vet', '250'",
+ "'jeff', 7, '934-2002-3485', '634-5879-0345', '2008-02-19 21:41:00', 'Doctor', '800'",
+ "'jeff', 8, '934-2002-3485', '435-4325-3358', '2008-02-20 21:42:00', 'X-rays', '200'", };
+ try
+ {
+ for (int i = 0; i < data.length; i++)
+ {
+ statement.executeUpdate("INSERT INTO Transactions VALUES (" + data[i] + ");");
+ }
+ } catch (SQLException sqle)
+ {
+ System.out.println("Error: Unable to insert transactions: " + sqle.getLocalizedMessage());
+ int errorCode = sqle.getErrorCode();
+ System.out.println("Error Code: " + errorCode);
+ // ignore exceptions for Oracle and SQL Server
+ if (errorCode != 911 && errorCode != 273) { throw sqle; }
+ }
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param connection
+ * Description of the Parameter
+ * @exception SQLException
+ * Description of the Exception
+ * @throws java.sql.SQLException if any.
+ */
+ public void makeDB(Connection connection) throws SQLException
+ {
+ System.out.println("Successful connection to database");
+ createUserDataTable(connection);
+ createLoginTable(connection);
+ createBlindSQLLessonTable(connection);
+ createUserAdminTable(connection);
+ createProductTable(connection);
+ createMessageTable(connection);
+ createEmployeeTable(connection);
+ createRolesTable(connection);
+ createAuthTable(connection);
+ createOwnershipTable(connection);
+ createWeatherDataTable(connection);
+ createTransactionTable(connection);
+ createTanUserDataTable(connection);
+ createTanTable(connection);
+ createMFEImagesTable(connection);
+ createModifyWithSQLLessonTable(connection);
+ System.out.println("Success: creating tables.");
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/DatabaseUtilities.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/DatabaseUtilities.java
index 1a9638a3b..79b56858c 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/DatabaseUtilities.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/DatabaseUtilities.java
@@ -1,173 +1,197 @@
-
-package org.owasp.webgoat.session;
-
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.ecs.MultiPartElement;
-import org.apache.ecs.html.B;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- */
-public class DatabaseUtilities
-{
-
- private static Map connections = new HashMap();
- private static Map dbBuilt = new HashMap();
-
- public static Connection getConnection(WebSession s) throws SQLException
- {
- return getConnection(s.getUserName(), s.getWebgoatContext());
- }
-
- public static synchronized Connection getConnection(String user, WebgoatContext context) throws SQLException
- {
- Connection conn = connections.get(user);
- if (conn != null && !conn.isClosed()) return conn;
- conn = makeConnection(user, context);
- connections.put(user, conn);
-
- if (dbBuilt.get(user) == null)
- {
- new CreateDB().makeDB(conn);
- dbBuilt.put(user, Boolean.TRUE);
- }
-
- return conn;
- }
-
- public static synchronized void returnConnection(String user)
- {
- try
- {
- Connection connection = connections.get(user);
- if (connection == null || connection.isClosed()) return;
-
- if (connection.getMetaData().getDatabaseProductName().toLowerCase().contains("oracle")) connection.close();
- } catch (SQLException sqle)
- {
- sqle.printStackTrace();
- }
- }
-
- private static Connection makeConnection(String user, WebgoatContext context) throws SQLException
- {
- try
- {
- Class.forName(context.getDatabaseDriver());
-
- if (context.getDatabaseConnectionString().contains("hsqldb")) return getHsqldbConnection(user, context);
-
- String userPrefix = context.getDatabaseUser();
- String password = context.getDatabasePassword();
- String url = context.getDatabaseConnectionString();
- return DriverManager.getConnection(url, userPrefix + "_" + user, password);
- } catch (ClassNotFoundException cnfe)
- {
- cnfe.printStackTrace();
- throw new SQLException("Couldn't load the database driver: " + cnfe.getLocalizedMessage());
- }
- }
-
- private static Connection getHsqldbConnection(String user, WebgoatContext context) throws ClassNotFoundException,
- SQLException
- {
- String url = context.getDatabaseConnectionString().replaceAll("\\$\\{USER\\}", user);
- return DriverManager.getConnection(url, "sa", "");
- }
-
- /**
- * Description of the Method
- *
- * @param results
- * Description of the Parameter
- * @param resultsMetaData
- * Description of the Parameter
- *
- * @return Description of the Return Value
- *
- * @exception IOException
- * Description of the Exception
- * @exception SQLException
- * Description of the Exception
- */
- public static MultiPartElement writeTable(ResultSet results, ResultSetMetaData resultsMetaData) throws IOException,
- SQLException
- {
- int numColumns = resultsMetaData.getColumnCount();
- results.beforeFirst();
-
- if (results.next())
- {
- Table t = new Table(1); // 1 = with border
- t.setCellPadding(1);
-
- TR tr = new TR();
-
- for (int i = 1; i < (numColumns + 1); i++)
- {
- tr.addElement(new TD(new B(resultsMetaData.getColumnName(i))));
- }
-
- t.addElement(tr);
- results.beforeFirst();
-
- while (results.next())
- {
- TR row = new TR();
-
- for (int i = 1; i < (numColumns + 1); i++)
- {
- String str = results.getString(i);
- if (str == null) str = "";
- row.addElement(new TD(str.replaceAll(" ", " ")));
- }
-
- t.addElement(row);
- }
-
- return (t);
- }
- else
- {
- return (new B("Query Successful; however no data was returned from this query."));
- }
- }
-
-}
+
+package org.owasp.webgoat.session;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.ecs.MultiPartElement;
+import org.apache.ecs.html.B;
+import org.apache.ecs.html.TD;
+import org.apache.ecs.html.TR;
+import org.apache.ecs.html.Table;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @version $Id: $Id
+ */
+public class DatabaseUtilities
+{
+
+ private static Map connections = new HashMap();
+ private static Map dbBuilt = new HashMap();
+
+ /**
+ * getConnection.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.sql.Connection} object.
+ * @throws java.sql.SQLException if any.
+ */
+ public static Connection getConnection(WebSession s) throws SQLException
+ {
+ return getConnection(s.getUserName(), s.getWebgoatContext());
+ }
+
+ /**
+ * getConnection.
+ *
+ * @param user a {@link java.lang.String} object.
+ * @param context a {@link org.owasp.webgoat.session.WebgoatContext} object.
+ * @return a {@link java.sql.Connection} object.
+ * @throws java.sql.SQLException if any.
+ */
+ public static synchronized Connection getConnection(String user, WebgoatContext context) throws SQLException
+ {
+ Connection conn = connections.get(user);
+ if (conn != null && !conn.isClosed()) return conn;
+ conn = makeConnection(user, context);
+ connections.put(user, conn);
+
+ if (dbBuilt.get(user) == null)
+ {
+ new CreateDB().makeDB(conn);
+ dbBuilt.put(user, Boolean.TRUE);
+ }
+
+ return conn;
+ }
+
+ /**
+ * returnConnection.
+ *
+ * @param user a {@link java.lang.String} object.
+ */
+ public static synchronized void returnConnection(String user)
+ {
+ try
+ {
+ Connection connection = connections.get(user);
+ if (connection == null || connection.isClosed()) return;
+
+ if (connection.getMetaData().getDatabaseProductName().toLowerCase().contains("oracle")) connection.close();
+ } catch (SQLException sqle)
+ {
+ sqle.printStackTrace();
+ }
+ }
+
+ private static Connection makeConnection(String user, WebgoatContext context) throws SQLException
+ {
+ try
+ {
+ Class.forName(context.getDatabaseDriver());
+
+ if (context.getDatabaseConnectionString().contains("hsqldb")) return getHsqldbConnection(user, context);
+
+ String userPrefix = context.getDatabaseUser();
+ String password = context.getDatabasePassword();
+ String url = context.getDatabaseConnectionString();
+ return DriverManager.getConnection(url, userPrefix + "_" + user, password);
+ } catch (ClassNotFoundException cnfe)
+ {
+ cnfe.printStackTrace();
+ throw new SQLException("Couldn't load the database driver: " + cnfe.getLocalizedMessage());
+ }
+ }
+
+ private static Connection getHsqldbConnection(String user, WebgoatContext context) throws ClassNotFoundException,
+ SQLException
+ {
+ String url = context.getDatabaseConnectionString().replaceAll("\\$\\{USER\\}", user);
+ return DriverManager.getConnection(url, "sa", "");
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param results
+ * Description of the Parameter
+ * @param resultsMetaData
+ * Description of the Parameter
+ * @param resultsMetaData
+ * Description of the Parameter
+ * @return Description of the Return Value
+ * @exception IOException
+ * Description of the Exception
+ * @exception SQLException
+ * Description of the Exception
+ * @throws java.io.IOException if any.
+ * @throws java.sql.SQLException if any.
+ */
+ public static MultiPartElement writeTable(ResultSet results, ResultSetMetaData resultsMetaData) throws IOException,
+ SQLException
+ {
+ int numColumns = resultsMetaData.getColumnCount();
+ results.beforeFirst();
+
+ if (results.next())
+ {
+ Table t = new Table(1); // 1 = with border
+ t.setCellPadding(1);
+
+ TR tr = new TR();
+
+ for (int i = 1; i < (numColumns + 1); i++)
+ {
+ tr.addElement(new TD(new B(resultsMetaData.getColumnName(i))));
+ }
+
+ t.addElement(tr);
+ results.beforeFirst();
+
+ while (results.next())
+ {
+ TR row = new TR();
+
+ for (int i = 1; i < (numColumns + 1); i++)
+ {
+ String str = results.getString(i);
+ if (str == null) str = "";
+ row.addElement(new TD(str.replaceAll(" ", " ")));
+ }
+
+ t.addElement(row);
+ }
+
+ return (t);
+ }
+ else
+ {
+ return (new B("Query Successful; however no data was returned from this query."));
+ }
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/ECSFactory.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/ECSFactory.java
index f89167dbe..a08a63ac4 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/ECSFactory.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/ECSFactory.java
@@ -1,746 +1,740 @@
-
-package org.owasp.webgoat.session;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.Vector;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.A;
-import org.apache.ecs.html.BR;
-import org.apache.ecs.html.H3;
-import org.apache.ecs.html.Input;
-import org.apache.ecs.html.Label;
-import org.apache.ecs.html.Option;
-import org.apache.ecs.html.P;
-import org.apache.ecs.html.Select;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TH;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.U;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams (jeff.williams@aspectsecurity.com)
- * @created October 29, 2003
- */
-
-public class ECSFactory
-{
-
- /**
- * Description of the Field
- */
-
- public final static String ON = "On";
-
- /**
- * Description of the Field
- */
-
- public final static String PASSWORD = "Password";
-
- /**
- * Don't let anyone instantiate this class
- */
-
- private ECSFactory()
- {
- }
-
- /**
- * Description of the Method
- *
- * @param name
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Element makeBox(String name, String value)
- {
-
- Input i = new Input(Input.CHECKBOX, name, ON);
-
- i.setChecked(value.equals(ON));
-
- return (i);
- }
-
- /**
- * Description of the Method
- *
- * @param text
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Element makeButton(String text)
- {
-
- Input b = new Input();
-
- b.setType(Input.SUBMIT);
- b.setValue(text);
- b.setName(Input.SUBMIT);
-
- return (b);
- }
-
- public static Element makeButton(String text, String onClickFunction)
- {
-
- Input b = (Input) makeButton(text);
- b.setOnClick(onClickFunction);
-
- return (b);
- }
-
- /**
- * Description of the Method
- *
- * @param labeltext
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @param e
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static TR makeField(String labeltext, String value, Element e)
- {
-
- TD left = new TD().setAlign("right");
-
- Label label = new Label().addElement(labeltext);
-
- left.addElement(label);
-
- TD right = new TD().setAlign("left");
-
- right.addElement(e);
-
- TR row = new TR();
-
- row.addElement(left);
-
- row.addElement(right);
-
- return (row);
- }
-
- /**
- * Description of the Method
- *
- * @param labeltext
- * Description of the Parameter
- * @param name
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @param size
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static TR makeField(String labeltext, String name, String value, int size)
- {
-
- Input field = new Input().setName(name).setValue(value).setSize(size).setMaxlength(size);
-
- // double check in case someone means to make a * starred out password field
-
- if (name.equals(PASSWORD))
- {
-
- field.setType(Input.PASSWORD);
-
- }
-
- return (makeField(labeltext, value, field));
- }
-
- /**
- * Description of the Method
- *
- * @param label
- * Description of the Parameter
- * @param type
- * Description of the Parameter
- * @param name
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @param alignment
- * Description of the Parameter
- * @param selected
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Element makeInput(String label, String type, String name, boolean value, boolean selected,
- String alignment)
- {
-
- return makeInput(label, type, name, new Boolean(value).toString(), selected, alignment);
- }
-
- /**
- * Description of the Method
- *
- * @param label
- * Description of the Parameter
- * @param type
- * Description of the Parameter
- * @param name
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Element makeInput(String label, String type, String name, String value)
- {
-
- return makeInput(label, type, name, value, new Boolean(value).booleanValue(), "RIGHT");
- }
-
- /**
- * Description of the Method
- *
- * @param label
- * Description of the Parameter
- * @param type
- * Description of the Parameter
- * @param name
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @param alignment
- * Description of the Parameter
- * @param selected
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Element makeInput(String label, String type, String name, String value, boolean selected,
- String alignment)
- {
-
- ElementContainer ec = new ElementContainer();
-
- if (!alignment.equalsIgnoreCase("LEFT"))
- {
-
- ec.addElement(new StringElement(label));
-
- }
-
- Input input = new Input(type, name, value);
-
- ec.addElement(input);
-
- if (alignment.equalsIgnoreCase("LEFT"))
- {
-
- ec.addElement(new StringElement(label));
-
- }
-
- if (type.equalsIgnoreCase("CHECKBOX"))
- {
-
- input.setChecked(selected);
-
- }
-
- return (ec);
- }
-
- /**
- * Description of the Method
- *
- * @param text
- * Description of the Parameter
- * @param name
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static A makeLink(String text, String name, String value)
- {
-
- String href = "attack?" + name;
-
- if (value.length() > 0)
- {
-
- href = href + "=" + value;
-
- }
-
- A a = new A(href);
-
- a.addElement(new U().addElement(text));
-
- a.addAttribute("style", "cursor:hand");
-
- return (a);
- }
-
- /**
- * Description of the Method
- *
- * @param text
- * Description of the Parameter
- * @param name
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static A makeLink(String text, String name, int value)
- {
-
- return (makeLink(text, name, Integer.toString(value)));
- }
-
- /**
- * Description of the Method
- *
- * @param text
- * Description of the Parameter
- * @param name
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static A makeLink(String text, String name, boolean value)
- {
-
- return (makeLink(text, name, new Boolean(value).toString()));
- }
-
- /**
- * Description of the Method
- *
- * @param text
- * Description of the Parameter
- * @param clickAction
- * Description of the Parameter
- * @param type
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Input makeOnClickInput(String text, String clickAction, String type)
- {
-
- Input b = new Input();
-
- b.setType(type);
-
- b.setValue(text);
-
- b.setOnClick(clickAction);
-
- return (b);
- }
-
- /**
- * Description of the Method
- *
- * @param labeltext
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @param e
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static TR makeOption(String labeltext, String value, Element e)
- {
-
- TD left = new TD().setAlign("left").setWidth("10%");
-
- left.addElement(e);
-
- TD right = new TD().setAlign("right");
-
- Label label = new Label().addElement(labeltext);
-
- right.addElement(label);
-
- TR row = new TR();
-
- row.addElement(right);
-
- row.addElement(left);
-
- return (row);
- }
-
- /**
- * Description of the Method
- *
- * @param label
- * Description of the Parameter
- * @param value
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Option makeOption(String label, boolean value)
- {
-
- Option option = new Option(label, new Boolean(value).toString());
-
- option.setSelected(value);
-
- return option;
- }
-
- /**
- * Description of the Method
- *
- * @param line
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- private static org.apache.ecs.html.Option makeOption(String line)
- {
-
- StringTokenizer st = new StringTokenizer(line, "|");
-
- org.apache.ecs.html.Option o = new org.apache.ecs.html.Option();
-
- String token = "";
-
- if (st.hasMoreTokens())
- {
-
- token = st.nextToken();
-
- }
-
- o.addElement(token);
-
- return (o);
- }
-
- /**
- * Description of the Method
- *
- * @param name
- * Description of the Parameter
- * @param options
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Element makePulldown(String name, List options)
- {
-
- Select s = new Select(name);
-
- s.addElement(options.toArray(new String[options.size()]));
-
- return (s);
- }
-
- /**
- * Description of the Method
- *
- * @param results
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Element makePulldown(String name, String results)
- {
-
- Select select = new Select(name);
-
- StringTokenizer st = new StringTokenizer(results, "\n");
-
- if (!st.hasMoreTokens()) {
-
- return (new StringElement("")); }
-
- while (st.hasMoreTokens())
- {
-
- String line = st.nextToken();
-
- select.addElement(makeOption(line));
-
- }
-
- select.addElement("-------------------------");
-
- return (select);
- }
-
- /**
- * Description of the Method
- *
- * @param name
- * Description of the Parameter
- * @param list
- * Description of the Parameter
- * @param selected
- * Description of the Parameter
- * @param rowsShowing
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Select makePulldown(String name, Object[] list, String selected, int rowsShowing)
- {
-
- Select select = new Select(name);
-
- for (int loop = 0; loop < list.length; loop++)
- {
-
- String value = list[loop].toString();
-
- org.apache.ecs.html.Option o = new org.apache.ecs.html.Option(value, value, value);
-
- if (value.equals(selected))
- {
-
- o.setSelected(true);
-
- }
-
- select.addElement(o);
-
- }
-
- select.setSize(rowsShowing);
-
- return select;
- }
-
- /**
- * Default size of 1 for rows showing in select box.
- *
- * @param diffNames
- * Description of the Parameter
- * @param select
- * Description of the Parameter
- * @param name
- * Description of the Parameter
- * @param options
- * Description of the Parameter
- * @param list
- * Description of the Parameter
- * @param selected
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Element makeSelect(boolean diffNames, Select select, String name, Vector options,
- String[] list, String selected)
- {
-
- return makeSelect(diffNames, select, name, options, list, selected, 1);
- }
-
- /**
- * Description of the Method
- *
- * @param diffNames
- * Description of the Parameter
- * @param select
- * Description of the Parameter
- * @param name
- * Description of the Parameter
- * @param options
- * Description of the Parameter
- * @param list
- * Description of the Parameter
- * @param selected
- * Description of the Parameter
- * @param rowsShowing
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Select makeSelect(boolean diffNames, Select select, String name, Vector options,
- String[] list, String selected, int rowsShowing)
- {
-
- if (select == null)
- {
-
- select = new Select(name);
-
- if (diffNames)
- {
-
- for (int loop = 0; loop < list.length; loop += 2)
- {
-
- String value = list[loop];
-
- String label = list[loop + 1];
-
- Option o = new Option(value);
-
- if (loop == 0)
- {
-
- o.setSelected(true);
-
- }
-
- options.addElement(o);// add to Vector containing all options
-
- select.addElement(o);
-
- select.addElement(label);
-
- }
-
- }
-
- else
- {
-
- for (int loop = 0; loop < list.length; loop++)
- {
-
- String value = list[loop];
-
- org.apache.ecs.html.Option o = new org.apache.ecs.html.Option(value);
-
- if (loop == 0)
- {
-
- o.setSelected(true);
-
- }
-
- options.addElement(o);// add to Vector containing all options
-
- select.addElement(o);
-
- select.addElement(value);
-
- }
-
- }
-
- }
-
- // find selected option and set selected
-
- Iterator i = options.iterator();
-
- while (i.hasNext())
- {
-
- org.apache.ecs.html.Option o = (org.apache.ecs.html.Option) i.next();
-
- if (selected.equalsIgnoreCase(o.getAttribute("value")))
- {
-
- o.setSelected(true);
-
- }
-
- }
-
- select.setSize(rowsShowing);
-
- return (select);
- }
-
- /**
- * Description of the Method
- *
- * @param title
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static Element makeTallHeader(String title)
- {
- StringBuffer buff = new StringBuffer();
- for (int i = 0; i < title.length(); i++)
- {
- buff.append(title.charAt(i));
- buff.append(" ");
- }
- return new TH(buff.toString());
- }
-
- /**
- * Description of the Method
- *
- * @param title
- * Description of the Parameter
- * @param text
- * Description of the Parameter
- * @return Description of the Return Value
- */
-
- public static Element makeTextArea(String title, String text)
- {
-
- ElementContainer ec = new ElementContainer();
-
- ec.addElement(new BR());
-
- ec.addElement(new H3().addElement(title));
-
- ec.addElement(new P());
-
- ec.addElement(" ");
-
- ec.addElement(new BR());
-
- ec.addElement(new BR());
-
- return (ec);
- }
-
-}
+
+package org.owasp.webgoat.session;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.StringElement;
+import org.apache.ecs.html.A;
+import org.apache.ecs.html.BR;
+import org.apache.ecs.html.H3;
+import org.apache.ecs.html.Input;
+import org.apache.ecs.html.Label;
+import org.apache.ecs.html.Option;
+import org.apache.ecs.html.P;
+import org.apache.ecs.html.Select;
+import org.apache.ecs.html.TD;
+import org.apache.ecs.html.TH;
+import org.apache.ecs.html.TR;
+import org.apache.ecs.html.U;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams (jeff.williams@aspectsecurity.com)
+ * @since October 29, 2003
+ * @version $Id: $Id
+ */
+public class ECSFactory
+{
+
+ /**
+ * Description of the Field
+ */
+
+ public final static String ON = "On";
+
+ /**
+ * Description of the Field
+ */
+
+ public final static String PASSWORD = "Password";
+
+ /**
+ * Don't let anyone instantiate this class
+ */
+
+ private ECSFactory()
+ {
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param name
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element makeBox(String name, String value)
+ {
+
+ Input i = new Input(Input.CHECKBOX, name, ON);
+
+ i.setChecked(value.equals(ON));
+
+ return (i);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param text
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element makeButton(String text)
+ {
+
+ Input b = new Input();
+
+ b.setType(Input.SUBMIT);
+ b.setValue(text);
+ b.setName(Input.SUBMIT);
+
+ return (b);
+ }
+
+ /**
+ * makeButton.
+ *
+ * @param text a {@link java.lang.String} object.
+ * @param onClickFunction a {@link java.lang.String} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ */
+ public static Element makeButton(String text, String onClickFunction)
+ {
+
+ Input b = (Input) makeButton(text);
+ b.setOnClick(onClickFunction);
+
+ return (b);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param labeltext
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @param e
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static TR makeField(String labeltext, String value, Element e)
+ {
+
+ TD left = new TD().setAlign("right");
+
+ Label label = new Label().addElement(labeltext);
+
+ left.addElement(label);
+
+ TD right = new TD().setAlign("left");
+
+ right.addElement(e);
+
+ TR row = new TR();
+
+ row.addElement(left);
+
+ row.addElement(right);
+
+ return (row);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param labeltext
+ * Description of the Parameter
+ * @param name
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @param size
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static TR makeField(String labeltext, String name, String value, int size)
+ {
+
+ Input field = new Input().setName(name).setValue(value).setSize(size).setMaxlength(size);
+
+ // double check in case someone means to make a * starred out password field
+
+ if (name.equals(PASSWORD))
+ {
+
+ field.setType(Input.PASSWORD);
+
+ }
+
+ return (makeField(labeltext, value, field));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param label
+ * Description of the Parameter
+ * @param type
+ * Description of the Parameter
+ * @param name
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @param alignment
+ * Description of the Parameter
+ * @param selected
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element makeInput(String label, String type, String name, boolean value, boolean selected,
+ String alignment)
+ {
+
+ return makeInput(label, type, name, new Boolean(value).toString(), selected, alignment);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param label
+ * Description of the Parameter
+ * @param type
+ * Description of the Parameter
+ * @param name
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element makeInput(String label, String type, String name, String value)
+ {
+
+ return makeInput(label, type, name, value, new Boolean(value).booleanValue(), "RIGHT");
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param label
+ * Description of the Parameter
+ * @param type
+ * Description of the Parameter
+ * @param name
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @param alignment
+ * Description of the Parameter
+ * @param selected
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element makeInput(String label, String type, String name, String value, boolean selected,
+ String alignment)
+ {
+
+ ElementContainer ec = new ElementContainer();
+
+ if (!alignment.equalsIgnoreCase("LEFT"))
+ {
+
+ ec.addElement(new StringElement(label));
+
+ }
+
+ Input input = new Input(type, name, value);
+
+ ec.addElement(input);
+
+ if (alignment.equalsIgnoreCase("LEFT"))
+ {
+
+ ec.addElement(new StringElement(label));
+
+ }
+
+ if (type.equalsIgnoreCase("CHECKBOX"))
+ {
+
+ input.setChecked(selected);
+
+ }
+
+ return (ec);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param text
+ * Description of the Parameter
+ * @param name
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static A makeLink(String text, String name, String value)
+ {
+
+ String href = "attack?" + name;
+
+ if (value.length() > 0)
+ {
+
+ href = href + "=" + value;
+
+ }
+
+ A a = new A(href);
+
+ a.addElement(new U().addElement(text));
+
+ a.addAttribute("style", "cursor:hand");
+
+ return (a);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param text
+ * Description of the Parameter
+ * @param name
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static A makeLink(String text, String name, int value)
+ {
+
+ return (makeLink(text, name, Integer.toString(value)));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param text
+ * Description of the Parameter
+ * @param name
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static A makeLink(String text, String name, boolean value)
+ {
+
+ return (makeLink(text, name, new Boolean(value).toString()));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param text
+ * Description of the Parameter
+ * @param clickAction
+ * Description of the Parameter
+ * @param type
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Input makeOnClickInput(String text, String clickAction, String type)
+ {
+
+ Input b = new Input();
+
+ b.setType(type);
+
+ b.setValue(text);
+
+ b.setOnClick(clickAction);
+
+ return (b);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param labeltext
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @param e
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static TR makeOption(String labeltext, String value, Element e)
+ {
+
+ TD left = new TD().setAlign("left").setWidth("10%");
+
+ left.addElement(e);
+
+ TD right = new TD().setAlign("right");
+
+ Label label = new Label().addElement(labeltext);
+
+ right.addElement(label);
+
+ TR row = new TR();
+
+ row.addElement(right);
+
+ row.addElement(left);
+
+ return (row);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param label
+ * Description of the Parameter
+ * @param value
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Option makeOption(String label, boolean value)
+ {
+
+ Option option = new Option(label, new Boolean(value).toString());
+
+ option.setSelected(value);
+
+ return option;
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param line
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+
+ private static org.apache.ecs.html.Option makeOption(String line)
+ {
+
+ StringTokenizer st = new StringTokenizer(line, "|");
+
+ org.apache.ecs.html.Option o = new org.apache.ecs.html.Option();
+
+ String token = "";
+
+ if (st.hasMoreTokens())
+ {
+
+ token = st.nextToken();
+
+ }
+
+ o.addElement(token);
+
+ return (o);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param name
+ * Description of the Parameter
+ * @param options
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element makePulldown(String name, List options)
+ {
+
+ Select s = new Select(name);
+
+ s.addElement(options.toArray(new String[options.size()]));
+
+ return (s);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param results
+ * Description of the Parameter
+ * @return Description of the Return Value
+ * @param name a {@link java.lang.String} object.
+ */
+ public static Element makePulldown(String name, String results)
+ {
+
+ Select select = new Select(name);
+
+ StringTokenizer st = new StringTokenizer(results, "\n");
+
+ if (!st.hasMoreTokens()) {
+
+ return (new StringElement("")); }
+
+ while (st.hasMoreTokens())
+ {
+
+ String line = st.nextToken();
+
+ select.addElement(makeOption(line));
+
+ }
+
+ select.addElement("-------------------------");
+
+ return (select);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param name
+ * Description of the Parameter
+ * @param list
+ * Description of the Parameter
+ * @param selected
+ * Description of the Parameter
+ * @param rowsShowing
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Select makePulldown(String name, Object[] list, String selected, int rowsShowing)
+ {
+
+ Select select = new Select(name);
+
+ for (int loop = 0; loop < list.length; loop++)
+ {
+
+ String value = list[loop].toString();
+
+ org.apache.ecs.html.Option o = new org.apache.ecs.html.Option(value, value, value);
+
+ if (value.equals(selected))
+ {
+
+ o.setSelected(true);
+
+ }
+
+ select.addElement(o);
+
+ }
+
+ select.setSize(rowsShowing);
+
+ return select;
+ }
+
+ /**
+ * Default size of 1 for rows showing in select box.
+ *
+ * @param diffNames
+ * Description of the Parameter
+ * @param select
+ * Description of the Parameter
+ * @param selected
+ * Description of the Parameter
+ * @param name
+ * Description of the Parameter
+ * @param options
+ * Description of the Parameter
+ * @param list
+ * Description of the Parameter
+ * @param selected
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element makeSelect(boolean diffNames, Select select, String name, Vector options,
+ String[] list, String selected)
+ {
+
+ return makeSelect(diffNames, select, name, options, list, selected, 1);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param diffNames
+ * Description of the Parameter
+ * @param select
+ * Description of the Parameter
+ * @param selected
+ * Description of the Parameter
+ * @param name
+ * Description of the Parameter
+ * @param options
+ * Description of the Parameter
+ * @param list
+ * Description of the Parameter
+ * @param selected
+ * Description of the Parameter
+ * @param rowsShowing
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Select makeSelect(boolean diffNames, Select select, String name, Vector options,
+ String[] list, String selected, int rowsShowing)
+ {
+
+ if (select == null)
+ {
+
+ select = new Select(name);
+
+ if (diffNames)
+ {
+
+ for (int loop = 0; loop < list.length; loop += 2)
+ {
+
+ String value = list[loop];
+
+ String label = list[loop + 1];
+
+ Option o = new Option(value);
+
+ if (loop == 0)
+ {
+
+ o.setSelected(true);
+
+ }
+
+ options.addElement(o);// add to Vector containing all options
+
+ select.addElement(o);
+
+ select.addElement(label);
+
+ }
+
+ }
+
+ else
+ {
+
+ for (int loop = 0; loop < list.length; loop++)
+ {
+
+ String value = list[loop];
+
+ org.apache.ecs.html.Option o = new org.apache.ecs.html.Option(value);
+
+ if (loop == 0)
+ {
+
+ o.setSelected(true);
+
+ }
+
+ options.addElement(o);// add to Vector containing all options
+
+ select.addElement(o);
+
+ select.addElement(value);
+
+ }
+
+ }
+
+ }
+
+ // find selected option and set selected
+
+ Iterator i = options.iterator();
+
+ while (i.hasNext())
+ {
+
+ org.apache.ecs.html.Option o = (org.apache.ecs.html.Option) i.next();
+
+ if (selected.equalsIgnoreCase(o.getAttribute("value")))
+ {
+
+ o.setSelected(true);
+
+ }
+
+ }
+
+ select.setSize(rowsShowing);
+
+ return (select);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param title
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element makeTallHeader(String title)
+ {
+ StringBuffer buff = new StringBuffer();
+ for (int i = 0; i < title.length(); i++)
+ {
+ buff.append(title.charAt(i));
+ buff.append(" ");
+ }
+ return new TH(buff.toString());
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param title
+ * Description of the Parameter
+ * @param text
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element makeTextArea(String title, String text)
+ {
+
+ ElementContainer ec = new ElementContainer();
+
+ ec.addElement(new BR());
+
+ ec.addElement(new H3().addElement(title));
+
+ ec.addElement(new P());
+
+ ec.addElement(" ");
+
+ ec.addElement(new BR());
+
+ ec.addElement(new BR());
+
+ return (ec);
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/Employee.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/Employee.java
index 4b2c3561b..0581d3955 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/Employee.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/Employee.java
@@ -1,241 +1,405 @@
-
-package org.owasp.webgoat.session;
-
-import java.io.Serializable;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public class Employee implements Serializable
-{
-
- /**
- *
- */
- private static final long serialVersionUID = -1901957360367218399L;
-
- public final static String EMPLOYEE_ROLE = "employee";
-
- public final static String MANAGER_ROLE = "manager";
-
- public final static String HR_ROLE = "hr";
-
- private int id;
-
- private String firstName;
-
- private String lastName;
-
- private String title;
-
- private String ssn;
-
- private String phone;
-
- private String address1;
-
- private String address2;
-
- private int manager;
-
- private String startDate;
-
- private int salary;
-
- private String ccn;
-
- private int ccnLimit;
-
- private String disciplinaryActionDate;
-
- private String disciplinaryActionNotes;
-
- private String personalDescription;
-
- // FIXME: To be deleted
- public Employee()
- {
- }
-
- public Employee(int id, String firstName, String lastName, String ssn, String title, String phone, String address1,
- String address2, int manager, String startDate, int salary, String ccn, int ccnLimit,
- String disciplinaryActionDate, String disciplinaryActionNotes, String personalDescription)
- {
- this.id = id;
- this.firstName = firstName;
- this.lastName = lastName;
- this.ssn = ssn;
- this.title = title;
- this.phone = phone;
- this.address1 = address1;
- this.address2 = address2;
- this.manager = manager;
- this.startDate = startDate;
- this.salary = salary;
- this.ccn = ccn;
- this.ccnLimit = ccnLimit;
- this.disciplinaryActionDate = disciplinaryActionDate;
- this.disciplinaryActionNotes = disciplinaryActionNotes;
- this.personalDescription = personalDescription;
- }
-
- public String getAddress1()
- {
- return address1;
- }
-
- public void setAddress1(String address1)
- {
- this.address1 = address1;
- }
-
- public String getAddress2()
- {
- return address2;
- }
-
- public void setAddress2(String address2)
- {
- this.address2 = address2;
- }
-
- public String getCcn()
- {
- return ccn;
- }
-
- public void setCcn(String ccn)
- {
- this.ccn = ccn;
- }
-
- public int getCcnLimit()
- {
- return ccnLimit;
- }
-
- public void setCcnLimit(int ccnLimit)
- {
- this.ccnLimit = ccnLimit;
- }
-
- public String getFirstName()
- {
- return firstName;
- }
-
- public void setFirstName(String firstName)
- {
- this.firstName = firstName;
- }
-
- public String getLastName()
- {
- return lastName;
- }
-
- public void setLastName(String lastName)
- {
- this.lastName = lastName;
- }
-
- public String getPhoneNumber()
- {
- return phone;
- }
-
- public void setPhoneNumber(String phone)
- {
- this.phone = phone;
- }
-
- public int getSalary()
- {
- return salary;
- }
-
- public void setSalary(int salary)
- {
- this.salary = salary;
- }
-
- public String getSsn()
- {
- return ssn;
- }
-
- public void setSsn(String ssn)
- {
- this.ssn = ssn;
- }
-
- public String getStartDate()
- {
- return startDate;
- }
-
- public void setStartDate(String startDate)
- {
- this.startDate = startDate;
- }
-
- public int getId()
- {
- return id;
- }
-
- public void setId(int id)
- {
- this.id = id;
- }
-
- public String getTitle()
- {
- return this.title;
- }
-
- public int getManager()
- {
- return this.manager;
- }
-
- public String getDisciplinaryActionDate()
- {
- return this.disciplinaryActionDate;
- }
-
- public String getDisciplinaryActionNotes()
- {
- return this.disciplinaryActionNotes;
- }
-
- public String getPersonalDescription()
- {
- return this.personalDescription;
- }
-}
+
+package org.owasp.webgoat.session;
+
+import java.io.Serializable;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public class Employee implements Serializable
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1901957360367218399L;
+
+ /** Constant EMPLOYEE_ROLE="employee"
*/
+ public final static String EMPLOYEE_ROLE = "employee";
+
+ /** Constant MANAGER_ROLE="manager"
*/
+ public final static String MANAGER_ROLE = "manager";
+
+ /** Constant HR_ROLE="hr"
*/
+ public final static String HR_ROLE = "hr";
+
+ private int id;
+
+ private String firstName;
+
+ private String lastName;
+
+ private String title;
+
+ private String ssn;
+
+ private String phone;
+
+ private String address1;
+
+ private String address2;
+
+ private int manager;
+
+ private String startDate;
+
+ private int salary;
+
+ private String ccn;
+
+ private int ccnLimit;
+
+ private String disciplinaryActionDate;
+
+ private String disciplinaryActionNotes;
+
+ private String personalDescription;
+
+ // FIXME: To be deleted
+ /**
+ * Constructor for Employee.
+ */
+ public Employee()
+ {
+ }
+
+ /**
+ * Constructor for Employee.
+ *
+ * @param id a int.
+ * @param firstName a {@link java.lang.String} object.
+ * @param lastName a {@link java.lang.String} object.
+ * @param ssn a {@link java.lang.String} object.
+ * @param title a {@link java.lang.String} object.
+ * @param phone a {@link java.lang.String} object.
+ * @param address1 a {@link java.lang.String} object.
+ * @param address2 a {@link java.lang.String} object.
+ * @param manager a int.
+ * @param startDate a {@link java.lang.String} object.
+ * @param salary a int.
+ * @param ccn a {@link java.lang.String} object.
+ * @param ccnLimit a int.
+ * @param disciplinaryActionDate a {@link java.lang.String} object.
+ * @param disciplinaryActionNotes a {@link java.lang.String} object.
+ * @param personalDescription a {@link java.lang.String} object.
+ */
+ public Employee(int id, String firstName, String lastName, String ssn, String title, String phone, String address1,
+ String address2, int manager, String startDate, int salary, String ccn, int ccnLimit,
+ String disciplinaryActionDate, String disciplinaryActionNotes, String personalDescription)
+ {
+ this.id = id;
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.ssn = ssn;
+ this.title = title;
+ this.phone = phone;
+ this.address1 = address1;
+ this.address2 = address2;
+ this.manager = manager;
+ this.startDate = startDate;
+ this.salary = salary;
+ this.ccn = ccn;
+ this.ccnLimit = ccnLimit;
+ this.disciplinaryActionDate = disciplinaryActionDate;
+ this.disciplinaryActionNotes = disciplinaryActionNotes;
+ this.personalDescription = personalDescription;
+ }
+
+ /**
+ * Getter for the field address1
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getAddress1()
+ {
+ return address1;
+ }
+
+ /**
+ * Setter for the field address1
.
+ *
+ * @param address1 a {@link java.lang.String} object.
+ */
+ public void setAddress1(String address1)
+ {
+ this.address1 = address1;
+ }
+
+ /**
+ * Getter for the field address2
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getAddress2()
+ {
+ return address2;
+ }
+
+ /**
+ * Setter for the field address2
.
+ *
+ * @param address2 a {@link java.lang.String} object.
+ */
+ public void setAddress2(String address2)
+ {
+ this.address2 = address2;
+ }
+
+ /**
+ * Getter for the field ccn
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getCcn()
+ {
+ return ccn;
+ }
+
+ /**
+ * Setter for the field ccn
.
+ *
+ * @param ccn a {@link java.lang.String} object.
+ */
+ public void setCcn(String ccn)
+ {
+ this.ccn = ccn;
+ }
+
+ /**
+ * Getter for the field ccnLimit
.
+ *
+ * @return a int.
+ */
+ public int getCcnLimit()
+ {
+ return ccnLimit;
+ }
+
+ /**
+ * Setter for the field ccnLimit
.
+ *
+ * @param ccnLimit a int.
+ */
+ public void setCcnLimit(int ccnLimit)
+ {
+ this.ccnLimit = ccnLimit;
+ }
+
+ /**
+ * Getter for the field firstName
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getFirstName()
+ {
+ return firstName;
+ }
+
+ /**
+ * Setter for the field firstName
.
+ *
+ * @param firstName a {@link java.lang.String} object.
+ */
+ public void setFirstName(String firstName)
+ {
+ this.firstName = firstName;
+ }
+
+ /**
+ * Getter for the field lastName
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getLastName()
+ {
+ return lastName;
+ }
+
+ /**
+ * Setter for the field lastName
.
+ *
+ * @param lastName a {@link java.lang.String} object.
+ */
+ public void setLastName(String lastName)
+ {
+ this.lastName = lastName;
+ }
+
+ /**
+ * getPhoneNumber.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getPhoneNumber()
+ {
+ return phone;
+ }
+
+ /**
+ * setPhoneNumber.
+ *
+ * @param phone a {@link java.lang.String} object.
+ */
+ public void setPhoneNumber(String phone)
+ {
+ this.phone = phone;
+ }
+
+ /**
+ * Getter for the field salary
.
+ *
+ * @return a int.
+ */
+ public int getSalary()
+ {
+ return salary;
+ }
+
+ /**
+ * Setter for the field salary
.
+ *
+ * @param salary a int.
+ */
+ public void setSalary(int salary)
+ {
+ this.salary = salary;
+ }
+
+ /**
+ * Getter for the field ssn
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getSsn()
+ {
+ return ssn;
+ }
+
+ /**
+ * Setter for the field ssn
.
+ *
+ * @param ssn a {@link java.lang.String} object.
+ */
+ public void setSsn(String ssn)
+ {
+ this.ssn = ssn;
+ }
+
+ /**
+ * Getter for the field startDate
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getStartDate()
+ {
+ return startDate;
+ }
+
+ /**
+ * Setter for the field startDate
.
+ *
+ * @param startDate a {@link java.lang.String} object.
+ */
+ public void setStartDate(String startDate)
+ {
+ this.startDate = startDate;
+ }
+
+ /**
+ * Getter for the field id
.
+ *
+ * @return a int.
+ */
+ public int getId()
+ {
+ return id;
+ }
+
+ /**
+ * Setter for the field id
.
+ *
+ * @param id a int.
+ */
+ public void setId(int id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * Getter for the field title
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getTitle()
+ {
+ return this.title;
+ }
+
+ /**
+ * Getter for the field manager
.
+ *
+ * @return a int.
+ */
+ public int getManager()
+ {
+ return this.manager;
+ }
+
+ /**
+ * Getter for the field disciplinaryActionDate
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getDisciplinaryActionDate()
+ {
+ return this.disciplinaryActionDate;
+ }
+
+ /**
+ * Getter for the field disciplinaryActionNotes
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getDisciplinaryActionNotes()
+ {
+ return this.disciplinaryActionNotes;
+ }
+
+ /**
+ * Getter for the field personalDescription
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getPersonalDescription()
+ {
+ return this.personalDescription;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/EmployeeStub.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/EmployeeStub.java
index cb04a2a75..aa1dbae4a 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/EmployeeStub.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/EmployeeStub.java
@@ -1,82 +1,120 @@
-
-package org.owasp.webgoat.session;
-
-import java.io.Serializable;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public class EmployeeStub implements Serializable
-{
-
- /**
- *
- */
- private static final long serialVersionUID = -7109162877797765632L;
-
- private int id;
-
- private String firstName;
-
- private String lastName;
-
- private String role;
-
- public EmployeeStub(int id, String firstName, String lastName)
- {
- this(id, firstName, lastName, Employee.EMPLOYEE_ROLE);
- }
-
- public EmployeeStub(int id, String firstName, String lastName, String role)
- {
- this.id = id;
- this.firstName = firstName;
- this.lastName = lastName;
- this.role = role;
- }
-
- public String getFirstName()
- {
- return firstName;
- }
-
- public int getId()
- {
- return id;
- }
-
- public String getLastName()
- {
- return lastName;
- }
-
- public String getRole()
- {
- return role;
- }
-}
+
+package org.owasp.webgoat.session;
+
+import java.io.Serializable;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public class EmployeeStub implements Serializable
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7109162877797765632L;
+
+ private int id;
+
+ private String firstName;
+
+ private String lastName;
+
+ private String role;
+
+ /**
+ * Constructor for EmployeeStub.
+ *
+ * @param id a int.
+ * @param firstName a {@link java.lang.String} object.
+ * @param lastName a {@link java.lang.String} object.
+ */
+ public EmployeeStub(int id, String firstName, String lastName)
+ {
+ this(id, firstName, lastName, Employee.EMPLOYEE_ROLE);
+ }
+
+ /**
+ * Constructor for EmployeeStub.
+ *
+ * @param id a int.
+ * @param firstName a {@link java.lang.String} object.
+ * @param lastName a {@link java.lang.String} object.
+ * @param role a {@link java.lang.String} object.
+ */
+ public EmployeeStub(int id, String firstName, String lastName, String role)
+ {
+ this.id = id;
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.role = role;
+ }
+
+ /**
+ * Getter for the field firstName
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getFirstName()
+ {
+ return firstName;
+ }
+
+ /**
+ * Getter for the field id
.
+ *
+ * @return a int.
+ */
+ public int getId()
+ {
+ return id;
+ }
+
+ /**
+ * Getter for the field lastName
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getLastName()
+ {
+ return lastName;
+ }
+
+ /**
+ * Getter for the field role
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getRole()
+ {
+ return role;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/ErrorScreen.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/ErrorScreen.java
index 687e72b6b..8949113aa 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/ErrorScreen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/ErrorScreen.java
@@ -1,264 +1,285 @@
-
-package org.owasp.webgoat.session;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintWriter;
-import java.util.StringTokenizer;
-import javax.servlet.ServletException;
-import org.owasp.webgoat.lessons.AbstractLesson;
-import org.apache.ecs.Element;
-import org.apache.ecs.ElementContainer;
-import org.apache.ecs.HtmlColor;
-import org.apache.ecs.StringElement;
-import org.apache.ecs.html.Div;
-import org.apache.ecs.html.Form;
-import org.apache.ecs.html.H2;
-import org.apache.ecs.html.Small;
-import org.apache.ecs.html.TD;
-import org.apache.ecs.html.TR;
-import org.apache.ecs.html.Table;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- * @created November 4, 2003
- */
-public class ErrorScreen extends Screen
-{
- /**
- * Description of the Field
- */
- protected Throwable error;
-
- /**
- * Description of the Field
- */
- protected String message;
-
- /**
- * Constructor for the ErrorScreen object
- *
- * @param s
- * Description of the Parameter
- * @param t
- * Description of the Parameter
- */
- public ErrorScreen(WebSession s, Throwable t)
- {
- this.error = t;
- fixCurrentScreen(s);
- setup(s);
- }
-
- /**
- * Constructor for the ErrorScreen object
- *
- * @param s
- * Description of the Parameter
- * @param msg
- * Description of the Parameter
- */
- public ErrorScreen(WebSession s, String msg)
- {
- this.message = msg;
- fixCurrentScreen(s);
- setup(s);
- }
-
- public void fixCurrentScreen(WebSession s)
- {
- // So the user can't get stuck on the error screen, reset the
- // current screen to something known
- if (s != null)
- {
- try
- {
- s.setCurrentScreen(s.getCourse().getFirstLesson().getScreenId());
- } catch (Throwable t)
- {
- s.setCurrentScreen(WebSession.WELCOME);
- }
- }
- }
-
- public void setup(WebSession s)
- {
- // call createContent first so messages will go somewhere
-
- Form form = new Form("attack", Form.POST).setName("form").setEncType("");
-
- form.addElement(wrapForm(s));
-
- TD lowerright = new TD().setHeight("100%").setVAlign("top").setAlign("left").addElement(form);
- TR row = new TR().addElement(lowerright);
- Table layout = new Table().setBgColor(HtmlColor.WHITE).setCellSpacing(0).setCellPadding(0).setBorder(0);
-
- layout.addElement(row);
-
- setContent(layout);
- }
-
- protected Element wrapForm(WebSession s)
- {
- if (s == null) { return new StringElement("Invalid Session"); }
-
- Table container = new Table().setWidth("100%").setCellSpacing(10).setCellPadding(0).setBorder(0);
-
- // CreateContent can generate error messages so you MUST call it before makeMessages()
- Element content = createContent(s);
- container.addElement(new TR().addElement(new TD().setColSpan(2).setVAlign("TOP").addElement(makeMessages(s))));
- container.addElement(new TR().addElement(new TD().setColSpan(2).addElement(content)));
- container.addElement(new TR());
-
- return (container);
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(WebSession s)
- {
- System.out.println("errorscreen createContent Error:" + this.error + " message:" + this.message);
-
- Element content;
-
- if (this.error != null)
- {
- content = createContent(this.error);
- }
- else if (this.message != null)
- {
- content = createContent(this.message);
- }
- else
- {
- content = new StringElement("An unknown error occurred.");
- }
-
- return content;
- }
-
- /**
- * Description of the Method
- *
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(String s)
- {
- StringElement list = new StringElement(s);
-
- return (list);
- }
-
- /**
- * Description of the Method
- *
- * @param t
- * Description of the Parameter
- * @return Description of the Return Value
- */
- protected Element createContent(Throwable t)
- {
- StringElement list = new StringElement();
- list.addElement(new H2().addElement(new StringElement("Error Message: " + t.getMessage())));
- list.addElement(formatStackTrace(t));
-
- if (t instanceof ServletException)
- {
- Throwable root = ((ServletException) t).getRootCause();
-
- if (root != null)
- {
- list.addElement(new H2().addElement(new StringElement("Root Message: " + root.getMessage())));
- list.addElement(formatStackTrace(root));
- }
- }
-
- return (new Small().addElement(list));
- }
-
- /**
- * Description of the Method
- *
- * @param t
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static Element formatStackTrace(Throwable t)
- {
- String trace = getStackTrace(t);
- StringElement list = new StringElement();
- StringTokenizer st = new StringTokenizer(trace, "\r\n\t");
-
- while (st.hasMoreTokens())
- {
- String line = st.nextToken();
- list.addElement(new Div(line));
- }
-
- return (list);
- }
-
- /**
- * Gets the stackTrace attribute of the ErrorScreen class
- *
- * @param t
- * Description of the Parameter
- * @return The stackTrace value
- */
- public static String getStackTrace(Throwable t)
- {
- ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- PrintWriter writer = new PrintWriter(bytes, true);
- t.printStackTrace(writer);
-
- return (bytes.toString());
- }
-
- /**
- * Gets the title attribute of the ErrorScreen object
- *
- * @return The title value
- */
- public String getTitle()
- {
- return ("Error");
- }
-
- public String getRole()
- {
- return AbstractLesson.USER_ROLE;
- }
-}
+
+package org.owasp.webgoat.session;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.util.StringTokenizer;
+import javax.servlet.ServletException;
+import org.owasp.webgoat.lessons.AbstractLesson;
+import org.apache.ecs.Element;
+import org.apache.ecs.ElementContainer;
+import org.apache.ecs.HtmlColor;
+import org.apache.ecs.StringElement;
+import org.apache.ecs.html.Div;
+import org.apache.ecs.html.Form;
+import org.apache.ecs.html.H2;
+import org.apache.ecs.html.Small;
+import org.apache.ecs.html.TD;
+import org.apache.ecs.html.TR;
+import org.apache.ecs.html.Table;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @since November 4, 2003
+ * @version $Id: $Id
+ */
+public class ErrorScreen extends Screen
+{
+ /**
+ * Description of the Field
+ */
+ protected Throwable error;
+
+ /**
+ * Description of the Field
+ */
+ protected String message;
+
+ /**
+ * Constructor for the ErrorScreen object
+ *
+ * @param s
+ * Description of the Parameter
+ * @param t
+ * Description of the Parameter
+ */
+ public ErrorScreen(WebSession s, Throwable t)
+ {
+ this.error = t;
+ fixCurrentScreen(s);
+ setup(s);
+ }
+
+ /**
+ * Constructor for the ErrorScreen object
+ *
+ * @param s
+ * Description of the Parameter
+ * @param msg
+ * Description of the Parameter
+ */
+ public ErrorScreen(WebSession s, String msg)
+ {
+ this.message = msg;
+ fixCurrentScreen(s);
+ setup(s);
+ }
+
+ /**
+ * fixCurrentScreen.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ */
+ public void fixCurrentScreen(WebSession s)
+ {
+ // So the user can't get stuck on the error screen, reset the
+ // current screen to something known
+ if (s != null)
+ {
+ try
+ {
+ s.setCurrentScreen(s.getCourse().getFirstLesson().getScreenId());
+ } catch (Throwable t)
+ {
+ s.setCurrentScreen(WebSession.WELCOME);
+ }
+ }
+ }
+
+ /**
+ * setup.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ */
+ public void setup(WebSession s)
+ {
+ // call createContent first so messages will go somewhere
+
+ Form form = new Form("attack", Form.POST).setName("form").setEncType("");
+
+ form.addElement(wrapForm(s));
+
+ TD lowerright = new TD().setHeight("100%").setVAlign("top").setAlign("left").addElement(form);
+ TR row = new TR().addElement(lowerright);
+ Table layout = new Table().setBgColor(HtmlColor.WHITE).setCellSpacing(0).setCellPadding(0).setBorder(0);
+
+ layout.addElement(row);
+
+ setContent(layout);
+ }
+
+ /**
+ * wrapForm.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link org.apache.ecs.Element} object.
+ */
+ protected Element wrapForm(WebSession s)
+ {
+ if (s == null) { return new StringElement("Invalid Session"); }
+
+ Table container = new Table().setWidth("100%").setCellSpacing(10).setCellPadding(0).setBorder(0);
+
+ // CreateContent can generate error messages so you MUST call it before makeMessages()
+ Element content = createContent(s);
+ container.addElement(new TR().addElement(new TD().setColSpan(2).setVAlign("TOP").addElement(makeMessages(s))));
+ container.addElement(new TR().addElement(new TD().setColSpan(2).addElement(content)));
+ container.addElement(new TR());
+
+ return (container);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Description of the Method
+ */
+ protected Element createContent(WebSession s)
+ {
+ System.out.println("errorscreen createContent Error:" + this.error + " message:" + this.message);
+
+ Element content;
+
+ if (this.error != null)
+ {
+ content = createContent(this.error);
+ }
+ else if (this.message != null)
+ {
+ content = createContent(this.message);
+ }
+ else
+ {
+ content = new StringElement("An unknown error occurred.");
+ }
+
+ return content;
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ protected Element createContent(String s)
+ {
+ StringElement list = new StringElement(s);
+
+ return (list);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param t
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ protected Element createContent(Throwable t)
+ {
+ StringElement list = new StringElement();
+ list.addElement(new H2().addElement(new StringElement("Error Message: " + t.getMessage())));
+ list.addElement(formatStackTrace(t));
+
+ if (t instanceof ServletException)
+ {
+ Throwable root = ((ServletException) t).getRootCause();
+
+ if (root != null)
+ {
+ list.addElement(new H2().addElement(new StringElement("Root Message: " + root.getMessage())));
+ list.addElement(formatStackTrace(root));
+ }
+ }
+
+ return (new Small().addElement(list));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param t
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static Element formatStackTrace(Throwable t)
+ {
+ String trace = getStackTrace(t);
+ StringElement list = new StringElement();
+ StringTokenizer st = new StringTokenizer(trace, "\r\n\t");
+
+ while (st.hasMoreTokens())
+ {
+ String line = st.nextToken();
+ list.addElement(new Div(line));
+ }
+
+ return (list);
+ }
+
+ /**
+ * Gets the stackTrace attribute of the ErrorScreen class
+ *
+ * @param t
+ * Description of the Parameter
+ * @return The stackTrace value
+ */
+ public static String getStackTrace(Throwable t)
+ {
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ PrintWriter writer = new PrintWriter(bytes, true);
+ t.printStackTrace(writer);
+
+ return (bytes.toString());
+ }
+
+ /**
+ * Gets the title attribute of the ErrorScreen object
+ *
+ * @return The title value
+ */
+ public String getTitle()
+ {
+ return ("Error");
+ }
+
+ /**
+ * getRole.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getRole()
+ {
+ return AbstractLesson.USER_ROLE;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/LessonSession.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/LessonSession.java
index af1694f46..179b62442 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/LessonSession.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/LessonSession.java
@@ -1,63 +1,85 @@
-
-package org.owasp.webgoat.session;
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * Represents a virtual session for a lesson. Lesson-specific session data may be stored here.
- *
- * @author David Anderson Aspect Security
- * @created January 19, 2006
- */
-public class LessonSession
-{
-
- private boolean isAuthenticated = false;
-
- private String currentLessonScreen;
-
- public void setAuthenticated(boolean isAuthenticated)
- {
- this.isAuthenticated = isAuthenticated;
- }
-
- public boolean isAuthenticated()
- {
- return this.isAuthenticated;
- }
-
- public void setCurrentLessonScreen(String currentLessonScreen)
- {
- this.currentLessonScreen = currentLessonScreen;
- }
-
- public String getCurrentLessonScreen()
- {
- return this.currentLessonScreen;
- }
-
-}
+
+package org.owasp.webgoat.session;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * Represents a virtual session for a lesson. Lesson-specific session data may be stored here.
+ *
+ * @author David Anderson Aspect Security
+ * @since January 19, 2006
+ * @version $Id: $Id
+ */
+public class LessonSession
+{
+
+ private boolean isAuthenticated = false;
+
+ private String currentLessonScreen;
+
+ /**
+ * setAuthenticated.
+ *
+ * @param isAuthenticated a boolean.
+ */
+ public void setAuthenticated(boolean isAuthenticated)
+ {
+ this.isAuthenticated = isAuthenticated;
+ }
+
+ /**
+ * isAuthenticated.
+ *
+ * @return a boolean.
+ */
+ public boolean isAuthenticated()
+ {
+ return this.isAuthenticated;
+ }
+
+ /**
+ * Setter for the field currentLessonScreen
.
+ *
+ * @param currentLessonScreen a {@link java.lang.String} object.
+ */
+ public void setCurrentLessonScreen(String currentLessonScreen)
+ {
+ this.currentLessonScreen = currentLessonScreen;
+ }
+
+ /**
+ * Getter for the field currentLessonScreen
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getCurrentLessonScreen()
+ {
+ return this.currentLessonScreen;
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/LessonTracker.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/LessonTracker.java
index e936cc773..daa78f5ad 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/LessonTracker.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/LessonTracker.java
@@ -1,404 +1,427 @@
-
-package org.owasp.webgoat.session;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.util.Properties;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce Mayhew WebGoat
- * @created October 29, 2003
- */
-public class LessonTracker
-{
-
- private boolean completed = false;
-
- private int maxHintLevel = 0;
-
- private int numVisits = 0;
-
- private boolean viewedCookies = false;
-
- private boolean viewedHtml = false;
-
- private boolean viewedLessonPlan = false;
-
- private boolean viewedParameters = false;
-
- private boolean viewedSource = false;
-
- private boolean viewedSolution = false;
-
- Properties lessonProperties = new Properties();
-
- /**
- * Gets the completed attribute of the LessonTracker object
- *
- * @return The completed value
- */
- public boolean getCompleted()
- {
- return completed;
- }
-
- /**
- * Gets the maxHintLevel attribute of the LessonTracker object
- *
- * @return The maxHintLevel value
- */
- public int getMaxHintLevel()
- {
- return maxHintLevel;
- }
-
- /**
- * Gets the numVisits attribute of the LessonTracker object
- *
- * @return The numVisits value
- */
- public int getNumVisits()
- {
- return numVisits;
- }
-
- /**
- * Gets the viewedCookies attribute of the LessonTracker object
- *
- * @return The viewedCookies value
- */
- public boolean getViewedCookies()
- {
- return viewedCookies;
- }
-
- /**
- * Gets the viewedHtml attribute of the LessonTracker object
- *
- * @return The viewedHtml value
- */
- public boolean getViewedHtml()
- {
- return viewedHtml;
- }
-
- /**
- * Gets the viewedLessonPlan attribute of the LessonTracker object
- *
- * @return The viewedLessonPlan value
- */
- public boolean getViewedLessonPlan()
- {
- return viewedLessonPlan;
- }
-
- /**
- * Gets the viewedParameters attribute of the LessonTracker object
- *
- * @return The viewedParameters value
- */
- public boolean getViewedParameters()
- {
- return viewedParameters;
- }
-
- /**
- * Gets the viewedSource attribute of the LessonTracker object
- *
- * @return The viewedSource value
- */
- public boolean getViewedSource()
- {
- return viewedSource;
- }
-
- public boolean getViewedSolution()
- {
- return viewedSource;
- }
-
- /**
- * Description of the Method
- */
- public void incrementNumVisits()
- {
- numVisits++;
- }
-
- /**
- * Sets the properties attribute of the LessonTracker object
- *
- * @param props
- * The new properties value
- */
- protected void setProperties(Properties props, Screen screen)
- {
- completed = Boolean.valueOf(props.getProperty(screen.getTitle() + ".completed")).booleanValue();
- maxHintLevel = Integer.parseInt(props.getProperty(screen.getTitle() + ".maxHintLevel", "0"));
- numVisits = Integer.parseInt(props.getProperty(screen.getTitle() + ".numVisits", "0"));
- viewedCookies = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedCookies", "false")).booleanValue();
- viewedHtml = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedHtml", "false")).booleanValue();
- viewedLessonPlan = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedLessonPlan", "false")).booleanValue();
- viewedParameters = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedParameters", "false")).booleanValue();
- viewedSource = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedSource", "false")).booleanValue();
- }
-
- public static String getUserDir(WebSession s)
- {
- return s.getContext().getRealPath("users") + "/";
- }
-
- private static String getTrackerFile(WebSession s, String user, Screen screen)
- {
- return getUserDir(s) + user + "." + screen.getClass().getName() + ".props";
- }
-
- /**
- * Description of the Method
- *
- * @param screen
- * Description of the Parameter
- * @param s
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static LessonTracker load(WebSession s, String user, Screen screen)
- {
- FileInputStream in = null;
- try
- {
- String fileName = getTrackerFile(s, user, screen);
- if (fileName != null)
- {
- Properties tempProps = new Properties();
- // System.out.println("Loading lesson state from: " + fileName);
- in = new FileInputStream(fileName);
- tempProps.load(in);
- // allow the screen to use any custom properties it may have set
- LessonTracker tempLessonTracker = screen.createLessonTracker(tempProps);
- tempLessonTracker.setProperties(tempProps, screen);
- return tempLessonTracker;
- }
- } catch (FileNotFoundException e)
- {
- // Normal if the lesson has not been accessed yet.
- } catch (Exception e)
- {
- System.out.println("Failed to load lesson state for " + screen);
- e.printStackTrace();
- } finally
- {
- try
- {
- in.close();
- } catch (Exception e)
- {
- }
- }
-
- return screen.createLessonTracker();
- }
-
- /**
- * Sets the completed attribute of the LessonTracker object
- *
- * @param completed
- * The new completed value
- */
- public void setCompleted(boolean completed)
- {
- this.completed = completed;
- }
-
- /**
- * Sets the maxHintLevel attribute of the LessonTracker object
- *
- * @param maxHintLevel
- * The new maxHintLevel value
- */
- public void setMaxHintLevel(int maxHintLevel)
- {
- this.maxHintLevel = Math.max(this.maxHintLevel, maxHintLevel);
- }
-
- /**
- * Sets the viewedCookies attribute of the LessonTracker object
- *
- * @param viewedCookies
- * The new viewedCookies value
- */
- public void setViewedCookies(boolean viewedCookies)
- {
- this.viewedCookies = viewedCookies;
- }
-
- /**
- * Sets the viewedHtml attribute of the LessonTracker object
- *
- * @param viewedHtml
- * The new viewedHtml value
- */
- public void setViewedHtml(boolean viewedHtml)
- {
- this.viewedHtml = viewedHtml;
- }
-
- /**
- * Sets the viewedLessonPlan attribute of the LessonTracker object
- *
- * @param viewedLessonPlan
- * The new viewedLessonPlan value
- */
- public void setViewedLessonPlan(boolean viewedLessonPlan)
- {
- this.viewedLessonPlan = viewedLessonPlan;
- }
-
- /**
- * Sets the viewedParameters attribute of the LessonTracker object
- *
- * @param viewedParameters
- * The new viewedParameters value
- */
- public void setViewedParameters(boolean viewedParameters)
- {
- this.viewedParameters = viewedParameters;
- }
-
- /**
- * Sets the viewedSource attribute of the LessonTracker object
- *
- * @param viewedSource
- * The new viewedSource value
- */
- public void setViewedSource(boolean viewedSource)
- {
- this.viewedSource = viewedSource;
- }
-
- /**
- * Sets the viewedSource attribute of the LessonTracker object
- *
- * @param viewedSource
- * The new viewedSource value
- */
- public void setViewedSolution(boolean viewedSolution)
- {
- this.viewedSolution = viewedSolution;
- }
-
- /**
- * Allows the storing of properties for the logged in and a screen.
- *
- * @param s
- * Description of the Parameter
- */
- public void store(WebSession s, Screen screen)
- {
- store(s, screen, s.getUserName());
- }
-
- /**
- * Allows the storing of properties for a user and a screen.
- *
- * @param s
- * Description of the Parameter
- */
- public void store(WebSession s, Screen screen, String user)
- {
- FileOutputStream out = null;
- String fileName = getTrackerFile(s, user, screen);
- // System.out.println( "Storing data to" + fileName );
- lessonProperties.setProperty(screen.getTitle() + ".completed", Boolean.toString(completed));
- lessonProperties.setProperty(screen.getTitle() + ".maxHintLevel", Integer.toString(maxHintLevel));
- lessonProperties.setProperty(screen.getTitle() + ".numVisits", Integer.toString(numVisits));
- lessonProperties.setProperty(screen.getTitle() + ".viewedCookies", Boolean.toString(viewedCookies));
- lessonProperties.setProperty(screen.getTitle() + ".viewedHtml", Boolean.toString(viewedHtml));
- lessonProperties.setProperty(screen.getTitle() + ".viewedLessonPlan", Boolean.toString(viewedLessonPlan));
- lessonProperties.setProperty(screen.getTitle() + ".viewedParameters", Boolean.toString(viewedParameters));
- lessonProperties.setProperty(screen.getTitle() + ".viewedSource", Boolean.toString(viewedSource));
- try
- {
- out = new FileOutputStream(fileName);
- lessonProperties.store(out, s.getUserName());
- } catch (Exception e)
- {
- // what do we want to do, I think nothing.
- System.out.println("Warning User data for " + s.getUserName() + " will not persist");
- } finally
- {
- try
- {
- out.close();
- } catch (Exception e)
- {
- }
- }
-
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- public String toString()
- {
- StringBuffer buff = new StringBuffer();
- buff.append("LessonTracker:" + "\n");
- buff.append(" - completed:.......... " + completed + "\n");
- buff.append(" - maxHintLevel:....... " + maxHintLevel + "\n");
- buff.append(" - numVisits:.......... " + numVisits + "\n");
- buff.append(" - viewedCookies:...... " + viewedCookies + "\n");
- buff.append(" - viewedHtml:......... " + viewedHtml + "\n");
- buff.append(" - viewedLessonPlan:... " + viewedLessonPlan + "\n");
- buff.append(" - viewedParameters:... " + viewedParameters + "\n");
- buff.append(" - viewedSource:....... " + viewedSource + "\n" + "\n");
- return buff.toString();
- }
-
- /**
- * @return Returns the lessonProperties.
- */
- public Properties getLessonProperties()
- {
- return lessonProperties;
- }
-
- /**
- * @param lessonProperties
- * The lessonProperties to set.
- */
- public void setLessonProperties(Properties lessonProperties)
- {
- this.lessonProperties = lessonProperties;
- }
-}
+
+package org.owasp.webgoat.session;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.util.Properties;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce Mayhew WebGoat
+ * @since October 29, 2003
+ * @version $Id: $Id
+ */
+public class LessonTracker
+{
+
+ private boolean completed = false;
+
+ private int maxHintLevel = 0;
+
+ private int numVisits = 0;
+
+ private boolean viewedCookies = false;
+
+ private boolean viewedHtml = false;
+
+ private boolean viewedLessonPlan = false;
+
+ private boolean viewedParameters = false;
+
+ private boolean viewedSource = false;
+
+ private boolean viewedSolution = false;
+
+ Properties lessonProperties = new Properties();
+
+ /**
+ * Gets the completed attribute of the LessonTracker object
+ *
+ * @return The completed value
+ */
+ public boolean getCompleted()
+ {
+ return completed;
+ }
+
+ /**
+ * Gets the maxHintLevel attribute of the LessonTracker object
+ *
+ * @return The maxHintLevel value
+ */
+ public int getMaxHintLevel()
+ {
+ return maxHintLevel;
+ }
+
+ /**
+ * Gets the numVisits attribute of the LessonTracker object
+ *
+ * @return The numVisits value
+ */
+ public int getNumVisits()
+ {
+ return numVisits;
+ }
+
+ /**
+ * Gets the viewedCookies attribute of the LessonTracker object
+ *
+ * @return The viewedCookies value
+ */
+ public boolean getViewedCookies()
+ {
+ return viewedCookies;
+ }
+
+ /**
+ * Gets the viewedHtml attribute of the LessonTracker object
+ *
+ * @return The viewedHtml value
+ */
+ public boolean getViewedHtml()
+ {
+ return viewedHtml;
+ }
+
+ /**
+ * Gets the viewedLessonPlan attribute of the LessonTracker object
+ *
+ * @return The viewedLessonPlan value
+ */
+ public boolean getViewedLessonPlan()
+ {
+ return viewedLessonPlan;
+ }
+
+ /**
+ * Gets the viewedParameters attribute of the LessonTracker object
+ *
+ * @return The viewedParameters value
+ */
+ public boolean getViewedParameters()
+ {
+ return viewedParameters;
+ }
+
+ /**
+ * Gets the viewedSource attribute of the LessonTracker object
+ *
+ * @return The viewedSource value
+ */
+ public boolean getViewedSource()
+ {
+ return viewedSource;
+ }
+
+ /**
+ * Getter for the field viewedSolution
.
+ *
+ * @return a boolean.
+ */
+ public boolean getViewedSolution()
+ {
+ return viewedSource;
+ }
+
+ /**
+ * Description of the Method
+ */
+ public void incrementNumVisits()
+ {
+ numVisits++;
+ }
+
+ /**
+ * Sets the properties attribute of the LessonTracker object
+ *
+ * @param props
+ * The new properties value
+ * @param screen a {@link org.owasp.webgoat.session.Screen} object.
+ */
+ protected void setProperties(Properties props, Screen screen)
+ {
+ completed = Boolean.valueOf(props.getProperty(screen.getTitle() + ".completed")).booleanValue();
+ maxHintLevel = Integer.parseInt(props.getProperty(screen.getTitle() + ".maxHintLevel", "0"));
+ numVisits = Integer.parseInt(props.getProperty(screen.getTitle() + ".numVisits", "0"));
+ viewedCookies = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedCookies", "false")).booleanValue();
+ viewedHtml = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedHtml", "false")).booleanValue();
+ viewedLessonPlan = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedLessonPlan", "false")).booleanValue();
+ viewedParameters = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedParameters", "false")).booleanValue();
+ viewedSource = Boolean.valueOf(props.getProperty(screen.getTitle() + ".viewedSource", "false")).booleanValue();
+ }
+
+ /**
+ * getUserDir.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public static String getUserDir(WebSession s)
+ {
+ return s.getContext().getRealPath("users") + "/";
+ }
+
+ private static String getTrackerFile(WebSession s, String user, Screen screen)
+ {
+ return getUserDir(s) + user + "." + screen.getClass().getName() + ".props";
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param screen
+ * Description of the Parameter
+ * @param screen
+ * Description of the Parameter
+ * @param s
+ * Description of the Parameter
+ * @return Description of the Return Value
+ * @param user a {@link java.lang.String} object.
+ */
+ public static LessonTracker load(WebSession s, String user, Screen screen)
+ {
+ FileInputStream in = null;
+ try
+ {
+ String fileName = getTrackerFile(s, user, screen);
+ if (fileName != null)
+ {
+ Properties tempProps = new Properties();
+ // System.out.println("Loading lesson state from: " + fileName);
+ in = new FileInputStream(fileName);
+ tempProps.load(in);
+ // allow the screen to use any custom properties it may have set
+ LessonTracker tempLessonTracker = screen.createLessonTracker(tempProps);
+ tempLessonTracker.setProperties(tempProps, screen);
+ return tempLessonTracker;
+ }
+ } catch (FileNotFoundException e)
+ {
+ // Normal if the lesson has not been accessed yet.
+ } catch (Exception e)
+ {
+ System.out.println("Failed to load lesson state for " + screen);
+ e.printStackTrace();
+ } finally
+ {
+ try
+ {
+ in.close();
+ } catch (Exception e)
+ {
+ }
+ }
+
+ return screen.createLessonTracker();
+ }
+
+ /**
+ * Sets the completed attribute of the LessonTracker object
+ *
+ * @param completed
+ * The new completed value
+ */
+ public void setCompleted(boolean completed)
+ {
+ this.completed = completed;
+ }
+
+ /**
+ * Sets the maxHintLevel attribute of the LessonTracker object
+ *
+ * @param maxHintLevel
+ * The new maxHintLevel value
+ */
+ public void setMaxHintLevel(int maxHintLevel)
+ {
+ this.maxHintLevel = Math.max(this.maxHintLevel, maxHintLevel);
+ }
+
+ /**
+ * Sets the viewedCookies attribute of the LessonTracker object
+ *
+ * @param viewedCookies
+ * The new viewedCookies value
+ */
+ public void setViewedCookies(boolean viewedCookies)
+ {
+ this.viewedCookies = viewedCookies;
+ }
+
+ /**
+ * Sets the viewedHtml attribute of the LessonTracker object
+ *
+ * @param viewedHtml
+ * The new viewedHtml value
+ */
+ public void setViewedHtml(boolean viewedHtml)
+ {
+ this.viewedHtml = viewedHtml;
+ }
+
+ /**
+ * Sets the viewedLessonPlan attribute of the LessonTracker object
+ *
+ * @param viewedLessonPlan
+ * The new viewedLessonPlan value
+ */
+ public void setViewedLessonPlan(boolean viewedLessonPlan)
+ {
+ this.viewedLessonPlan = viewedLessonPlan;
+ }
+
+ /**
+ * Sets the viewedParameters attribute of the LessonTracker object
+ *
+ * @param viewedParameters
+ * The new viewedParameters value
+ */
+ public void setViewedParameters(boolean viewedParameters)
+ {
+ this.viewedParameters = viewedParameters;
+ }
+
+ /**
+ * Sets the viewedSource attribute of the LessonTracker object
+ *
+ * @param viewedSource
+ * The new viewedSource value
+ */
+ public void setViewedSource(boolean viewedSource)
+ {
+ this.viewedSource = viewedSource;
+ }
+
+ /**
+ * Sets the viewedSource attribute of the LessonTracker object
+ *
+ * @param viewedSolution a boolean.
+ */
+ public void setViewedSolution(boolean viewedSolution)
+ {
+ this.viewedSolution = viewedSolution;
+ }
+
+ /**
+ * Allows the storing of properties for the logged in and a screen.
+ *
+ * @param s
+ * Description of the Parameter
+ * @param screen a {@link org.owasp.webgoat.session.Screen} object.
+ */
+ public void store(WebSession s, Screen screen)
+ {
+ store(s, screen, s.getUserName());
+ }
+
+ /**
+ * Allows the storing of properties for a user and a screen.
+ *
+ * @param s
+ * Description of the Parameter
+ * @param screen a {@link org.owasp.webgoat.session.Screen} object.
+ * @param user a {@link java.lang.String} object.
+ */
+ public void store(WebSession s, Screen screen, String user)
+ {
+ FileOutputStream out = null;
+ String fileName = getTrackerFile(s, user, screen);
+ // System.out.println( "Storing data to" + fileName );
+ lessonProperties.setProperty(screen.getTitle() + ".completed", Boolean.toString(completed));
+ lessonProperties.setProperty(screen.getTitle() + ".maxHintLevel", Integer.toString(maxHintLevel));
+ lessonProperties.setProperty(screen.getTitle() + ".numVisits", Integer.toString(numVisits));
+ lessonProperties.setProperty(screen.getTitle() + ".viewedCookies", Boolean.toString(viewedCookies));
+ lessonProperties.setProperty(screen.getTitle() + ".viewedHtml", Boolean.toString(viewedHtml));
+ lessonProperties.setProperty(screen.getTitle() + ".viewedLessonPlan", Boolean.toString(viewedLessonPlan));
+ lessonProperties.setProperty(screen.getTitle() + ".viewedParameters", Boolean.toString(viewedParameters));
+ lessonProperties.setProperty(screen.getTitle() + ".viewedSource", Boolean.toString(viewedSource));
+ try
+ {
+ out = new FileOutputStream(fileName);
+ lessonProperties.store(out, s.getUserName());
+ } catch (Exception e)
+ {
+ // what do we want to do, I think nothing.
+ System.out.println("Warning User data for " + s.getUserName() + " will not persist");
+ } finally
+ {
+ try
+ {
+ out.close();
+ } catch (Exception e)
+ {
+ }
+ }
+
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ public String toString()
+ {
+ StringBuffer buff = new StringBuffer();
+ buff.append("LessonTracker:" + "\n");
+ buff.append(" - completed:.......... " + completed + "\n");
+ buff.append(" - maxHintLevel:....... " + maxHintLevel + "\n");
+ buff.append(" - numVisits:.......... " + numVisits + "\n");
+ buff.append(" - viewedCookies:...... " + viewedCookies + "\n");
+ buff.append(" - viewedHtml:......... " + viewedHtml + "\n");
+ buff.append(" - viewedLessonPlan:... " + viewedLessonPlan + "\n");
+ buff.append(" - viewedParameters:... " + viewedParameters + "\n");
+ buff.append(" - viewedSource:....... " + viewedSource + "\n" + "\n");
+ return buff.toString();
+ }
+
+ /**
+ * Getter for the field lessonProperties
.
+ *
+ * @return Returns the lessonProperties.
+ */
+ public Properties getLessonProperties()
+ {
+ return lessonProperties;
+ }
+
+ /**
+ * Setter for the field lessonProperties
.
+ *
+ * @param lessonProperties
+ * The lessonProperties to set.
+ */
+ public void setLessonProperties(Properties lessonProperties)
+ {
+ this.lessonProperties = lessonProperties;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/Parameter.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/Parameter.java
index bc77e0a18..f1321b298 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/Parameter.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/Parameter.java
@@ -1,81 +1,112 @@
-
-package org.owasp.webgoat.session;
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public class Parameter implements Comparable
-{
-
- String name;
-
- String value;
-
- public Parameter(String name, String value)
- {
- this.name = name;
- this.value = value;
- }
-
- public String getName()
- {
- return name;
- }
-
- public String getValue()
- {
- return value;
- }
-
- // @Override
- public boolean equals(Object obj)
- {
- if (obj instanceof Parameter)
- {
- Parameter other = (Parameter) obj;
- return (name.equals(other.getName()) && value.equals(other.getValue()));
- }
- return false;
- }
-
- // @Override
- public int hashCode()
- {
- return toString().hashCode();
- }
-
- // @Override
- public String toString()
- {
- return (name + "=" + value);
- }
-
- public int compareTo(Object o)
- {
- return toString().compareTo(o.toString());
- }
-}
+
+package org.owasp.webgoat.session;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public class Parameter implements Comparable
+{
+
+ String name;
+
+ String value;
+
+ /**
+ * Constructor for Parameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @param value a {@link java.lang.String} object.
+ */
+ public Parameter(String name, String value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ /**
+ * Getter for the field name
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Getter for the field value
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getValue()
+ {
+ return value;
+ }
+
+ // @Override
+ /** {@inheritDoc} */
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof Parameter)
+ {
+ Parameter other = (Parameter) obj;
+ return (name.equals(other.getName()) && value.equals(other.getValue()));
+ }
+ return false;
+ }
+
+ // @Override
+ /**
+ * hashCode.
+ *
+ * @return a int.
+ */
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
+ // @Override
+ /**
+ * toString.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String toString()
+ {
+ return (name + "=" + value);
+ }
+
+ /** {@inheritDoc} */
+ public int compareTo(Object o)
+ {
+ return toString().compareTo(o.toString());
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/ParameterNotFoundException.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/ParameterNotFoundException.java
index f2cfb028f..456f8b6a6 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/ParameterNotFoundException.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/ParameterNotFoundException.java
@@ -1,59 +1,61 @@
-
-package org.owasp.webgoat.session;
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- */
-public class ParameterNotFoundException extends Exception
-{
-
- /**
- *
- */
- private static final long serialVersionUID = 3286112913299408382L;
-
- /**
- * Constructs a new ParameterNotFoundException with no detail message.
- */
- public ParameterNotFoundException()
- {
- super();
- }
-
- /**
- * Constructs a new ParameterNotFoundException with the specified detail message.
- *
- * @param s
- * the detail message
- */
- public ParameterNotFoundException(String s)
- {
- super(s);
- }
-}
+
+package org.owasp.webgoat.session;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @version $Id: $Id
+ */
+public class ParameterNotFoundException extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3286112913299408382L;
+
+ /**
+ * Constructs a new ParameterNotFoundException with no detail message.
+ */
+ public ParameterNotFoundException()
+ {
+ super();
+ }
+
+ /**
+ * Constructs a new ParameterNotFoundException with the specified detail message.
+ *
+ * @param s
+ * the detail message
+ */
+ public ParameterNotFoundException(String s)
+ {
+ super(s);
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/ParameterParser.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/ParameterParser.java
index 7c62de643..bca462024 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/ParameterParser.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/ParameterParser.java
@@ -1,872 +1,1012 @@
-package org.owasp.webgoat.session;
-
-import java.util.Enumeration;
-import java.util.StringTokenizer;
-import java.util.Vector;
-import java.util.regex.Pattern;
-import javax.servlet.ServletRequest;
-import org.owasp.webgoat.util.HtmlEncoder;
-
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect
- * Security
- */
-public class ParameterParser {
-
- private final static String ALLOWED_CHARACTERS = "_$()-?.@!,:;=//+"; // Don't
- // allow
- // #&
- // specifically
-
- private ServletRequest request;
-
- /**
- * Constructs a new ParameterParser to handle the parameters of the given
- * request.
- *
- * @param request the servlet request
- */
- public ParameterParser(ServletRequest request) {
- this.request = request;
- }
-
- /**
- * Description of the Method
- *
- * @param s Description of the Parameter
- * @return Description of the Return Value
- */
- private String clean(String s) {
- StringBuffer clean = new StringBuffer();
-
- for (int loop = 0; loop < s.length(); loop++) {
- char c = s.charAt(loop);
-
- if (Character.isLetterOrDigit(c) || Character.isWhitespace(c) || (ALLOWED_CHARACTERS.indexOf(c) != -1)) {
- clean.append(c);
- } else {
- clean.append('.');
- }
- }
-
- return (clean.toString());
- }
-
- /**
- * Gets the named parameter value as a boolean
- *
- * @param name the parameter name
- * @return the parameter value as a boolean
- * @exception ParameterNotFoundException if the parameter was not found
- */
- public boolean getBooleanParameter(String name) throws ParameterNotFoundException {
- return new Boolean(getStringParameter(name)).booleanValue();
- }
-
- /**
- * Gets the named parameter value as a boolean, with a default. Returns the
- * default value if the parameter is not found.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a boolean, or the default
- */
- public boolean getBooleanParameter(String name, boolean def) {
- try {
- return getBooleanParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the booleanSubParameter attribute of the ParameterParser object
- *
- * @param first Description of the Parameter
- * @param next Description of the Parameter
- * @param def Description of the Parameter
- * @return The booleanSubParameter value
- */
- public boolean getBooleanSubParameter(String first, String next, boolean def) {
- try {
- return new Boolean(getSubParameter(first, next)).booleanValue();
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the named parameter value as a byte
- *
- * @param name the parameter name
- * @return the parameter value as a byte
- * @exception ParameterNotFoundException if the parameter was not found
- * @exception NumberFormatException if the parameter value could not be
- * converted to a byte
- */
- public byte getByteParameter(String name) throws ParameterNotFoundException, NumberFormatException {
- return Byte.parseByte(getStringParameter(name));
- }
-
- /**
- * Gets the named parameter value as a byte, with a default. Returns the
- * default value if the parameter is not found or cannot be converted to a
- * byte.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a byte, or the default
- */
- public byte getByteParameter(String name, byte def) {
- try {
- return getByteParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the named parameter value as a char
- *
- * @param name the parameter name
- * @return the parameter value as a char
- * @exception ParameterNotFoundException if the parameter was not found or
- * was the empty string
- */
- public char getCharParameter(String name) throws ParameterNotFoundException {
- String param = getStringParameter(name);
-
- if (param.length() == 0) {
- throw new ParameterNotFoundException(name + " is empty string");
- } else {
- return (param.charAt(0));
- }
- }
-
- /**
- * Gets the named parameter value as a char, with a default. Returns the
- * default value if the parameter is not found.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a char, or the default
- */
- public char getCharParameter(String name, char def) {
- try {
- return getCharParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the classNameParameter attribute of the ParameterParser object
- *
- * @param name Description of the Parameter
- * @return The classNameParameter value
- */
- public String getClassNameParameter(String name) throws ParameterNotFoundException {
- String p = getStringParameter(name);
- StringTokenizer st = new StringTokenizer(p);
-
- return (st.nextToken().trim());
- }
-
- // FIXME: check for [a-zA-Z].([a-zA-Z])*
- /**
- * Gets the classNameParameter attribute of the ParameterParser object
- *
- * @param name Description of the Parameter
- * @param def Description of the Parameter
- * @return The classNameParameter value
- */
- public String getClassNameParameter(String name, String def) {
- try {
- return getClassNameParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the named parameter value as a double
- *
- * @param name the parameter name
- * @return the parameter value as a double
- * @exception ParameterNotFoundException if the parameter was not found
- * @exception NumberFormatException if the parameter could not be converted
- * to a double
- */
- public double getDoubleParameter(String name) throws ParameterNotFoundException, NumberFormatException {
- return new Double(getStringParameter(name)).doubleValue();
- }
-
- /**
- * Gets the named parameter value as a double, with a default. Returns the
- * default value if the parameter is not found.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a double, or the default
- */
- public double getDoubleParameter(String name, double def) {
- try {
- return getDoubleParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the named parameter value as a float
- *
- * @param name the parameter name
- * @return the parameter value as a float
- * @exception ParameterNotFoundException if the parameter was not found
- * @exception NumberFormatException if the parameter could not be converted
- * to a float
- */
- public float getFloatParameter(String name) throws ParameterNotFoundException, NumberFormatException {
- return new Float(getStringParameter(name)).floatValue();
- }
-
- /**
- * Gets the named parameter value as a float, with a default. Returns the
- * default value if the parameter is not found.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a float, or the default
- */
- public float getFloatParameter(String name, float def) {
- try {
- return getFloatParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the named parameter value as an IP String, with a default. Returns
- * the default value if the parameter is not found or is the empty string.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a String, or the default
- */
- public String getIPParameter(String name, String def) {
- try {
- return getIPParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the named parameter value as an IP String
- *
- * @param name the parameter name
- * @return the parameter value as a valid IP String or an Empty string if
- * invalid
- * @exception ParameterNotFoundException if the parameter was not found or
- * was the empty string
- */
- public String getIPParameter(String name) throws ParameterNotFoundException {
- boolean valid = true;
- String[] values = request.getParameterValues(name);
- String value;
-
- if (values == null) {
- throw new ParameterNotFoundException(name + " not found");
- } else if (values[0].length() == 0) {
- throw new ParameterNotFoundException(name + " was empty");
- } else {
- // trim illegal characters
- value = clean(values[0].trim());
-
- if (value.indexOf("&") > 0) {
- // truncate additional parameters that follow &
- value = value.substring(0, value.indexOf("&"));
- }
-
- // validate the IP ex: 124.143.12.254
- int startIndex = 0;
- int endIndex = 0;
- int octetCount = 0;
- int octetValue;
- String octet;
-
- // if no .'s then it's not an IP
- if (value.indexOf(".") >= 0) {
- while ((valid == true) && (octetCount < 4)) {
- endIndex = value.indexOf(".", startIndex);
-
- if (endIndex == -1) {
- endIndex = value.length();
- }
-
- octet = value.substring(startIndex, endIndex);
- startIndex = endIndex + 1;
-
- try {
- octetValue = Integer.parseInt(octet);
-
- if ((octetValue <= 0) || (octetValue >= 256)) {
- valid = false;
- }
- } catch (Exception e) {
- valid = false;
- }
-
- octetCount++;
- }
- } else {
- // Not a valid IP
- valid = false;
- }
-
- // Check for any extra garbage. If the last octet was a large value
- // it would be trapped by the above range check.
- if (value.length() != endIndex) {
- valid = false;
- }
-
- return valid ? value : null;
- }
- }
-
- /**
- * Gets the named parameter value as a int
- *
- * @param name the parameter name
- * @return the parameter value as a int
- * @exception ParameterNotFoundException if the parameter was not found
- * @exception NumberFormatException if the parameter could not be converted
- * to a int
- */
- public int getIntParameter(String name) throws ParameterNotFoundException, NumberFormatException {
- return Integer.parseInt(getStringParameter(name));
- }
-
- /**
- * Gets the named parameter value as a int, with a default. Returns the
- * default value if the parameter is not found.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a int, or the default
- */
- public int getIntParameter(String name, int def) {
- try {
- return getIntParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the named parameter value as a long
- *
- * @param name the parameter name
- * @return the parameter value as a long
- * @exception ParameterNotFoundException if the parameter was not found
- * @exception NumberFormatException if the parameter could not be converted
- * to a long
- */
- public long getLongParameter(String name) throws ParameterNotFoundException, NumberFormatException {
- return Long.parseLong(getStringParameter(name));
- }
-
- /**
- * Gets the named parameter value as a long, with a default. Returns the
- * default value if the parameter is not found.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a long, or the default
- */
- public long getLongParameter(String name, long def) {
- try {
- return getLongParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Determines which of the required parameters were missing from the
- * request. Returns null if all the parameters are present.
- *
- * @param requestuired Description of the Parameter
- * @return an array of missing parameters, or null if none are missing
- */
- public String[] getMissingParameters(String[] requestuired) {
- Vector missing = new Vector();
-
- for (int i = 0; i < requestuired.length; i++) {
- String val = getStringParameter(requestuired[i], null);
-
- if (val == null) {
- missing.addElement(requestuired[i]);
- }
- }
-
- if (missing.size() == 0) {
- return null;
- } else {
- String[] ret = new String[missing.size()];
- missing.copyInto(ret);
-
- return ret;
- }
- }
-
- /**
- * Gets the parameterNames attribute of the ParameterParser object
- *
- * @return The parameterNames value
- */
- public Enumeration getParameterNames() {
- if (request == null) {
- return (null);
- }
-
- return request.getParameterNames();
- }
-
- /**
- * Gets the parameterValues attribute of the ParameterParser object
- *
- * @param name Description of the Parameter
- * @return The parameterValues value
- */
- public String[] getParameterValues(String name) {
- if (request == null) {
- return (null);
- }
-
- return request.getParameterValues(name);
- }
-
- /**
- * Gets the rawParameter attribute of the ParameterParser object
- *
- * @param name Description of the Parameter
- * @param def Description of the Parameter
- * @return The rawParameter value
- */
- public String getRawParameter(String name, String def) {
- try {
- return getRawParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the rawParameter attribute of the ParameterParser object
- *
- * @param name Description of the Parameter
- * @return The rawParameter value
- * @exception ParameterNotFoundException Description of the Exception
- */
- public String getRawParameter(String name) throws ParameterNotFoundException {
- String[] values = request.getParameterValues(name);
-
- if (values == null) {
- throw new ParameterNotFoundException(name + " not found");
- } else if (values[0].length() == 0) {
- throw new ParameterNotFoundException(name + " was empty");
- }
-
- return (values[0]);
- }
-
- /**
- * Gets the named parameter value as a short
- *
- * @param name the parameter name
- * @return the parameter value as a short
- * @exception ParameterNotFoundException if the parameter was not found
- * @exception NumberFormatException if the parameter could not be converted
- * to a short
- */
- public short getShortParameter(String name) throws ParameterNotFoundException, NumberFormatException {
- return Short.parseShort(getStringParameter(name));
- }
-
- /**
- * Gets the named parameter value as a short, with a default. Returns the
- * default value if the parameter is not found.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a short, or the default
- */
- public short getShortParameter(String name, short def) {
- try {
- return getShortParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the named parameter value as a String
- *
- * @param name the parameter name
- * @return the parameter value as a String
- * @exception ParameterNotFoundException if the parameter was not found or
- * was the empty string
- */
- public String getStringParameter(String name) throws ParameterNotFoundException {
- String[] values = request.getParameterValues(name);
- String value;
-
- if (values == null) {
- throw new ParameterNotFoundException(name + " not found");
- } else if (values[0].length() == 0) {
- throw new ParameterNotFoundException(name + " was empty");
- } else {
- // trim illegal characters
- value = clean(values[0].trim());
-
- if (value.indexOf("&") > 0) {
- // truncate additional parameters that follow &
- value = value.substring(0, value.indexOf("&"));
- }
-
- return value;
- }
- }
-
- /**
- * Gets the named parameter value as a String, with a default. Returns the
- * default value if the parameter is not found or is the empty string.
- *
- * @param name the parameter name
- * @param def the default parameter value
- * @return the parameter value as a String, or the default
- */
- public String getStringParameter(String name, String def) {
- try {
- return getStringParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the subParameter attribute of the ParameterParser object
- *
- * @param first Description of the Parameter
- * @param next Description of the Parameter
- * @param def Description of the Parameter
- * @return The subParameter value
- */
- public String getSubParameter(String first, String next, String def) {
- try {
- return getSubParameter(first, next);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the parameter named 'next' following the parameter 'first'. Presumes
- * the structure: first=firstvalue&next=nextValue
- *
- * @param first Description of the Parameter
- * @param next Description of the Parameter
- * @return The subParameter value
- * @exception ParameterNotFoundException Description of the Exception
- */
- public String getSubParameter(String first, String next) throws ParameterNotFoundException {
- String[] values = request.getParameterValues(first);
- String value;
-
- if (values == null) {
- throw new ParameterNotFoundException(first + " not found");
- } else if (values[0].length() == 0) {
- throw new ParameterNotFoundException(first + " was empty");
- } else {
- value = clean(values[0].trim());
-
- int idx = value.indexOf("&") + 1;
-
- // index of first char of first sub-param name
- if (idx == 0) {
- throw new ParameterNotFoundException("No subparameter key");
- }
-
- value = value.substring(idx);
-
- // System.out.println("= = = = = =Parameter parser looking for " +
- // next + " in " + value );
- int nextValueIndex = value.indexOf(next + "=");
-
- // System.out.println("= = = = = =Parameter parser nextValueIndex =
- // " + nextValueIndex );
- if (nextValueIndex < 0) {
- throw new ParameterNotFoundException("No subparameter value");
- }
-
- nextValueIndex += (next.length() + 1);
-
- if (nextValueIndex >= 0) {
- value = value.substring(nextValueIndex);
- } else {
- throw new ParameterNotFoundException(next + " not found");
- }
- }
-
- if (value.indexOf("&") > 0) {
- // truncate additional parameters that follow &
- value = value.substring(0, value.indexOf("&"));
- }
-
- // System.out.println("=-=-=-=-=ParameterParser returning value " +
- // value );
- return value;
- }
-
- /**
- * Gets the wordParameter attribute of the ParameterParser object
- *
- * @param name Description of the Parameter
- * @return The wordParameter value
- */
- public String getWordParameter(String name) throws ParameterNotFoundException {
- String p = getStringParameter(name);
- StringTokenizer st = new StringTokenizer(p);
-
- return (st.nextToken().trim());
- }
-
- // FIXME: check for [a-zA-Z]
- /**
- * Gets the wordParameter attribute of the ParameterParser object
- *
- * @param name Description of the Parameter
- * @param def Description of the Parameter
- * @return The wordParameter value
- */
- public String getWordParameter(String name, String def) {
- try {
- return getWordParameter(name);
- } catch (Exception e) {
- return def;
- }
- }
-
- /**
- * Gets the specified parameter from the request and validates it against
- * the provided regular expression. If the regular expression check fails,
- * the default value is returned instead.
- *
- * @param name The name of the parameter to retrieve from the request.
- * @param def The default value of the parameter.
- * @param regexpattern The precompiled regular expression to be used to
- * validate the parameter.
- * @return The validated parameter value, or the default value if validation
- * failed.
- */
- private String getRegexParameter(String name, String def, Pattern regexpattern) throws ValidationException {
- try {
- return getRegexParameter(name, regexpattern);
- } catch (Exception e) {
- // System.out.println("Exception occured in defined pattern match");
- // e.printStackTrace();
- return def;
- }
- }
-
- /**
- * Gets the specified parameter from the request and validates it against
- * the provided regular expression. If the regular expression check fails,
- * the default value is returned instead.
- *
- * @param name The name of the parameter to retrieve from the request.
- * @param def The default value of the parameter.
- * @param regexpattern The precompiled regular expression to be used to
- * validate the parameter.
- * @return The validated parameter value, or the default value if validation
- * failed.
- */
- private String getRegexParameter(String name, Pattern regexpattern) throws ParameterNotFoundException,
- ValidationException {
- String param = getStringParameter(name);
-
- if (regexpattern.matcher(param).matches()) {
- return param;
- } else {
- // System.out.println(param + " didn't match defined pattern.");
- throw new ValidationException(name + " contained an invalid value");
- }
- }
-
- public String getStrictAlphaParameter(String name, int maxLength) throws ParameterNotFoundException,
- ValidationException {
- String alphaRegEx = "^[a-zA-Z\\s]{0," + maxLength + "}$";
- Pattern alphaPattern = Pattern.compile(alphaRegEx);
-
- return getRegexParameter(name, alphaPattern);
- }
-
- public String getStrictNumericParameter(String name, int maxLength) throws ParameterNotFoundException,
- ValidationException {
- String numericRegEx = "^\\d{0," + maxLength + "}$";
- Pattern numericPattern = Pattern.compile(numericRegEx);
-
- return getRegexParameter(name, numericPattern);
- }
-
- private static final String SSNREGEX = "^\\d{3}-\\d{2}-\\d{4}$";
-
- private static final Pattern Ssnpattern = Pattern.compile(SSNREGEX);
-
- public String getSsnParameter(String name) throws ParameterNotFoundException, ValidationException {
- return getRegexParameter(name, Ssnpattern);
- }
-
- // Validates format for major brands of credit card.
- // private static final String CCNREGEX =
- // "^(?:(?4\\d{3})|(?5[1-5]\\d{2})|(?6011)|(?(?:3[68]\\d{2})|(?:30[0-5]\\d))|(?3[47]\\d{2}))([
- //-]?)(?(DinersClub)(?:\\d{6}\\1\\d{4})|(?(AmericanExpress)(?:\\d{6}\\1\\d{5})|(?:\\d{4}\\1\\d{4
- // }\\1\\d{4})))$";
- private static final String CCNREGEX = "^\\d{16}$";
-
- private static final Pattern Ccnpattern = Pattern.compile(CCNREGEX);
-
- public String getCcnParameter(String name) throws ParameterNotFoundException, ValidationException {
- return getRegexParameter(name, Ccnpattern);
- }
-
- private static final String ZIPREGEX = "^\\d{5}(-\\d{4})?$";
-
- private static final Pattern Zippattern = Pattern.compile(ZIPREGEX);
-
- public String getZipParameter(String name) throws ParameterNotFoundException, ValidationException {
- return getZipParameter(name, null);
- }
-
- public String getZipParameter(String name, String def) throws ValidationException {
- return getRegexParameter(name, def, Zippattern);
- }
-
- private static final String PHONEREGEX = "^\\(?[\\d]{3}\\)?[\\s-]?[\\d]{3}[\\s-]?[\\d]{4}$";
-
- // Or this more forgiving pattern:
- // private static final String PHONEREGEX = "^([\\-()+ 0-9x])+$";
- private static final Pattern phonepattern = Pattern.compile(PHONEREGEX);
-
- public String getPhoneParameter(String name) throws ParameterNotFoundException, ValidationException {
- return getPhoneParameter(name, null);
- }
-
- public String getPhoneParameter(String name, String def) throws ValidationException {
- return getRegexParameter(name, def, phonepattern);
- }
-
- private static final String EMAILREGEX = "^[\\w-]+(?:\\.[\\w-]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7}$";
-
- private static final Pattern emailpattern = Pattern.compile(EMAILREGEX);
-
- public String getEMailParameter(String name) throws ParameterNotFoundException, ValidationException {
- return getEMailParameter(name, null);
- }
-
- public String getEMailParameter(String name, String def) throws ValidationException {
- return getRegexParameter(name, def, emailpattern);
- }
-
- private static final String DATEREGEX = "([\\/ .,:0-9a-zA-Z])+$";
-
- private static final Pattern datepattern = Pattern.compile(DATEREGEX);
-
- public String getDateParameter(String name) throws ParameterNotFoundException, ValidationException {
- return getDateParameter(name, null);
- }
-
- public String getDateParameter(String name, String def) throws ValidationException {
- return getRegexParameter(name, def, datepattern);
- }
-
- private static final String URLREGEX = "^(((https?)://)([-()_.!~*';/?:@&=+$,A-Za-z0-9])+)([).!';/?:,][[:blank:]])?$";
-
- private static final Pattern URLpattern = Pattern.compile(URLREGEX);
-
- public String getURLParameter(String name) throws ParameterNotFoundException, ValidationException {
- return getURLParameter(name, null);
- }
-
- public String getURLParameter(String name, String def) throws ValidationException {
- return getRegexParameter(name, def, URLpattern);
- }
-
- protected static String htmlEncode(String s) {
- return HtmlEncoder.encode(s);
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- public String toString() {
- StringBuffer s = new StringBuffer("[");
- Enumeration e = getParameterNames();
-
- while (e.hasMoreElements()) {
- String key = (String) e.nextElement();
- s.append(key + "=" + getParameterValues(key)[0]);
-
- // FIXME: Other values?
- if (e.hasMoreElements()) {
- s.append(",");
- }
- }
-
- s.append("]");
-
- return (s.toString());
- }
-
- /**
- * Description of the Method
- *
- * @param request Description of the Parameter
- */
- public void update(ServletRequest request) {
- this.request = request;
- }
-}
+package org.owasp.webgoat.session;
+
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import java.util.regex.Pattern;
+import javax.servlet.ServletRequest;
+import org.owasp.webgoat.util.HtmlEncoder;
+
+/**
+ * *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project
+ * utility. For details, please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
+ * for free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @version $Id: $Id
+ */
+public class ParameterParser {
+
+ private final static String ALLOWED_CHARACTERS = "_$()-?.@!,:;=//+"; // Don't
+ // allow
+ // #&
+ // specifically
+
+ private ServletRequest request;
+
+ /**
+ * Constructs a new ParameterParser to handle the parameters of the given
+ * request.
+ *
+ * @param request the servlet request
+ */
+ public ParameterParser(ServletRequest request) {
+ this.request = request;
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param s Description of the Parameter
+ * @return Description of the Return Value
+ */
+ private String clean(String s) {
+ StringBuffer clean = new StringBuffer();
+
+ for (int loop = 0; loop < s.length(); loop++) {
+ char c = s.charAt(loop);
+
+ if (Character.isLetterOrDigit(c) || Character.isWhitespace(c) || (ALLOWED_CHARACTERS.indexOf(c) != -1)) {
+ clean.append(c);
+ } else {
+ clean.append('.');
+ }
+ }
+
+ return (clean.toString());
+ }
+
+ /**
+ * Gets the named parameter value as a boolean
+ *
+ * @param name the parameter name
+ * @return the parameter value as a boolean
+ * @exception ParameterNotFoundException if the parameter was not found
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public boolean getBooleanParameter(String name) throws ParameterNotFoundException {
+ return new Boolean(getStringParameter(name)).booleanValue();
+ }
+
+ /**
+ * Gets the named parameter value as a boolean, with a default. Returns the
+ * default value if the parameter is not found.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a boolean, or the default
+ */
+ public boolean getBooleanParameter(String name, boolean def) {
+ try {
+ return getBooleanParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the booleanSubParameter attribute of the ParameterParser object
+ *
+ * @param first Description of the Parameter
+ * @param next Description of the Parameter
+ * @param def Description of the Parameter
+ * @return The booleanSubParameter value
+ */
+ public boolean getBooleanSubParameter(String first, String next, boolean def) {
+ try {
+ return new Boolean(getSubParameter(first, next)).booleanValue();
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as a byte
+ *
+ * @param name the parameter name
+ * @return the parameter value as a byte
+ * @exception ParameterNotFoundException if the parameter was not found
+ * @exception NumberFormatException if the parameter value could not be
+ * converted to a byte
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws java.lang.NumberFormatException if any.
+ */
+ public byte getByteParameter(String name) throws ParameterNotFoundException, NumberFormatException {
+ return Byte.parseByte(getStringParameter(name));
+ }
+
+ /**
+ * Gets the named parameter value as a byte, with a default. Returns the
+ * default value if the parameter is not found or cannot be converted to a
+ * byte.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a byte, or the default
+ */
+ public byte getByteParameter(String name, byte def) {
+ try {
+ return getByteParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as a char
+ *
+ * @param name the parameter name
+ * @return the parameter value as a char
+ * @exception ParameterNotFoundException if the parameter was not found or
+ * was the empty string
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public char getCharParameter(String name) throws ParameterNotFoundException {
+ String param = getStringParameter(name);
+
+ if (param.length() == 0) {
+ throw new ParameterNotFoundException(name + " is empty string");
+ } else {
+ return (param.charAt(0));
+ }
+ }
+
+ /**
+ * Gets the named parameter value as a char, with a default. Returns the
+ * default value if the parameter is not found.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a char, or the default
+ */
+ public char getCharParameter(String name, char def) {
+ try {
+ return getCharParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the classNameParameter attribute of the ParameterParser object
+ *
+ * @param name Description of the Parameter
+ * @return The classNameParameter value
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public String getClassNameParameter(String name) throws ParameterNotFoundException {
+ String p = getStringParameter(name);
+ StringTokenizer st = new StringTokenizer(p);
+
+ return (st.nextToken().trim());
+ }
+
+ // FIXME: check for [a-zA-Z].([a-zA-Z])*
+ /**
+ * Gets the classNameParameter attribute of the ParameterParser object
+ *
+ * @param name Description of the Parameter
+ * @param def Description of the Parameter
+ * @return The classNameParameter value
+ */
+ public String getClassNameParameter(String name, String def) {
+ try {
+ return getClassNameParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as a double
+ *
+ * @param name the parameter name
+ * @return the parameter value as a double
+ * @exception ParameterNotFoundException if the parameter was not found
+ * @exception NumberFormatException if the parameter could not be converted
+ * to a double
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws java.lang.NumberFormatException if any.
+ */
+ public double getDoubleParameter(String name) throws ParameterNotFoundException, NumberFormatException {
+ return new Double(getStringParameter(name)).doubleValue();
+ }
+
+ /**
+ * Gets the named parameter value as a double, with a default. Returns the
+ * default value if the parameter is not found.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a double, or the default
+ */
+ public double getDoubleParameter(String name, double def) {
+ try {
+ return getDoubleParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as a float
+ *
+ * @param name the parameter name
+ * @return the parameter value as a float
+ * @exception ParameterNotFoundException if the parameter was not found
+ * @exception NumberFormatException if the parameter could not be converted
+ * to a float
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws java.lang.NumberFormatException if any.
+ */
+ public float getFloatParameter(String name) throws ParameterNotFoundException, NumberFormatException {
+ return new Float(getStringParameter(name)).floatValue();
+ }
+
+ /**
+ * Gets the named parameter value as a float, with a default. Returns the
+ * default value if the parameter is not found.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a float, or the default
+ */
+ public float getFloatParameter(String name, float def) {
+ try {
+ return getFloatParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as an IP String, with a default. Returns
+ * the default value if the parameter is not found or is the empty string.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a String, or the default
+ */
+ public String getIPParameter(String name, String def) {
+ try {
+ return getIPParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as an IP String
+ *
+ * @param name the parameter name
+ * @return the parameter value as a valid IP String or an Empty string if
+ * invalid
+ * @exception ParameterNotFoundException if the parameter was not found or
+ * was the empty string
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public String getIPParameter(String name) throws ParameterNotFoundException {
+ boolean valid = true;
+ String[] values = request.getParameterValues(name);
+ String value;
+
+ if (values == null) {
+ throw new ParameterNotFoundException(name + " not found");
+ } else if (values[0].length() == 0) {
+ throw new ParameterNotFoundException(name + " was empty");
+ } else {
+ // trim illegal characters
+ value = clean(values[0].trim());
+
+ if (value.indexOf("&") > 0) {
+ // truncate additional parameters that follow &
+ value = value.substring(0, value.indexOf("&"));
+ }
+
+ // validate the IP ex: 124.143.12.254
+ int startIndex = 0;
+ int endIndex = 0;
+ int octetCount = 0;
+ int octetValue;
+ String octet;
+
+ // if no .'s then it's not an IP
+ if (value.indexOf(".") >= 0) {
+ while ((valid == true) && (octetCount < 4)) {
+ endIndex = value.indexOf(".", startIndex);
+
+ if (endIndex == -1) {
+ endIndex = value.length();
+ }
+
+ octet = value.substring(startIndex, endIndex);
+ startIndex = endIndex + 1;
+
+ try {
+ octetValue = Integer.parseInt(octet);
+
+ if ((octetValue <= 0) || (octetValue >= 256)) {
+ valid = false;
+ }
+ } catch (Exception e) {
+ valid = false;
+ }
+
+ octetCount++;
+ }
+ } else {
+ // Not a valid IP
+ valid = false;
+ }
+
+ // Check for any extra garbage. If the last octet was a large value
+ // it would be trapped by the above range check.
+ if (value.length() != endIndex) {
+ valid = false;
+ }
+
+ return valid ? value : null;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as a int
+ *
+ * @param name the parameter name
+ * @return the parameter value as a int
+ * @exception ParameterNotFoundException if the parameter was not found
+ * @exception NumberFormatException if the parameter could not be converted
+ * to a int
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws java.lang.NumberFormatException if any.
+ */
+ public int getIntParameter(String name) throws ParameterNotFoundException, NumberFormatException {
+ return Integer.parseInt(getStringParameter(name));
+ }
+
+ /**
+ * Gets the named parameter value as a int, with a default. Returns the
+ * default value if the parameter is not found.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a int, or the default
+ */
+ public int getIntParameter(String name, int def) {
+ try {
+ return getIntParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as a long
+ *
+ * @param name the parameter name
+ * @return the parameter value as a long
+ * @exception ParameterNotFoundException if the parameter was not found
+ * @exception NumberFormatException if the parameter could not be converted
+ * to a long
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws java.lang.NumberFormatException if any.
+ */
+ public long getLongParameter(String name) throws ParameterNotFoundException, NumberFormatException {
+ return Long.parseLong(getStringParameter(name));
+ }
+
+ /**
+ * Gets the named parameter value as a long, with a default. Returns the
+ * default value if the parameter is not found.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a long, or the default
+ */
+ public long getLongParameter(String name, long def) {
+ try {
+ return getLongParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Determines which of the required parameters were missing from the
+ * request. Returns null if all the parameters are present.
+ *
+ * @param requestuired Description of the Parameter
+ * @return an array of missing parameters, or null if none are missing
+ */
+ public String[] getMissingParameters(String[] requestuired) {
+ Vector missing = new Vector();
+
+ for (int i = 0; i < requestuired.length; i++) {
+ String val = getStringParameter(requestuired[i], null);
+
+ if (val == null) {
+ missing.addElement(requestuired[i]);
+ }
+ }
+
+ if (missing.size() == 0) {
+ return null;
+ } else {
+ String[] ret = new String[missing.size()];
+ missing.copyInto(ret);
+
+ return ret;
+ }
+ }
+
+ /**
+ * Gets the parameterNames attribute of the ParameterParser object
+ *
+ * @return The parameterNames value
+ */
+ public Enumeration getParameterNames() {
+ if (request == null) {
+ return (null);
+ }
+
+ return request.getParameterNames();
+ }
+
+ /**
+ * Gets the parameterValues attribute of the ParameterParser object
+ *
+ * @param name Description of the Parameter
+ * @return The parameterValues value
+ */
+ public String[] getParameterValues(String name) {
+ if (request == null) {
+ return (null);
+ }
+
+ return request.getParameterValues(name);
+ }
+
+ /**
+ * Gets the rawParameter attribute of the ParameterParser object
+ *
+ * @param name Description of the Parameter
+ * @param def Description of the Parameter
+ * @return The rawParameter value
+ */
+ public String getRawParameter(String name, String def) {
+ try {
+ return getRawParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the rawParameter attribute of the ParameterParser object
+ *
+ * @param name Description of the Parameter
+ * @return The rawParameter value
+ * @exception ParameterNotFoundException Description of the Exception
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public String getRawParameter(String name) throws ParameterNotFoundException {
+ String[] values = request.getParameterValues(name);
+
+ if (values == null) {
+ throw new ParameterNotFoundException(name + " not found");
+ } else if (values[0].length() == 0) {
+ throw new ParameterNotFoundException(name + " was empty");
+ }
+
+ return (values[0]);
+ }
+
+ /**
+ * Gets the named parameter value as a short
+ *
+ * @param name the parameter name
+ * @return the parameter value as a short
+ * @exception ParameterNotFoundException if the parameter was not found
+ * @exception NumberFormatException if the parameter could not be converted
+ * to a short
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws java.lang.NumberFormatException if any.
+ */
+ public short getShortParameter(String name) throws ParameterNotFoundException, NumberFormatException {
+ return Short.parseShort(getStringParameter(name));
+ }
+
+ /**
+ * Gets the named parameter value as a short, with a default. Returns the
+ * default value if the parameter is not found.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a short, or the default
+ */
+ public short getShortParameter(String name, short def) {
+ try {
+ return getShortParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as a String
+ *
+ * @param name the parameter name
+ * @return the parameter value as a String
+ * @exception ParameterNotFoundException if the parameter was not found or
+ * was the empty string
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public String getStringParameter(String name) throws ParameterNotFoundException {
+ String[] values = request.getParameterValues(name);
+ String value;
+
+ if (values == null) {
+ throw new ParameterNotFoundException(name + " not found");
+ } else if (values[0].length() == 0) {
+ throw new ParameterNotFoundException(name + " was empty");
+ } else {
+ // trim illegal characters
+ value = clean(values[0].trim());
+
+ if (value.indexOf("&") > 0) {
+ // truncate additional parameters that follow &
+ value = value.substring(0, value.indexOf("&"));
+ }
+
+ return value;
+ }
+ }
+
+ /**
+ * Gets the named parameter value as a String, with a default. Returns the
+ * default value if the parameter is not found or is the empty string.
+ *
+ * @param name the parameter name
+ * @param def the default parameter value
+ * @return the parameter value as a String, or the default
+ */
+ public String getStringParameter(String name, String def) {
+ try {
+ return getStringParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the subParameter attribute of the ParameterParser object
+ *
+ * @param first Description of the Parameter
+ * @param next Description of the Parameter
+ * @param def Description of the Parameter
+ * @return The subParameter value
+ */
+ public String getSubParameter(String first, String next, String def) {
+ try {
+ return getSubParameter(first, next);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the parameter named 'next' following the parameter 'first'. Presumes
+ * the structure: first=firstvalue&next=nextValue
+ *
+ * @param first Description of the Parameter
+ * @param next Description of the Parameter
+ * @return The subParameter value
+ * @exception ParameterNotFoundException Description of the Exception
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public String getSubParameter(String first, String next) throws ParameterNotFoundException {
+ String[] values = request.getParameterValues(first);
+ String value;
+
+ if (values == null) {
+ throw new ParameterNotFoundException(first + " not found");
+ } else if (values[0].length() == 0) {
+ throw new ParameterNotFoundException(first + " was empty");
+ } else {
+ value = clean(values[0].trim());
+
+ int idx = value.indexOf("&") + 1;
+
+ // index of first char of first sub-param name
+ if (idx == 0) {
+ throw new ParameterNotFoundException("No subparameter key");
+ }
+
+ value = value.substring(idx);
+
+ // System.out.println("= = = = = =Parameter parser looking for " +
+ // next + " in " + value );
+ int nextValueIndex = value.indexOf(next + "=");
+
+ // System.out.println("= = = = = =Parameter parser nextValueIndex =
+ // " + nextValueIndex );
+ if (nextValueIndex < 0) {
+ throw new ParameterNotFoundException("No subparameter value");
+ }
+
+ nextValueIndex += (next.length() + 1);
+
+ if (nextValueIndex >= 0) {
+ value = value.substring(nextValueIndex);
+ } else {
+ throw new ParameterNotFoundException(next + " not found");
+ }
+ }
+
+ if (value.indexOf("&") > 0) {
+ // truncate additional parameters that follow &
+ value = value.substring(0, value.indexOf("&"));
+ }
+
+ // System.out.println("=-=-=-=-=ParameterParser returning value " +
+ // value );
+ return value;
+ }
+
+ /**
+ * Gets the wordParameter attribute of the ParameterParser object
+ *
+ * @param name Description of the Parameter
+ * @return The wordParameter value
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public String getWordParameter(String name) throws ParameterNotFoundException {
+ String p = getStringParameter(name);
+ StringTokenizer st = new StringTokenizer(p);
+
+ return (st.nextToken().trim());
+ }
+
+ // FIXME: check for [a-zA-Z]
+ /**
+ * Gets the wordParameter attribute of the ParameterParser object
+ *
+ * @param name Description of the Parameter
+ * @param def Description of the Parameter
+ * @return The wordParameter value
+ */
+ public String getWordParameter(String name, String def) {
+ try {
+ return getWordParameter(name);
+ } catch (Exception e) {
+ return def;
+ }
+ }
+
+ /**
+ * Gets the specified parameter from the request and validates it against
+ * the provided regular expression. If the regular expression check fails,
+ * the default value is returned instead.
+ *
+ * @param name The name of the parameter to retrieve from the request.
+ * @param def The default value of the parameter.
+ * @param regexpattern The precompiled regular expression to be used to
+ * validate the parameter.
+ * @return The validated parameter value, or the default value if validation
+ * failed.
+ */
+ private String getRegexParameter(String name, String def, Pattern regexpattern) throws ValidationException {
+ try {
+ return getRegexParameter(name, regexpattern);
+ } catch (Exception e) {
+ // System.out.println("Exception occured in defined pattern match");
+ // e.printStackTrace();
+ return def;
+ }
+ }
+
+ /**
+ * Gets the specified parameter from the request and validates it against
+ * the provided regular expression. If the regular expression check fails,
+ * the default value is returned instead.
+ *
+ * @param name The name of the parameter to retrieve from the request.
+ * @param def The default value of the parameter.
+ * @param regexpattern The precompiled regular expression to be used to
+ * validate the parameter.
+ * @return The validated parameter value, or the default value if validation
+ * failed.
+ */
+ private String getRegexParameter(String name, Pattern regexpattern) throws ParameterNotFoundException,
+ ValidationException {
+ String param = getStringParameter(name);
+
+ if (regexpattern.matcher(param).matches()) {
+ return param;
+ } else {
+ // System.out.println(param + " didn't match defined pattern.");
+ throw new ValidationException(name + " contained an invalid value");
+ }
+ }
+
+ /**
+ * getStrictAlphaParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @param maxLength a int.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getStrictAlphaParameter(String name, int maxLength) throws ParameterNotFoundException,
+ ValidationException {
+ String alphaRegEx = "^[a-zA-Z\\s]{0," + maxLength + "}$";
+ Pattern alphaPattern = Pattern.compile(alphaRegEx);
+
+ return getRegexParameter(name, alphaPattern);
+ }
+
+ /**
+ * getStrictNumericParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @param maxLength a int.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getStrictNumericParameter(String name, int maxLength) throws ParameterNotFoundException,
+ ValidationException {
+ String numericRegEx = "^\\d{0," + maxLength + "}$";
+ Pattern numericPattern = Pattern.compile(numericRegEx);
+
+ return getRegexParameter(name, numericPattern);
+ }
+
+ private static final String SSNREGEX = "^\\d{3}-\\d{2}-\\d{4}$";
+
+ private static final Pattern Ssnpattern = Pattern.compile(SSNREGEX);
+
+ /**
+ * getSsnParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getSsnParameter(String name) throws ParameterNotFoundException, ValidationException {
+ return getRegexParameter(name, Ssnpattern);
+ }
+
+ // Validates format for major brands of credit card.
+ // private static final String CCNREGEX =
+ // "^(?:(?4\\d{3})|(?5[1-5]\\d{2})|(?6011)|(?(?:3[68]\\d{2})|(?:30[0-5]\\d))|(?3[47]\\d{2}))([
+ //-]?)(?(DinersClub)(?:\\d{6}\\1\\d{4})|(?(AmericanExpress)(?:\\d{6}\\1\\d{5})|(?:\\d{4}\\1\\d{4
+ // }\\1\\d{4})))$";
+ private static final String CCNREGEX = "^\\d{16}$";
+
+ private static final Pattern Ccnpattern = Pattern.compile(CCNREGEX);
+
+ /**
+ * getCcnParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getCcnParameter(String name) throws ParameterNotFoundException, ValidationException {
+ return getRegexParameter(name, Ccnpattern);
+ }
+
+ private static final String ZIPREGEX = "^\\d{5}(-\\d{4})?$";
+
+ private static final Pattern Zippattern = Pattern.compile(ZIPREGEX);
+
+ /**
+ * getZipParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getZipParameter(String name) throws ParameterNotFoundException, ValidationException {
+ return getZipParameter(name, null);
+ }
+
+ /**
+ * getZipParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @param def a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getZipParameter(String name, String def) throws ValidationException {
+ return getRegexParameter(name, def, Zippattern);
+ }
+
+ private static final String PHONEREGEX = "^\\(?[\\d]{3}\\)?[\\s-]?[\\d]{3}[\\s-]?[\\d]{4}$";
+
+ // Or this more forgiving pattern:
+ // private static final String PHONEREGEX = "^([\\-()+ 0-9x])+$";
+ private static final Pattern phonepattern = Pattern.compile(PHONEREGEX);
+
+ /**
+ * getPhoneParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getPhoneParameter(String name) throws ParameterNotFoundException, ValidationException {
+ return getPhoneParameter(name, null);
+ }
+
+ /**
+ * getPhoneParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @param def a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getPhoneParameter(String name, String def) throws ValidationException {
+ return getRegexParameter(name, def, phonepattern);
+ }
+
+ private static final String EMAILREGEX = "^[\\w-]+(?:\\.[\\w-]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7}$";
+
+ private static final Pattern emailpattern = Pattern.compile(EMAILREGEX);
+
+ /**
+ * getEMailParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getEMailParameter(String name) throws ParameterNotFoundException, ValidationException {
+ return getEMailParameter(name, null);
+ }
+
+ /**
+ * getEMailParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @param def a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getEMailParameter(String name, String def) throws ValidationException {
+ return getRegexParameter(name, def, emailpattern);
+ }
+
+ private static final String DATEREGEX = "([\\/ .,:0-9a-zA-Z])+$";
+
+ private static final Pattern datepattern = Pattern.compile(DATEREGEX);
+
+ /**
+ * getDateParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getDateParameter(String name) throws ParameterNotFoundException, ValidationException {
+ return getDateParameter(name, null);
+ }
+
+ /**
+ * getDateParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @param def a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getDateParameter(String name, String def) throws ValidationException {
+ return getRegexParameter(name, def, datepattern);
+ }
+
+ private static final String URLREGEX = "^(((https?)://)([-()_.!~*';/?:@&=+$,A-Za-z0-9])+)([).!';/?:,][[:blank:]])?$";
+
+ private static final Pattern URLpattern = Pattern.compile(URLREGEX);
+
+ /**
+ * getURLParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getURLParameter(String name) throws ParameterNotFoundException, ValidationException {
+ return getURLParameter(name, null);
+ }
+
+ /**
+ * getURLParameter.
+ *
+ * @param name a {@link java.lang.String} object.
+ * @param def a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ValidationException if any.
+ */
+ public String getURLParameter(String name, String def) throws ValidationException {
+ return getRegexParameter(name, def, URLpattern);
+ }
+
+ /**
+ * htmlEncode.
+ *
+ * @param s a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ */
+ protected static String htmlEncode(String s) {
+ return HtmlEncoder.encode(s);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ public String toString() {
+ StringBuffer s = new StringBuffer("[");
+ Enumeration e = getParameterNames();
+
+ while (e.hasMoreElements()) {
+ String key = (String) e.nextElement();
+ s.append(key + "=" + getParameterValues(key)[0]);
+
+ // FIXME: Other values?
+ if (e.hasMoreElements()) {
+ s.append(",");
+ }
+ }
+
+ s.append("]");
+
+ return (s.toString());
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param request Description of the Parameter
+ */
+ public void update(ServletRequest request) {
+ this.request = request;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/RandomLessonTracker.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/RandomLessonTracker.java
index 5c7f0704f..6d124b3dc 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/RandomLessonTracker.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/RandomLessonTracker.java
@@ -1,117 +1,164 @@
-
-package org.owasp.webgoat.session;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-
-public class RandomLessonTracker extends LessonTracker
-{
-
- private String[] stages;
-
- private String stage;
-
- private Map completed = new HashMap();
-
- public RandomLessonTracker(String[] stages)
- {
- if (stages == null) stages = new String[0];
- this.stages = stages;
- }
-
- public void setStage(String stage)
- {
- this.stage = stage;
- }
-
- public String getStage()
- {
- if (this.stage == null && stages.length > 0) return stages[0];
- return this.stage;
- }
-
- public void setStageComplete(String stage, boolean complete)
- {
- completed.put(stage, Boolean.valueOf(complete));
- if (!complete) return;
- int i = getStageNumber(stage);
- if (i < stages.length - 1) setStage(stages[i + 1]);
- }
-
- public int getStageNumber(String stage)
- {
- for (int i = 0; i < stages.length; i++)
- if (stages[i].equals(stage)) return i;
- return -1;
- }
-
- public boolean hasCompleted(String stage)
- {
- Boolean complete = completed.get(stage);
- return complete == null ? false : complete.booleanValue();
- }
-
- @Override
- public boolean getCompleted()
- {
- for (int i = 0; i < stages.length; i++)
- if (!hasCompleted(stages[i])) return false;
- return true;
- }
-
- @Override
- public void setCompleted(boolean complete)
- {
- if (complete == true) throw new UnsupportedOperationException("Use individual stage completion instead");
- for (int i = 0; i < stages.length; i++)
- setStageComplete(stages[i], false);
- setStage(stages[0]);
- }
-
- protected void setProperties(Properties props, Screen screen)
- {
- super.setProperties(props, screen);
- for (int i = 0; i < stages.length; i++)
- {
- String p = props.getProperty(screen.getTitle() + "." + stages[i] + ".completed");
- if (p != null)
- {
- setStageComplete(stages[i], Boolean.valueOf(p));
- }
- }
- setStage(props.getProperty(screen.getTitle() + ".stage"));
- }
-
- public void store(WebSession s, Screen screen, String user)
- {
- for (int i = 0; i < stages.length; i++)
- {
- if (hasCompleted(stages[i]))
- {
- lessonProperties.setProperty(screen.getTitle() + "." + stages[i] + ".completed", Boolean.TRUE
- .toString());
- }
- else
- {
- lessonProperties.remove(screen.getTitle() + "." + stages[i] + ".completed");
- }
- }
- lessonProperties.setProperty(screen.getTitle() + ".stage", getStage());
- super.store(s, screen, user);
- }
-
- public String toString()
- {
- StringBuffer buff = new StringBuffer();
- buff.append(super.toString());
- for (int i = 0; i < stages.length; i++)
- {
- buff.append(" - completed " + stages[i] + " :....... " + hasCompleted(stages[i]) + "\n");
- }
- buff.append(" - currentStage:....... " + getStage() + "\n");
- return buff.toString();
- }
-
-}
+
+package org.owasp.webgoat.session;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+
+/**
+ * RandomLessonTracker class.
+ *
+ * @version $Id: $Id
+ */
+public class RandomLessonTracker extends LessonTracker
+{
+
+ private String[] stages;
+
+ private String stage;
+
+ private Map completed = new HashMap();
+
+ /**
+ * Constructor for RandomLessonTracker.
+ *
+ * @param stages an array of {@link java.lang.String} objects.
+ */
+ public RandomLessonTracker(String[] stages)
+ {
+ if (stages == null) stages = new String[0];
+ this.stages = stages;
+ }
+
+ /**
+ * Setter for the field stage
.
+ *
+ * @param stage a {@link java.lang.String} object.
+ */
+ public void setStage(String stage)
+ {
+ this.stage = stage;
+ }
+
+ /**
+ * Getter for the field stage
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getStage()
+ {
+ if (this.stage == null && stages.length > 0) return stages[0];
+ return this.stage;
+ }
+
+ /**
+ * setStageComplete.
+ *
+ * @param stage a {@link java.lang.String} object.
+ * @param complete a boolean.
+ */
+ public void setStageComplete(String stage, boolean complete)
+ {
+ completed.put(stage, Boolean.valueOf(complete));
+ if (!complete) return;
+ int i = getStageNumber(stage);
+ if (i < stages.length - 1) setStage(stages[i + 1]);
+ }
+
+ /**
+ * getStageNumber.
+ *
+ * @param stage a {@link java.lang.String} object.
+ * @return a int.
+ */
+ public int getStageNumber(String stage)
+ {
+ for (int i = 0; i < stages.length; i++)
+ if (stages[i].equals(stage)) return i;
+ return -1;
+ }
+
+ /**
+ * hasCompleted.
+ *
+ * @param stage a {@link java.lang.String} object.
+ * @return a boolean.
+ */
+ public boolean hasCompleted(String stage)
+ {
+ Boolean complete = completed.get(stage);
+ return complete == null ? false : complete.booleanValue();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean getCompleted()
+ {
+ for (int i = 0; i < stages.length; i++)
+ if (!hasCompleted(stages[i])) return false;
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void setCompleted(boolean complete)
+ {
+ if (complete == true) throw new UnsupportedOperationException("Use individual stage completion instead");
+ for (int i = 0; i < stages.length; i++)
+ setStageComplete(stages[i], false);
+ setStage(stages[0]);
+ }
+
+ /** {@inheritDoc} */
+ protected void setProperties(Properties props, Screen screen)
+ {
+ super.setProperties(props, screen);
+ for (int i = 0; i < stages.length; i++)
+ {
+ String p = props.getProperty(screen.getTitle() + "." + stages[i] + ".completed");
+ if (p != null)
+ {
+ setStageComplete(stages[i], Boolean.valueOf(p));
+ }
+ }
+ setStage(props.getProperty(screen.getTitle() + ".stage"));
+ }
+
+ /** {@inheritDoc} */
+ public void store(WebSession s, Screen screen, String user)
+ {
+ for (int i = 0; i < stages.length; i++)
+ {
+ if (hasCompleted(stages[i]))
+ {
+ lessonProperties.setProperty(screen.getTitle() + "." + stages[i] + ".completed", Boolean.TRUE
+ .toString());
+ }
+ else
+ {
+ lessonProperties.remove(screen.getTitle() + "." + stages[i] + ".completed");
+ }
+ }
+ lessonProperties.setProperty(screen.getTitle() + ".stage", getStage());
+ super.store(s, screen, user);
+ }
+
+ /**
+ * toString.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String toString()
+ {
+ StringBuffer buff = new StringBuffer();
+ buff.append(super.toString());
+ for (int i = 0; i < stages.length; i++)
+ {
+ buff.append(" - completed " + stages[i] + " :....... " + hasCompleted(stages[i]) + "\n");
+ }
+ buff.append(" - currentStage:....... " + getStage() + "\n");
+ return buff.toString();
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/Role.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/Role.java
index 0b7310ccd..5b6744c70 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/Role.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/Role.java
@@ -1,13 +1,28 @@
package org.owasp.webgoat.session;
+/**
+ * Role class.
+ *
+ * @version $Id: $Id
+ */
public class Role {
private String rolename;
+ /**
+ * Constructor for Role.
+ *
+ * @param rolename a {@link java.lang.String} object.
+ */
public Role(String rolename) {
this.rolename = rolename;
}
+ /**
+ * Getter for the field rolename
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
public String getRolename() {
return this.rolename;
}
-}
\ No newline at end of file
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/Screen.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/Screen.java
index 619dfd28c..40bc3a6d1 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/Screen.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/Screen.java
@@ -42,7 +42,8 @@ import org.owasp.webgoat.lessons.AbstractLesson;
*
* @author Jeff Williams Aspect
* Security
- * @created October 28, 2003
+ * @since October 28, 2003
+ * @version $Id: $Id
*/
public abstract class Screen {
@@ -69,6 +70,11 @@ public abstract class Screen {
// will be stored in the internal database. The user will be able to hack
// into the database and change their role. This will allow the user to
// see the admin screens, once they figure out how to turn the admin switch on.
+ /**
+ * getRole.
+ *
+ * @return a {@link java.lang.String} object.
+ */
public abstract String getRole();
/**
@@ -106,19 +112,33 @@ public abstract class Screen {
/**
* Gets the lessonTracker attribute of the AbstractLesson object
*
- * @param userName Description of the Parameter
* @return The lessonTracker value
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
*/
public LessonTracker getLessonTracker(WebSession s) {
UserTracker userTracker = UserTracker.instance();
return userTracker.getLessonTracker(s, this);
}
+ /**
+ * getLessonTracker.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param userNameOverride a {@link java.lang.String} object.
+ * @return a {@link org.owasp.webgoat.session.LessonTracker} object.
+ */
public LessonTracker getLessonTracker(WebSession s, String userNameOverride) {
UserTracker userTracker = UserTracker.instance();
return userTracker.getLessonTracker(s, userNameOverride, this);
}
+ /**
+ * getLessonTracker.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param lesson a {@link org.owasp.webgoat.lessons.AbstractLesson} object.
+ * @return a {@link org.owasp.webgoat.session.LessonTracker} object.
+ */
public LessonTracker getLessonTracker(WebSession s, AbstractLesson lesson) {
UserTracker userTracker = UserTracker.instance();
return userTracker.getLessonTracker(s, lesson);
@@ -131,6 +151,11 @@ public abstract class Screen {
*/
public abstract String getTitle();
+ /**
+ * Setter for the field content
.
+ *
+ * @param content a {@link org.apache.ecs.Element} object.
+ */
protected void setContent(Element content) {
this.content = content;
}
@@ -145,10 +170,20 @@ public abstract class Screen {
return new A("http://www.aspectsecurity.com/webgoat.html", logo);
}
+ /**
+ * getSponsor.
+ *
+ * @return a {@link java.lang.String} object.
+ */
public String getSponsor() {
return "Aspect Security";
}
+ /**
+ * getSponsorLogoResource.
+ *
+ * @return a {@link java.lang.String} object.
+ */
public String getSponsorLogoResource() {
return "images/aspectlogo-horizontal-small.jpg";
}
@@ -178,6 +213,7 @@ public abstract class Screen {
/**
* Returns the content length of the the html.
*
+ * @return a int.
*/
public int getContentLength() {
return getContent().length();
@@ -197,6 +233,11 @@ public abstract class Screen {
}
// hook all the links
+ /**
+ * Getter for the field content
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
public String getContent() {
//String makeAllAjax = "";
// need to do this here as some of the lessons render forms after submission of an ajax form
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/SequentialLessonTracker.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/SequentialLessonTracker.java
index 85937ceeb..5f7dfa761 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/SequentialLessonTracker.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/SequentialLessonTracker.java
@@ -1,38 +1,60 @@
-
-package org.owasp.webgoat.session;
-
-import java.util.Properties;
-
-
-public class SequentialLessonTracker extends LessonTracker
-{
-
- private int currentStage = 1;
-
- public int getStage()
- {
- return currentStage;
- }
-
- public void setStage(int stage)
- {
- currentStage = stage;
- }
-
- protected void setProperties(Properties props, Screen screen)
- {
- super.setProperties(props, screen);
- currentStage = Integer.parseInt(props.getProperty(screen.getTitle() + ".currentStage"));
- }
-
- public void store(WebSession s, Screen screen, String user)
- {
- lessonProperties.setProperty(screen.getTitle() + ".currentStage", Integer.toString(currentStage));
- super.store(s, screen, user);
- }
-
- public String toString()
- {
- return super.toString() + " - currentStage:....... " + currentStage + "\n";
- }
-}
+
+package org.owasp.webgoat.session;
+
+import java.util.Properties;
+
+
+/**
+ * SequentialLessonTracker class.
+ *
+ * @version $Id: $Id
+ */
+public class SequentialLessonTracker extends LessonTracker
+{
+
+ private int currentStage = 1;
+
+ /**
+ * getStage.
+ *
+ * @return a int.
+ */
+ public int getStage()
+ {
+ return currentStage;
+ }
+
+ /**
+ * setStage.
+ *
+ * @param stage a int.
+ */
+ public void setStage(int stage)
+ {
+ currentStage = stage;
+ }
+
+ /** {@inheritDoc} */
+ protected void setProperties(Properties props, Screen screen)
+ {
+ super.setProperties(props, screen);
+ currentStage = Integer.parseInt(props.getProperty(screen.getTitle() + ".currentStage"));
+ }
+
+ /** {@inheritDoc} */
+ public void store(WebSession s, Screen screen, String user)
+ {
+ lessonProperties.setProperty(screen.getTitle() + ".currentStage", Integer.toString(currentStage));
+ super.store(s, screen, user);
+ }
+
+ /**
+ * toString.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String toString()
+ {
+ return super.toString() + " - currentStage:....... " + currentStage + "\n";
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/UnauthenticatedException.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/UnauthenticatedException.java
index 4984668fb..8ea4f710f 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/UnauthenticatedException.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/UnauthenticatedException.java
@@ -1,39 +1,42 @@
-
-package org.owasp.webgoat.session;
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public class UnauthenticatedException extends Exception
-{
-
- /**
- *
- */
- private static final long serialVersionUID = 97865025446819061L;
-
-}
+
+package org.owasp.webgoat.session;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public class UnauthenticatedException extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 97865025446819061L;
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/UnauthorizedException.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/UnauthorizedException.java
index 7fa586c18..a405d2bd2 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/UnauthorizedException.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/UnauthorizedException.java
@@ -1,39 +1,42 @@
-
-package org.owasp.webgoat.session;
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public class UnauthorizedException extends Exception
-{
-
- /**
- *
- */
- private static final long serialVersionUID = 5245519486798464814L;
-
-}
+
+package org.owasp.webgoat.session;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public class UnauthorizedException extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5245519486798464814L;
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/User.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/User.java
index ff9940d86..e74e5824f 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/User.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/User.java
@@ -3,24 +3,49 @@ package org.owasp.webgoat.session;
import java.util.ArrayList;
import java.util.Iterator;
+/**
+ * User class.
+ *
+ * @version $Id: $Id
+ */
public class User {
private String username;
private ArrayList roles;
+ /**
+ * Constructor for User.
+ *
+ * @param username a {@link java.lang.String} object.
+ */
public User(String username) {
this.username = username;
this.roles = new ArrayList();
}
+ /**
+ * Getter for the field username
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
public String getUsername() {
return username;
}
+ /**
+ * Getter for the field roles
.
+ *
+ * @return a {@link java.util.Iterator} object.
+ */
public Iterator getRoles() {
return roles.iterator();
}
+ /**
+ * addRole.
+ *
+ * @param rolename a {@link java.lang.String} object.
+ */
public void addRole(String rolename) {
roles.add(new Role(rolename));
}
-}
\ No newline at end of file
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/UserDatabase.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/UserDatabase.java
index d383c7e79..25867223c 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/UserDatabase.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/UserDatabase.java
@@ -23,6 +23,9 @@ class UserDatabase {
private final String DELETE_ALL_ROLES_FOR_USER = "DELETE FROM user_roles WHERE user_id IN (SELECT id FROM users WHERE username = ?);";
private final String DELETE_USER = "DELETE FROM users WHERE username = ?;";
+ /**
+ * Constructor for UserDatabase.
+ */
public UserDatabase() {
createDefaultTables();
if (getTableCount("users") <= 0) {
@@ -36,6 +39,11 @@ class UserDatabase {
}
}
+ /**
+ * open.
+ *
+ * @return a boolean.
+ */
public boolean open() {
try {
if (userDB == null || userDB.isClosed()) {
@@ -52,6 +60,11 @@ class UserDatabase {
return true;
}
+ /**
+ * close.
+ *
+ * @return a boolean.
+ */
public boolean close() {
try {
if (userDB != null && !userDB.isClosed())
@@ -63,6 +76,12 @@ class UserDatabase {
return true;
}
+ /**
+ * getTableCount.
+ *
+ * @param tableName a {@link java.lang.String} object.
+ * @return a int.
+ */
public int getTableCount(String tableName) {
int count = 0;
try {
@@ -82,6 +101,11 @@ class UserDatabase {
return count;
}
+ /**
+ * getUsers.
+ *
+ * @return a {@link java.util.Iterator} object.
+ */
public Iterator getUsers() {
ArrayList users = new ArrayList();
User currentUser;
@@ -113,6 +137,13 @@ class UserDatabase {
return users.iterator();
}
+ /**
+ * addRoleToUser.
+ *
+ * @param username a {@link java.lang.String} object.
+ * @param rolename a {@link java.lang.String} object.
+ * @return a boolean.
+ */
public boolean addRoleToUser(String username, String rolename) {
try {
open();
@@ -129,10 +160,22 @@ class UserDatabase {
return true;
}
+ /**
+ * removeUser.
+ *
+ * @param user a {@link org.owasp.webgoat.session.User} object.
+ * @return a boolean.
+ */
public boolean removeUser(User user) {
return removeUser(user.getUsername());
}
+ /**
+ * removeUser.
+ *
+ * @param username a {@link java.lang.String} object.
+ * @return a boolean.
+ */
public boolean removeUser(String username) {
try {
open();
@@ -211,4 +254,4 @@ class UserDatabase {
addRoleToUser("basic", "webgoat_basic");
addRoleToUser("guest", "webgoat_user");
}
-}
\ No newline at end of file
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/UserTracker.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/UserTracker.java
index 5ef2004ea..07129bdac 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/UserTracker.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/UserTracker.java
@@ -1,269 +1,289 @@
-
-package org.owasp.webgoat.session;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Bruce Mayhew WebGoat
- * @created October 29, 2003
- */
-
-public class UserTracker
-{
-
- private static UserTracker instance;
-
- // FIXME: persist this somehow!
-
- private static HashMap> storage = new HashMap>();
-
- private static UserDatabase usersDB = new UserDatabase();
-
- /**
- * Constructor for the UserTracker object
- */
- private UserTracker()
- {
- }
-
- /**
- * Gets the completed attribute of the UserTracker object
- *
- * @param userName
- * Description of the Parameter
- * @return The completed value
- */
- public int getCompleted(String userName)
- {
-
- HashMap usermap = getUserMap(userName);
-
- Iterator i = usermap.entrySet().iterator();
-
- int count = 0;
-
- while (i.hasNext())
- {
-
- Map.Entry entry = (Map.Entry) i.next();
-
- int value = ((Integer) entry.getValue()).intValue();
-
- if (value > 5)
- {
- count++;
- }
-
- }
-
- return count;
- }
-
- /**
- * Gets the users attribute of the UserTracker object
- *
- * @return The users value
- */
- public Collection getUsers()
- {
- return storage.keySet();
- }
-
- public Collection getAllUsers(String roleName)
- {
- synchronized (usersDB)
- {
- Collection allUsers = new ArrayList();
- try
- {
- usersDB.open();
- Iterator users = usersDB.getUsers();
- while (users.hasNext())
- {
- User user = (User) users.next();
- Iterator roles = user.getRoles();
- while (roles.hasNext())
- {
- Role role = (Role) roles.next();
- if (role.getRolename().trim().equals(roleName))
- {
- allUsers.add(user.getUsername());
- }
- }
- }
- usersDB.close();
- } catch (Exception e)
- {
- }
- return allUsers;
- }
- }
-
- public void deleteUser(String user)
- {
- synchronized (usersDB)
- {
- try
- {
- usersDB.open();
- Iterator users = usersDB.getUsers();
- while (users.hasNext())
- {
- User tomcatUser = (User) users.next();
- if (tomcatUser.getUsername().equals(user))
- {
- usersDB.removeUser(tomcatUser);
- // FIXME: delete all the lesson tracking property files
- break;
- }
- }
- usersDB.close();
-
- } catch (Exception e)
- {
- }
- }
- }
-
- /**
- * Gets the lessonTracker attribute of the UserTracker object
- *
- * @param screen
- * Description of the Parameter
- * @param userName
- * Description of the Parameter
- * @return The lessonTracker value
- */
- public LessonTracker getLessonTracker(WebSession s, Screen screen)
- {
- return getLessonTracker(s, s.getUserName(), screen);
- }
-
- public LessonTracker getLessonTracker(WebSession s, String user, Screen screen)
- {
- HashMap usermap = getUserMap(user);
- LessonTracker tracker = (LessonTracker) usermap.get(screen.getTitle());
- if (tracker == null)
- {
- // Creates a new lesson tracker, if one does not exist on disk.
- tracker = LessonTracker.load(s, user, screen);
- usermap.put(screen.getTitle(), tracker);
- }
- // System.out.println( "User: [" + userName + "] UserTracker:getLessonTracker() LTH " +
- // tracker.hashCode() + " for " + screen );
- return tracker;
- }
-
- /**
- * Gets the status attribute of the UserTracker object
- *
- * @param screen
- * Description of the Parameter
- * @param userName
- * Description of the Parameter
- * @return The status value
- */
- public String getStatus(WebSession s, Screen screen)
- {
- return ("User [" + s.getUserName() + "] has accessed " + screen + " UserTracker:getStatus()LTH = " + getLessonTracker(
- s,
- screen)
- .hashCode());
- }
-
- /**
- * Gets the userMap attribute of the UserTracker object
- *
- * @param userName
- * Description of the Parameter
- * @return The userMap value
- */
- private HashMap getUserMap(String userName)
- {
-
- HashMap usermap = storage.get(userName);
-
- if (usermap == null)
- {
-
- usermap = new HashMap();
-
- storage.put(userName, usermap);
-
- }
-
- return (usermap);
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- public static synchronized UserTracker instance()
- {
-
- if (instance == null)
- {
-
- instance = new UserTracker();
-
- }
-
- return instance;
- }
-
- /**
- * Description of the Method
- *
- * @param screen
- * Description of the Parameter
- * @param s
- * Description of the Parameter
- */
- public void update(WebSession s, Screen screen)
- {
-
- LessonTracker tracker = getLessonTracker(s, screen);
-
- // System.out.println( "User [" + s.getUserName() + "] TRACKER: updating " + screen +
- // " LTH " + tracker.hashCode() );
- tracker.store(s, screen);
-
- HashMap usermap = getUserMap(s.getUserName());
- usermap.put(screen.getTitle(), tracker);
-
- }
-
-}
+
+package org.owasp.webgoat.session;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Bruce Mayhew WebGoat
+ * @since October 29, 2003
+ * @version $Id: $Id
+ */
+public class UserTracker
+{
+
+ private static UserTracker instance;
+
+ // FIXME: persist this somehow!
+
+ private static HashMap> storage = new HashMap>();
+
+ private static UserDatabase usersDB = new UserDatabase();
+
+ /**
+ * Constructor for the UserTracker object
+ */
+ private UserTracker()
+ {
+ }
+
+ /**
+ * Gets the completed attribute of the UserTracker object
+ *
+ * @param userName
+ * Description of the Parameter
+ * @return The completed value
+ */
+ public int getCompleted(String userName)
+ {
+
+ HashMap usermap = getUserMap(userName);
+
+ Iterator i = usermap.entrySet().iterator();
+
+ int count = 0;
+
+ while (i.hasNext())
+ {
+
+ Map.Entry entry = (Map.Entry) i.next();
+
+ int value = ((Integer) entry.getValue()).intValue();
+
+ if (value > 5)
+ {
+ count++;
+ }
+
+ }
+
+ return count;
+ }
+
+ /**
+ * Gets the users attribute of the UserTracker object
+ *
+ * @return The users value
+ */
+ public Collection getUsers()
+ {
+ return storage.keySet();
+ }
+
+ /**
+ * getAllUsers.
+ *
+ * @param roleName a {@link java.lang.String} object.
+ * @return a {@link java.util.Collection} object.
+ */
+ public Collection getAllUsers(String roleName)
+ {
+ synchronized (usersDB)
+ {
+ Collection allUsers = new ArrayList();
+ try
+ {
+ usersDB.open();
+ Iterator users = usersDB.getUsers();
+ while (users.hasNext())
+ {
+ User user = (User) users.next();
+ Iterator roles = user.getRoles();
+ while (roles.hasNext())
+ {
+ Role role = (Role) roles.next();
+ if (role.getRolename().trim().equals(roleName))
+ {
+ allUsers.add(user.getUsername());
+ }
+ }
+ }
+ usersDB.close();
+ } catch (Exception e)
+ {
+ }
+ return allUsers;
+ }
+ }
+
+ /**
+ * deleteUser.
+ *
+ * @param user a {@link java.lang.String} object.
+ */
+ public void deleteUser(String user)
+ {
+ synchronized (usersDB)
+ {
+ try
+ {
+ usersDB.open();
+ Iterator users = usersDB.getUsers();
+ while (users.hasNext())
+ {
+ User tomcatUser = (User) users.next();
+ if (tomcatUser.getUsername().equals(user))
+ {
+ usersDB.removeUser(tomcatUser);
+ // FIXME: delete all the lesson tracking property files
+ break;
+ }
+ }
+ usersDB.close();
+
+ } catch (Exception e)
+ {
+ }
+ }
+ }
+
+ /**
+ * Gets the lessonTracker attribute of the UserTracker object
+ *
+ * @param screen
+ * Description of the Parameter
+ * @return The lessonTracker value
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ */
+ public LessonTracker getLessonTracker(WebSession s, Screen screen)
+ {
+ return getLessonTracker(s, s.getUserName(), screen);
+ }
+
+ /**
+ * getLessonTracker.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @param user a {@link java.lang.String} object.
+ * @param screen a {@link org.owasp.webgoat.session.Screen} object.
+ * @return a {@link org.owasp.webgoat.session.LessonTracker} object.
+ */
+ public LessonTracker getLessonTracker(WebSession s, String user, Screen screen)
+ {
+ HashMap usermap = getUserMap(user);
+ LessonTracker tracker = (LessonTracker) usermap.get(screen.getTitle());
+ if (tracker == null)
+ {
+ // Creates a new lesson tracker, if one does not exist on disk.
+ tracker = LessonTracker.load(s, user, screen);
+ usermap.put(screen.getTitle(), tracker);
+ }
+ // System.out.println( "User: [" + userName + "] UserTracker:getLessonTracker() LTH " +
+ // tracker.hashCode() + " for " + screen );
+ return tracker;
+ }
+
+ /**
+ * Gets the status attribute of the UserTracker object
+ *
+ * @param screen
+ * Description of the Parameter
+ * @return The status value
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ */
+ public String getStatus(WebSession s, Screen screen)
+ {
+ return ("User [" + s.getUserName() + "] has accessed " + screen + " UserTracker:getStatus()LTH = " + getLessonTracker(
+ s,
+ screen)
+ .hashCode());
+ }
+
+ /**
+ * Gets the userMap attribute of the UserTracker object
+ *
+ * @param userName
+ * Description of the Parameter
+ * @return The userMap value
+ */
+ private HashMap getUserMap(String userName)
+ {
+
+ HashMap usermap = storage.get(userName);
+
+ if (usermap == null)
+ {
+
+ usermap = new HashMap();
+
+ storage.put(userName, usermap);
+
+ }
+
+ return (usermap);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ public static synchronized UserTracker instance()
+ {
+
+ if (instance == null)
+ {
+
+ instance = new UserTracker();
+
+ }
+
+ return instance;
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param screen
+ * Description of the Parameter
+ * @param screen
+ * Description of the Parameter
+ * @param s
+ * Description of the Parameter
+ */
+ public void update(WebSession s, Screen screen)
+ {
+
+ LessonTracker tracker = getLessonTracker(s, screen);
+
+ // System.out.println( "User [" + s.getUserName() + "] TRACKER: updating " + screen +
+ // " LTH " + tracker.hashCode() );
+ tracker.store(s, screen);
+
+ HashMap usermap = getUserMap(s.getUserName());
+ usermap.put(screen.getTitle(), tracker);
+
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/ValidationException.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/ValidationException.java
index fa9789bc4..8af108b06 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/ValidationException.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/ValidationException.java
@@ -1,48 +1,59 @@
-
-package org.owasp.webgoat.session;
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public class ValidationException extends Exception
-{
-
- /**
- *
- */
- private static final long serialVersionUID = -8358754606830400708L;
-
- public ValidationException()
- {
- super();
- }
-
- public ValidationException(String message)
- {
- super(message);
- }
-}
+
+package org.owasp.webgoat.session;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public class ValidationException extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -8358754606830400708L;
+
+ /**
+ * Constructor for ValidationException.
+ */
+ public ValidationException()
+ {
+ super();
+ }
+
+ /**
+ * Constructor for ValidationException.
+ *
+ * @param message a {@link java.lang.String} object.
+ */
+ public ValidationException(String message)
+ {
+ super(message);
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/WebSession.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/WebSession.java
index 879c3af03..d750b4272 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/WebSession.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/WebSession.java
@@ -1,1051 +1,1268 @@
-package org.owasp.webgoat.session;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.security.Principal;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Vector;
-import javax.servlet.ServletContext;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-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.lessons.model.RequestParameter;
-import org.owasp.webgoat.util.BeanProvider;
-import org.owasp.webgoat.util.LabelManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect
- * Security
- * @author Bruce Mayhew WebGoat
- *
- * @created October 28, 2003
- */
-public class WebSession {
-
- final Logger logger = LoggerFactory.getLogger(WebSession.class);
-
- /**
- * Description of the Field
- */
- public final static String ADMIN = "admin";
-
- /**
- * Tomcat role for a webgoat user
- */
- public final static String WEBGOAT_USER = "ROLE_WEBGOAT_USER";
-
- /**
- * Tomcat role for a webgoat admin
- */
- public final static String WEBGOAT_ADMIN = "ROLE_WEBGOAT_ADMIN";
-
- /**
- * Description of the Field
- */
- public final static String CHALLENGE = "Challenge";
-
- /**
- * Description of the Field
- */
- public final static String COLOR = "color";
-
- public final static String COURSE = "course";
-
- /**
- * Description of the Field
- */
- public final static int ERROR = 0;
-
- public static final String STAGE = "stage";
-
- /**
- * Description of the Field
- */
- public final static String JSESSION_ID = "jsessionid";
-
- /**
- * Description of the Field
- */
- public final static String LOGOUT = "Logout";
-
- /**
- * Description of the Field
- */
- public final static String RESTART = "Restart";
-
- /**
- * Description of the Field
- */
- public final static String MENU = "menu";
-
- /**
- * Description of the Field
- */
- public final static String SCREEN = "Screen";
-
- /**
- * Description of the Field
- */
- public final static String SESSION = "websession";
-
- public final static String SHOWSOURCE = "ShowSource";
-
- public final static String SHOWSOLUTION = "ShowSolution";
-
- public final static String SHOWHINTS = "ShowHints";
-
- public final static String SHOW = "show";
-
- public final static String SHOW_NEXTHINT = "NextHint";
-
- public final static String SHOW_PREVIOUSHINT = "PreviousHint";
-
- public final static String SHOW_PARAMS = "Params";
-
- public final static String SHOW_COOKIES = "Cookies";
-
- public final static String SHOW_SOURCE = "Source";
-
- public final static String SHOW_SOLUTION = "Solution";
-
- public final static String DEBUG = "debug";
-
- public final static String LANGUAGE = "language";
-
- /**
- * Description of the Field
- */
- public final static int WELCOME = -1;
-
- private WebgoatContext webgoatContext;
-
- private ServletContext context = null;
-
- private Course course;
-
- private int currentScreen = WELCOME;
-
- private int previousScreen = ERROR;
-
- private int hintNum = -1;
-
- private boolean isAdmin = false;
-
- private boolean isHackedAdmin = false;
-
- private boolean isAuthenticated = false;
-
- private boolean isColor = false;
-
- private boolean isDebug = false;
-
- private boolean hasHackedHackableAdmin = false;
-
- private StringBuffer message = new StringBuffer("");
-
- private ParameterParser myParser;
-
- private HttpServletRequest request = null;
-
- private HttpServletResponse response = null;
-
- private String servletName;
-
- private HashMap session = new HashMap();
-
- private boolean showCookies = false;
-
- private boolean showParams = false;
-
- private boolean showRequest = false;
-
- private boolean showSource = false;
-
- private boolean showSolution = false;
-
- private boolean completedHackableAdmin = false;
-
- private int currentMenu;
-
- private String currentLanguage = null;
-
- private List cookiesOnLastRequest;
-
- private List parmsOnLastRequest;
-
- /**
- * Constructor for the WebSession object
- *
- * @param webgoatContext
- * @param context Description of the Parameter
- */
- public WebSession(WebgoatContext webgoatContext, ServletContext context) {
- this.webgoatContext = webgoatContext;
- // initialize from web.xml
- showParams = webgoatContext.isShowParams();
- showCookies = webgoatContext.isShowCookies();
- showSource = webgoatContext.isShowSource();
- showSolution = webgoatContext.isShowSolution();
- showRequest = webgoatContext.isShowRequest();
- currentLanguage = webgoatContext.getDefaultLanguage();
- this.context = context;
-
- course = new Course();
- course.loadCourses(webgoatContext, context, "/");
- }
-
- public static synchronized Connection getConnection(WebSession s) throws SQLException {
- return DatabaseUtilities.getConnection(s);
- }
-
- public static void returnConnection(WebSession s) {
- DatabaseUtilities.returnConnection(s.getUserName());
- }
-
- /**
- * Description of the Method
- *
- * @param key Description of the Parameter
- * @param value Description of the Parameter
- */
- public void add(String key, Object value) {
- session.put(key, value);
- }
-
- /**
- * Description of the Method
- */
- public void clearMessage() {
- message.setLength(0);
- }
-
- /**
- * Description of the Method
- */
- public void eatCookies() {
- Cookie[] cookies = request.getCookies();
-
- for (int loop = 0; loop < cookies.length; loop++) {
- if (!cookies[loop].getName().startsWith("JS")) {// skip jsessionid cookie
- cookies[loop].setMaxAge(0);// mark for deletion by browser
- response.addCookie(cookies[loop]);
- }
- }
- }
-
- /**
- * Description of the Method
- *
- * @param key Description of the Parameter
- * @return Description of the Return Value
- */
- public Object get(String key) {
- return (session.get(key));
- }
-
- /**
- * Gets the context attribute of the WebSession object
- *
- * @return The context value
- */
- public ServletContext getContext() {
- return context;
- }
-
- public List getRoles() {
- List roles = new ArrayList();
-
- roles.add(AbstractLesson.USER_ROLE);
- if (isAdmin()) {
- roles.add(AbstractLesson.ADMIN_ROLE);
- }
-
- return roles;
- }
-
- /**
- * 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;
-
- }
-
- public String getRole() {
-
- String role = "";
- if (isAdmin()) {
- role = AbstractLesson.ADMIN_ROLE;
- } else if (isHackedAdmin()) {
- role = AbstractLesson.HACKED_ADMIN_ROLE;
- } else if (isChallenge()) {
- role = AbstractLesson.CHALLENGE_ROLE;
- } else {
- role = AbstractLesson.USER_ROLE;
- }
-
- return role;
- }
-
- /**
- * Gets the course attribute of the WebSession object
- *
- * @return The course value
- */
- public Course getCourse() {
- return course;
- }
-
- public void setCourse(Course course) {
- this.course = course;
- }
-
- /**
- * Gets the currentScreen attribute of the WebSession object
- *
- * @return The currentScreen value
- */
- public int getCurrentScreen() {
- return (currentScreen);
- }
-
- public void setCurrentScreen(int screen) {
- currentScreen = screen;
- }
-
- public String getRestartLink() {
- return getCurrentLesson().getLink() + "&" + RESTART + "=" + getCurrentScreen();
- }
-
- public String getCurrentLink() {
- String thisLink = "attack";
- Enumeration e = request.getParameterNames();
- boolean isFirstParameter = true;
- while (e.hasMoreElements()) {
- String name = e.nextElement();
- if (isFirstParameter) {
- isFirstParameter = false;
- thisLink += "?";
- } else {
- thisLink += "&";
- }
- thisLink = thisLink + name + "=" + request.getParameter(name);
- }
-
- return thisLink;
- }
-
- public AbstractLesson getCurrentLesson() {
- return getCourse().getLesson(this, getCurrentScreen(), getRoles());
- }
-
- public AbstractLesson getLesson(int id) {
- return getCourse().getLesson(this, id, getRoles());
- }
-
- public List getLessons(Category category) {
- return getCourse().getLessons(this, category, getRoles());
- }
-
- /**
- * Gets the hint1 attribute of the WebSession object
- *
- * @return The hint1 value
- */
- private int getHintNum() {
- return (hintNum);
- }
-
- public String getHint() {
- String hint = null;
- int hints = getCurrentLesson().getHintCount(this);
- if (getHintNum() > hints) {
- hintNum = -1;
- }
- if (getHintNum() >= 0) // FIXME
- {
- hint = getCurrentLesson().getHint(this, getHintNum());
- }
-
- return hint;
- }
-
- public List getParams() {
- Vector params = null;
-
- if (showParams() && getParser() != null) {
- params = new Vector();
-
- Enumeration e = getParser().getParameterNames();
-
- while ((e != null) && e.hasMoreElements()) {
- String name = (String) e.nextElement();
- String[] values = getParser().getParameterValues(name);
-
- for (int loop = 0; (values != null) && (loop < values.length); loop++) {
- params.add(new Parameter(name, values[loop]));
- // params.add( name + " -> " + values[loop] );
- }
- }
-
- Collections.sort(params);
- }
-
- return params;
- }
-
- public List getCookies() {
- List cookies = null;
-
- if (showCookies()) {
- cookies = Arrays.asList(request.getCookies());
- }
-
- /*
- * List cookies = new Vector(); HttpServletRequest request = getRequest(); Cookie[] cookies
- * = request.getCookies(); if ( cookies.length == 0 ) { list.addElement( new LI(
- * "No Cookies" ) ); } for ( int i = 0; i < cookies.length; i++ ) { Cookie cookie =
- * cookies[i]; cookies.add(cookie); //list.addElement( new LI( cookie.getName() + " -> " +
- * cookie.getValue() ) ); }
- */
- return cookies;
- }
-
- /**
- * Gets the cookie attribute of the CookieScreen object
- *
- * @param s Description of the Parameter
- * @return The cookie value
- */
- public String getCookie(String cookieName) {
- Cookie[] cookies = getRequest().getCookies();
-
- for (int i = 0; i < cookies.length; i++) {
- if (cookies[i].getName().equalsIgnoreCase(cookieName)) {
- return (cookies[i].getValue());
- }
- }
-
- return (null);
- }
-
- public String getSource() {
- return "Sorry. No Java Source viewing available.";
- // return getCurrentLesson().getSource(this);
- }
-
- public String getSolution() {
- return "Sorry. No solution is available.";
- // return getCurrentLesson().getSolution(this);
- }
-
- public String getInstructions() {
- return getCurrentLesson().getInstructions(this);
- }
-
- /**
- * Gets the message attribute of the WebSession object
- *
- * @return The message value
- */
- public String getMessage() {
- return (message.toString());
- }
-
- /**
- * Gets the parser attribute of the WebSession object
- *
- * @return The parser value
- */
- public ParameterParser getParser() {
- return (myParser);
- }
-
- /**
- * Gets the previousScreen attribute of the WebSession object
- *
- * @return The previousScreen value
- */
- public int getPreviousScreen() {
- return (previousScreen);
- }
-
- /**
- * Gets the request attribute of the WebSession object
- *
- * @return The request value
- */
- public HttpServletRequest getRequest() {
- return request;
- }
-
- public void setRequest(HttpServletRequest request) {
- this.request = request;
- }
-
- /**
- * Gets the response attribute of the WebSession object
- *
- * @return The response value
- */
- public HttpServletResponse getResponse() {
- return response;
- }
-
- /**
- * Gets the servletName attribute of the WebSession object
- *
- * @return The servletName value
- */
- public String getServletName() {
- return (servletName);
- }
-
- /**
- * Gets the sourceFile attribute of the WebSession object
- *
- * @param screen Description of the Parameter
- * @return The sourceFile value
- */
- public String getWebResource(String fileName) {
- // Note: doesn't work for admin path! Maybe with a ../ attack
- return (context.getRealPath(fileName));
- }
-
- /**
- * Gets the admin attribute of the WebSession object
- *
- * @return The admin value
- */
- public boolean isAdmin() {
- return (isAdmin);
- }
-
- /**
- * Gets the hackedAdmin attribute of the WebSession object
- *
- * @return The hackedAdmin value
- */
- public boolean isHackedAdmin() {
- return (isHackedAdmin);
- }
-
- /**
- * Has the user ever hacked the hackable admin
- *
- * @return The hackedAdmin value
- */
- public boolean completedHackableAdmin() {
- return (completedHackableAdmin);
- }
-
- /**
- * Gets the authenticated attribute of the WebSession object
- *
- * @return The authenticated value
- */
- public boolean isAuthenticated() {
- return (isAuthenticated);
- }
-
- private Map lessonSessions = new Hashtable();
-
- public boolean isAuthenticatedInLesson(AbstractLesson lesson) {
- boolean authenticated = false;
-
- LessonSession lessonSession = getLessonSession(lesson);
- if (lessonSession != null) {
- authenticated = lessonSession.isAuthenticated();
- }
- // System.out.println("Authenticated for lesson " + lesson + "? " + authenticated);
-
- return authenticated;
- }
-
- public boolean isAuthorizedInLesson(int employeeId, String functionId) {
- return getCurrentLesson().isAuthorized(this, employeeId, functionId);
- }
-
- public boolean isAuthorizedInLesson(String role, String functionId) {
- return getCurrentLesson().isAuthorized(this, role, functionId);
- }
-
- public int getUserIdInLesson() throws ParameterNotFoundException {
- return getCurrentLesson().getUserId(this);
- }
-
- public String getUserNameInLesson() throws ParameterNotFoundException {
- return getCurrentLesson().getUserName(this);
- }
-
- public void openLessonSession(AbstractLesson lesson) {
- System.out.println("Opening new lesson session for lesson " + lesson);
- LessonSession lessonSession = new LessonSession();
- lessonSessions.put(lesson, lessonSession);
- }
-
- public void closeLessonSession(AbstractLesson lesson) {
- lessonSessions.remove(lesson);
- }
-
- public LessonSession getLessonSession(AbstractLesson lesson) {
- return lessonSessions.get(lesson);
- }
-
- /**
- * Gets the challenge attribute of the WebSession object
- *
- * @return The challenge value
- */
- public boolean isChallenge() {
- if (getCurrentLesson() != null) {
- return (Category.CHALLENGE.equals(getCurrentLesson().getCategory()));
- }
- return false;
- }
-
- /**
- * Gets the color attribute of the WebSession object
- *
- * @return The color value
- */
- public boolean isColor() {
- return (isColor);
- }
-
- /**
- * Gets the screen attribute of the WebSession object
- *
- * @param value Description of the Parameter
- * @return The screen value
- */
- public boolean isScreen(int value) {
- return (getCurrentScreen() == value);
- }
-
- /**
- * Gets the user attribute of the WebSession object
- *
- * @return The user value
- */
- public boolean isUser() {
- return (!isAdmin && !isChallenge());
- }
-
- /**
- * Sets the message attribute of the WebSession object
- *
- * @param text The new message value
- */
- public void setMessage(String text) {
- message.append(" " + " * " + text);
- }
-
- public void setLineBreak(String text) {
- message.append(" " + text);
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- public boolean showCookies() {
- return (showCookies);
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- public boolean showParams() {
- return (showParams);
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- public boolean showRequest() {
- return (showRequest);
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- public boolean showSource() {
- return (showSource);
- }
-
- public boolean showSolution() {
- return (showSolution);
- }
-
- /**
- * Gets the userName attribute of the WebSession object
- *
- * @return The userName value
- */
- public String getUserName() {
- HttpServletRequest request = getRequest();
- if (request == null) {
- throw new RuntimeException("Could not find the ServletRequest in the web session");
- }
- Principal principal = request.getUserPrincipal();
- if (principal == null) {
- throw new RuntimeException("Could not find the Principal in the Servlet Request");
- }
- return principal.getName();
- }
-
- /**
- * Parse parameters from the given request, handle any servlet commands, and
- * update this session based on the parameters.
- *
- * @param request Description of the Parameter
- * @param response Description of the Parameter
- * @param name Description of the Parameter
- */
- public void update(HttpServletRequest request, HttpServletResponse response, String name) throws IOException {
- String content = null;
-
- clearMessage();
- this.request = request;
- this.response = response;
- this.servletName = name;
-
- if (myParser == null) {
- myParser = new ParameterParser(request);
- } else {
- myParser.update(request);
- }
-
- Locale locale = request.getLocale();
- if(locale != null) {
- LabelManager labelManager = BeanProvider.getBean("labelManager", LabelManager.class);
- labelManager.setLocale(locale);
- }
-
- // System.out.println("Current Screen 1: " + currentScreen );
- // System.out.println("Previous Screen 1: " + previousScreen );
- // FIXME: requires ?Logout=true
- // FIXME: doesn't work right -- no reauthentication
- // REMOVED - we have explicit logout now via spriing security
- /*
- if (myParser.getRawParameter(LOGOUT, null) != null) {
- System.out.println("Logout " + request.getUserPrincipal());
- eatCookies();
- request.getSession().invalidate();
- currentScreen = WELCOME;
- previousScreen = ERROR;
- }
- */
-
- // There are several scenarios where we want the first lesson to be loaded
- // 1) Previous screen is Welcome - Start of the course
- // 2) After a logout and after the session has been reinitialized
- if ((this.getPreviousScreen() == WebSession.WELCOME) || (getRequest().getSession(false) != null
- && // getRequest().getSession(false).isNew() &&
- this.getCurrentScreen() == WebSession.WELCOME && this.getPreviousScreen() == WebSession.ERROR)) {
- currentScreen = course.getFirstLesson().getScreenId();
- hintNum = -1;
- }
-
- // System.out.println("Current Screen 2: " + currentScreen );
- // System.out.println("Previous Screen 2: " + previousScreen );
- // update the screen variables
- previousScreen = currentScreen;
-
- try {
- // If the request is new there should be no parameters.
- // This can occur from a session timeout or a the starting of a new course.
- if (!request.getSession().isNew()) {
- currentScreen = myParser.getIntParameter(SCREEN, currentScreen);
- } else {
- if (!myParser.getRawParameter(SCREEN, "NULL").equals("NULL")) {
- this.setMessage("Session Timeout - Starting new Session.");
- }
- }
- } catch (Exception e) {
- }
-
- // clear variables when switching screens
- if (this.getCurrentScreen() != this.getPreviousScreen()) {
- if (webgoatContext.isDebug()) {
- setMessage("Changed to a new screen, clearing cookies and hints");
- }
- eatCookies();
- hintNum = -1;
- } else if (myParser.getRawParameter(STAGE, null) != null) {
- AbstractLesson al = getCurrentLesson();
- if (al instanceof SequentialLessonAdapter) {
- SequentialLessonAdapter sla = (SequentialLessonAdapter) al;
- int stage = myParser.getIntParameter(STAGE, sla.getStage(this));
- if (stage > 0 && stage <= sla.getStageCount()) {
- sla.setStage(this, stage);
- }
- } else if (al instanceof RandomLessonAdapter) {
- try {
- RandomLessonAdapter rla = (RandomLessonAdapter) al;
- if (!myParser.getRawParameter(STAGE).equals("null")) {
- int stage = myParser.getIntParameter(STAGE) - 1;
- String[] stages = rla.getStages();
- if (stages == null) {
- stages = new String[0];
- }
- if (stage >= 0 && stage < stages.length) {
- rla.setStage(this, stages[stage]);
- }
- } else {
- rla.setStage(this, null);
- }
- } catch (ParameterNotFoundException pnfe) {
- }
- }
- } // else update global variables for the current screen
- else {
- // Handle "restart" commands
- int lessonId = myParser.getIntParameter(RESTART, -1);
- if (lessonId != -1) {
- restartLesson(lessonId);
- }
- // if ( myParser.getBooleanParameter( RESTART, false ) )
- // {
- // getCurrentLesson().getLessonTracker( this ).getLessonProperties().setProperty(
- // CHALLENGE_STAGE, "1" );
- // }
-
- // Handle "show" commands
- String showCommand = myParser.getStringParameter(SHOW, null);
- if (showCommand != null) {
- if (showCommand.equalsIgnoreCase(SHOW_PARAMS)) {
- showParams = !showParams;
- } else if (showCommand.equalsIgnoreCase(SHOW_COOKIES)) {
- showCookies = !showCookies;
- } else if (showCommand.equalsIgnoreCase(SHOW_SOURCE)) {
- content = getSource();
- // showSource = true;
- } else if (showCommand.equalsIgnoreCase(SHOW_SOLUTION)) {
- content = getSolution();
- // showSource = true;
- } else if (showCommand.equalsIgnoreCase(SHOW_NEXTHINT)) {
- getNextHint();
- } else if (showCommand.equalsIgnoreCase(SHOW_PREVIOUSHINT)) {
- getPreviousHint();
- }
- }
-
- }
-
- isAdmin = request.isUserInRole(WEBGOAT_ADMIN);
- isHackedAdmin = myParser.getBooleanParameter(ADMIN, isAdmin);
- if (isHackedAdmin) {
- System.out.println("Hacked admin");
- hasHackedHackableAdmin = true;
- }
- isColor = myParser.getBooleanParameter(COLOR, isColor);
- isDebug = myParser.getBooleanParameter(DEBUG, isDebug);
-
- // System.out.println( "showParams:" + showParams );
- // System.out.println( "showSource:" + showSource );
- // System.out.println( "showSolution:" + showSolution );
- // System.out.println( "showCookies:" + showCookies );
- // System.out.println( "showRequest:" + showRequest );
- if (content != null) {
- response.setContentType("text/html");
- PrintWriter out = new PrintWriter(response.getOutputStream());
- out.print(content);
- out.flush();
- out.close();
- }
- }
-
- public void updateLastAttackRequestInfo(HttpServletRequest request) {
- // store cookies
- Cookie[] cookies = request.getCookies();
- if (cookies == null) {
- this.cookiesOnLastRequest = new ArrayList();
- } else {
- this.cookiesOnLastRequest = Arrays.asList(cookies);
- }
- // store parameters
- Map parmMap = request.getParameterMap();
- logger.info("PARM MAP: " + parmMap);
- if (parmMap == null) {
- this.parmsOnLastRequest = new ArrayList();
- } else {
- this.parmsOnLastRequest = new ArrayList();
- for (String name : parmMap.keySet()) {
- String[] values = parmMap.get(name);
- String delim = "";
- StringBuffer sb = new StringBuffer();
- if (values != null && values.length > 0) {
- for (String parm : values) {
- sb.append(delim).append(parm);
- delim = ",";
- }
- }
- RequestParameter parm = new RequestParameter(name, sb.toString());
- this.parmsOnLastRequest.add(parm);
- }
- }
- }
-
- public void restartLesson(int lessonId) {
- AbstractLesson al = getLesson(lessonId);
- System.out.println("Restarting lesson: " + al);
- al.getLessonTracker(this).setCompleted(false);
- if (al instanceof SequentialLessonAdapter) {
- SequentialLessonAdapter sla = (SequentialLessonAdapter) al;
- sla.getLessonTracker(this).setStage(1);
- } else if (al instanceof RandomLessonAdapter) {
- RandomLessonAdapter rla = (RandomLessonAdapter) al;
- rla.setStage(this, rla.getStages()[0]);
- }
- }
-
- /**
- * @param string
- */
- public void setHasHackableAdmin(String role) {
- hasHackedHackableAdmin = (AbstractLesson.HACKED_ADMIN_ROLE.equals(role) & hasHackedHackableAdmin);
-
- // if the user got the Admin=true parameter correct AND they accessed an admin screen
- if (hasHackedHackableAdmin) {
- completedHackableAdmin = true;
- }
- }
-
- /**
- * @return Returns the isDebug.
- */
- public boolean isDebug() {
- return isDebug;
- }
-
- /**
- * @param header - request header value to return
- * @return
- */
- public String getHeader(String header) {
- return getRequest().getHeader(header);
- }
-
- public String getNextHint() {
- String hint = null;
-
- // FIXME
- int maxHints = getCurrentLesson().getHintCount(this);
- if (hintNum < maxHints - 1) {
- hintNum++;
-
- // Hints are indexed from 0
- getCurrentLesson().getLessonTracker(this).setMaxHintLevel(getHintNum() + 1);
-
- hint = (String) getCurrentLesson().getHint(this, getHintNum());
- }
-
- return hint;
- }
-
- public String getPreviousHint() {
- String hint = null;
-
- if (hintNum > 0) {
- hintNum--;
-
- // Hints are indexed from 0
- getCurrentLesson().getLessonTracker(this).setMaxHintLevel(getHintNum() + 1);
-
- hint = (String) getCurrentLesson().getHint(this, getHintNum());
- }
-
- return hint;
- }
-
- public void setCurrentMenu(Integer ranking) {
- currentMenu = ranking.intValue();
- }
-
- public int getCurrentMenu() {
- return currentMenu;
- }
-
- public WebgoatContext getWebgoatContext() {
- return webgoatContext;
- }
-
- public String getCurrrentLanguage() {
- return currentLanguage;
- }
-
- /**
- * @return the cookiesOnLastRequest
- */
- public List getCookiesOnLastRequest() {
- return cookiesOnLastRequest;
- }
-
- /**
- * @return the parmsOnLastRequest
- */
- public List getParmsOnLastRequest() {
- return parmsOnLastRequest;
- }
-
-}
+package org.owasp.webgoat.session;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.security.Principal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Vector;
+import javax.servlet.ServletContext;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+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.lessons.model.RequestParameter;
+import org.owasp.webgoat.util.BeanProvider;
+import org.owasp.webgoat.util.LabelManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project
+ * utility. For details, please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
+ * for free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect
+ * Security
+ * @author Bruce Mayhew WebGoat
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class WebSession {
+
+ final Logger logger = LoggerFactory.getLogger(WebSession.class);
+
+ /**
+ * Description of the Field
+ */
+ public final static String ADMIN = "admin";
+
+ /**
+ * Tomcat role for a webgoat user
+ */
+ public final static String WEBGOAT_USER = "ROLE_WEBGOAT_USER";
+
+ /**
+ * Tomcat role for a webgoat admin
+ */
+ public final static String WEBGOAT_ADMIN = "ROLE_WEBGOAT_ADMIN";
+
+ /**
+ * Description of the Field
+ */
+ public final static String CHALLENGE = "Challenge";
+
+ /**
+ * Description of the Field
+ */
+ public final static String COLOR = "color";
+
+ /** Constant COURSE="course"
*/
+ public final static String COURSE = "course";
+
+ /**
+ * Description of the Field
+ */
+ public final static int ERROR = 0;
+
+ /** Constant STAGE="stage"
*/
+ public static final String STAGE = "stage";
+
+ /**
+ * Description of the Field
+ */
+ public final static String JSESSION_ID = "jsessionid";
+
+ /**
+ * Description of the Field
+ */
+ public final static String LOGOUT = "Logout";
+
+ /**
+ * Description of the Field
+ */
+ public final static String RESTART = "Restart";
+
+ /**
+ * Description of the Field
+ */
+ public final static String MENU = "menu";
+
+ /**
+ * Description of the Field
+ */
+ public final static String SCREEN = "Screen";
+
+ /**
+ * Description of the Field
+ */
+ public final static String SESSION = "websession";
+
+ /** Constant SHOWSOURCE="ShowSource"
*/
+ public final static String SHOWSOURCE = "ShowSource";
+
+ /** Constant SHOWSOLUTION="ShowSolution"
*/
+ public final static String SHOWSOLUTION = "ShowSolution";
+
+ /** Constant SHOWHINTS="ShowHints"
*/
+ public final static String SHOWHINTS = "ShowHints";
+
+ /** Constant SHOW="show"
*/
+ public final static String SHOW = "show";
+
+ /** Constant SHOW_NEXTHINT="NextHint"
*/
+ public final static String SHOW_NEXTHINT = "NextHint";
+
+ /** Constant SHOW_PREVIOUSHINT="PreviousHint"
*/
+ public final static String SHOW_PREVIOUSHINT = "PreviousHint";
+
+ /** Constant SHOW_PARAMS="Params"
*/
+ public final static String SHOW_PARAMS = "Params";
+
+ /** Constant SHOW_COOKIES="Cookies"
*/
+ public final static String SHOW_COOKIES = "Cookies";
+
+ /** Constant SHOW_SOURCE="Source"
*/
+ public final static String SHOW_SOURCE = "Source";
+
+ /** Constant SHOW_SOLUTION="Solution"
*/
+ public final static String SHOW_SOLUTION = "Solution";
+
+ /** Constant DEBUG="debug"
*/
+ public final static String DEBUG = "debug";
+
+ /** Constant LANGUAGE="language"
*/
+ public final static String LANGUAGE = "language";
+
+ /**
+ * Description of the Field
+ */
+ public final static int WELCOME = -1;
+
+ private WebgoatContext webgoatContext;
+
+ private ServletContext context = null;
+
+ private Course course;
+
+ private int currentScreen = WELCOME;
+
+ private int previousScreen = ERROR;
+
+ private int hintNum = -1;
+
+ private boolean isAdmin = false;
+
+ private boolean isHackedAdmin = false;
+
+ private boolean isAuthenticated = false;
+
+ private boolean isColor = false;
+
+ private boolean isDebug = false;
+
+ private boolean hasHackedHackableAdmin = false;
+
+ private StringBuffer message = new StringBuffer("");
+
+ private ParameterParser myParser;
+
+ private HttpServletRequest request = null;
+
+ private HttpServletResponse response = null;
+
+ private String servletName;
+
+ private HashMap session = new HashMap();
+
+ private boolean showCookies = false;
+
+ private boolean showParams = false;
+
+ private boolean showRequest = false;
+
+ private boolean showSource = false;
+
+ private boolean showSolution = false;
+
+ private boolean completedHackableAdmin = false;
+
+ private int currentMenu;
+
+ private String currentLanguage = null;
+
+ private List cookiesOnLastRequest;
+
+ private List parmsOnLastRequest;
+
+ /**
+ * Constructor for the WebSession object
+ *
+ * @param webgoatContext a {@link org.owasp.webgoat.session.WebgoatContext} object.
+ * @param context Description of the Parameter
+ */
+ public WebSession(WebgoatContext webgoatContext, ServletContext context) {
+ this.webgoatContext = webgoatContext;
+ // initialize from web.xml
+ showParams = webgoatContext.isShowParams();
+ showCookies = webgoatContext.isShowCookies();
+ showSource = webgoatContext.isShowSource();
+ showSolution = webgoatContext.isShowSolution();
+ showRequest = webgoatContext.isShowRequest();
+ currentLanguage = webgoatContext.getDefaultLanguage();
+ this.context = context;
+
+ course = new Course();
+ course.loadCourses(webgoatContext, context, "/");
+ }
+
+ /**
+ * getConnection.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ * @return a {@link java.sql.Connection} object.
+ * @throws java.sql.SQLException if any.
+ */
+ public static synchronized Connection getConnection(WebSession s) throws SQLException {
+ return DatabaseUtilities.getConnection(s);
+ }
+
+ /**
+ * returnConnection.
+ *
+ * @param s a {@link org.owasp.webgoat.session.WebSession} object.
+ */
+ public static void returnConnection(WebSession s) {
+ DatabaseUtilities.returnConnection(s.getUserName());
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param key Description of the Parameter
+ * @param value Description of the Parameter
+ */
+ public void add(String key, Object value) {
+ session.put(key, value);
+ }
+
+ /**
+ * Description of the Method
+ */
+ public void clearMessage() {
+ message.setLength(0);
+ }
+
+ /**
+ * Description of the Method
+ */
+ public void eatCookies() {
+ Cookie[] cookies = request.getCookies();
+
+ for (int loop = 0; loop < cookies.length; loop++) {
+ if (!cookies[loop].getName().startsWith("JS")) {// skip jsessionid cookie
+ cookies[loop].setMaxAge(0);// mark for deletion by browser
+ response.addCookie(cookies[loop]);
+ }
+ }
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param key Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public Object get(String key) {
+ return (session.get(key));
+ }
+
+ /**
+ * Gets the context attribute of the WebSession object
+ *
+ * @return The context value
+ */
+ public ServletContext getContext() {
+ return context;
+ }
+
+ /**
+ * getRoles.
+ *
+ * @return a {@link java.util.List} object.
+ */
+ public List getRoles() {
+ List roles = new ArrayList();
+
+ roles.add(AbstractLesson.USER_ROLE);
+ if (isAdmin()) {
+ roles.add(AbstractLesson.ADMIN_ROLE);
+ }
+
+ return roles;
+ }
+
+ /**
+ * 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 a boolean.
+ */
+ public void setAdmin(boolean state) {
+ isAdmin = state;
+
+ }
+
+ /**
+ * getRole.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getRole() {
+
+ String role = "";
+ if (isAdmin()) {
+ role = AbstractLesson.ADMIN_ROLE;
+ } else if (isHackedAdmin()) {
+ role = AbstractLesson.HACKED_ADMIN_ROLE;
+ } else if (isChallenge()) {
+ role = AbstractLesson.CHALLENGE_ROLE;
+ } else {
+ role = AbstractLesson.USER_ROLE;
+ }
+
+ return role;
+ }
+
+ /**
+ * Gets the course attribute of the WebSession object
+ *
+ * @return The course value
+ */
+ public Course getCourse() {
+ return course;
+ }
+
+ /**
+ * Setter for the field course
.
+ *
+ * @param course a {@link org.owasp.webgoat.session.Course} object.
+ */
+ public void setCourse(Course course) {
+ this.course = course;
+ }
+
+ /**
+ * Gets the currentScreen attribute of the WebSession object
+ *
+ * @return The currentScreen value
+ */
+ public int getCurrentScreen() {
+ return (currentScreen);
+ }
+
+ /**
+ * Setter for the field currentScreen
.
+ *
+ * @param screen a int.
+ */
+ public void setCurrentScreen(int screen) {
+ currentScreen = screen;
+ }
+
+ /**
+ * getRestartLink.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getRestartLink() {
+ return getCurrentLesson().getLink() + "&" + RESTART + "=" + getCurrentScreen();
+ }
+
+ /**
+ * getCurrentLink.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getCurrentLink() {
+ String thisLink = "attack";
+ Enumeration e = request.getParameterNames();
+ boolean isFirstParameter = true;
+ while (e.hasMoreElements()) {
+ String name = e.nextElement();
+ if (isFirstParameter) {
+ isFirstParameter = false;
+ thisLink += "?";
+ } else {
+ thisLink += "&";
+ }
+ thisLink = thisLink + name + "=" + request.getParameter(name);
+ }
+
+ return thisLink;
+ }
+
+ /**
+ * getCurrentLesson.
+ *
+ * @return a {@link org.owasp.webgoat.lessons.AbstractLesson} object.
+ */
+ public AbstractLesson getCurrentLesson() {
+ return getCourse().getLesson(this, getCurrentScreen(), getRoles());
+ }
+
+ /**
+ * getLesson.
+ *
+ * @param id a int.
+ * @return a {@link org.owasp.webgoat.lessons.AbstractLesson} object.
+ */
+ public AbstractLesson getLesson(int id) {
+ return getCourse().getLesson(this, id, getRoles());
+ }
+
+ /**
+ * getLessons.
+ *
+ * @param category a {@link org.owasp.webgoat.lessons.Category} object.
+ * @return a {@link java.util.List} object.
+ */
+ public List getLessons(Category category) {
+ return getCourse().getLessons(this, category, getRoles());
+ }
+
+ /**
+ * Gets the hint1 attribute of the WebSession object
+ *
+ * @return The hint1 value
+ */
+ private int getHintNum() {
+ return (hintNum);
+ }
+
+ /**
+ * getHint.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getHint() {
+ String hint = null;
+ int hints = getCurrentLesson().getHintCount(this);
+ if (getHintNum() > hints) {
+ hintNum = -1;
+ }
+ if (getHintNum() >= 0) // FIXME
+ {
+ hint = getCurrentLesson().getHint(this, getHintNum());
+ }
+
+ return hint;
+ }
+
+ /**
+ * getParams.
+ *
+ * @return a {@link java.util.List} object.
+ */
+ public List getParams() {
+ Vector params = null;
+
+ if (showParams() && getParser() != null) {
+ params = new Vector();
+
+ Enumeration e = getParser().getParameterNames();
+
+ while ((e != null) && e.hasMoreElements()) {
+ String name = (String) e.nextElement();
+ String[] values = getParser().getParameterValues(name);
+
+ for (int loop = 0; (values != null) && (loop < values.length); loop++) {
+ params.add(new Parameter(name, values[loop]));
+ // params.add( name + " -> " + values[loop] );
+ }
+ }
+
+ Collections.sort(params);
+ }
+
+ return params;
+ }
+
+ /**
+ * getCookies.
+ *
+ * @return a {@link java.util.List} object.
+ */
+ public List getCookies() {
+ List cookies = null;
+
+ if (showCookies()) {
+ cookies = Arrays.asList(request.getCookies());
+ }
+
+ /*
+ * List cookies = new Vector(); HttpServletRequest request = getRequest(); Cookie[] cookies
+ * = request.getCookies(); if ( cookies.length == 0 ) { list.addElement( new LI(
+ * "No Cookies" ) ); } for ( int i = 0; i < cookies.length; i++ ) { Cookie cookie =
+ * cookies[i]; cookies.add(cookie); //list.addElement( new LI( cookie.getName() + " -> " +
+ * cookie.getValue() ) ); }
+ */
+ return cookies;
+ }
+
+ /**
+ * Gets the cookie attribute of the CookieScreen object
+ *
+ * @return The cookie value
+ * @param cookieName a {@link java.lang.String} object.
+ */
+ public String getCookie(String cookieName) {
+ Cookie[] cookies = getRequest().getCookies();
+
+ for (int i = 0; i < cookies.length; i++) {
+ if (cookies[i].getName().equalsIgnoreCase(cookieName)) {
+ return (cookies[i].getValue());
+ }
+ }
+
+ return (null);
+ }
+
+ /**
+ * getSource.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getSource() {
+ return "Sorry. No Java Source viewing available.";
+ // return getCurrentLesson().getSource(this);
+ }
+
+ /**
+ * getSolution.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getSolution() {
+ return "Sorry. No solution is available.";
+ // return getCurrentLesson().getSolution(this);
+ }
+
+ /**
+ * getInstructions.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getInstructions() {
+ return getCurrentLesson().getInstructions(this);
+ }
+
+ /**
+ * Gets the message attribute of the WebSession object
+ *
+ * @return The message value
+ */
+ public String getMessage() {
+ return (message.toString());
+ }
+
+ /**
+ * Gets the parser attribute of the WebSession object
+ *
+ * @return The parser value
+ */
+ public ParameterParser getParser() {
+ return (myParser);
+ }
+
+ /**
+ * Gets the previousScreen attribute of the WebSession object
+ *
+ * @return The previousScreen value
+ */
+ public int getPreviousScreen() {
+ return (previousScreen);
+ }
+
+ /**
+ * Gets the request attribute of the WebSession object
+ *
+ * @return The request value
+ */
+ public HttpServletRequest getRequest() {
+ return request;
+ }
+
+ /**
+ * Setter for the field request
.
+ *
+ * @param request a {@link javax.servlet.http.HttpServletRequest} object.
+ */
+ public void setRequest(HttpServletRequest request) {
+ this.request = request;
+ }
+
+ /**
+ * Gets the response attribute of the WebSession object
+ *
+ * @return The response value
+ */
+ public HttpServletResponse getResponse() {
+ return response;
+ }
+
+ /**
+ * Gets the servletName attribute of the WebSession object
+ *
+ * @return The servletName value
+ */
+ public String getServletName() {
+ return (servletName);
+ }
+
+ /**
+ * Gets the sourceFile attribute of the WebSession object
+ *
+ * @return The sourceFile value
+ * @param fileName a {@link java.lang.String} object.
+ */
+ public String getWebResource(String fileName) {
+ // Note: doesn't work for admin path! Maybe with a ../ attack
+ return (context.getRealPath(fileName));
+ }
+
+ /**
+ * Gets the admin attribute of the WebSession object
+ *
+ * @return The admin value
+ */
+ public boolean isAdmin() {
+ return (isAdmin);
+ }
+
+ /**
+ * Gets the hackedAdmin attribute of the WebSession object
+ *
+ * @return The hackedAdmin value
+ */
+ public boolean isHackedAdmin() {
+ return (isHackedAdmin);
+ }
+
+ /**
+ * Has the user ever hacked the hackable admin
+ *
+ * @return The hackedAdmin value
+ */
+ public boolean completedHackableAdmin() {
+ return (completedHackableAdmin);
+ }
+
+ /**
+ * Gets the authenticated attribute of the WebSession object
+ *
+ * @return The authenticated value
+ */
+ public boolean isAuthenticated() {
+ return (isAuthenticated);
+ }
+
+ private Map lessonSessions = new Hashtable();
+
+ /**
+ * isAuthenticatedInLesson.
+ *
+ * @param lesson a {@link org.owasp.webgoat.lessons.AbstractLesson} object.
+ * @return a boolean.
+ */
+ public boolean isAuthenticatedInLesson(AbstractLesson lesson) {
+ boolean authenticated = false;
+
+ LessonSession lessonSession = getLessonSession(lesson);
+ if (lessonSession != null) {
+ authenticated = lessonSession.isAuthenticated();
+ }
+ // System.out.println("Authenticated for lesson " + lesson + "? " + authenticated);
+
+ return authenticated;
+ }
+
+ /**
+ * isAuthorizedInLesson.
+ *
+ * @param employeeId a int.
+ * @param functionId a {@link java.lang.String} object.
+ * @return a boolean.
+ */
+ public boolean isAuthorizedInLesson(int employeeId, String functionId) {
+ return getCurrentLesson().isAuthorized(this, employeeId, functionId);
+ }
+
+ /**
+ * isAuthorizedInLesson.
+ *
+ * @param role a {@link java.lang.String} object.
+ * @param functionId a {@link java.lang.String} object.
+ * @return a boolean.
+ */
+ public boolean isAuthorizedInLesson(String role, String functionId) {
+ return getCurrentLesson().isAuthorized(this, role, functionId);
+ }
+
+ /**
+ * getUserIdInLesson.
+ *
+ * @return a int.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public int getUserIdInLesson() throws ParameterNotFoundException {
+ return getCurrentLesson().getUserId(this);
+ }
+
+ /**
+ * getUserNameInLesson.
+ *
+ * @return a {@link java.lang.String} object.
+ * @throws org.owasp.webgoat.session.ParameterNotFoundException if any.
+ */
+ public String getUserNameInLesson() throws ParameterNotFoundException {
+ return getCurrentLesson().getUserName(this);
+ }
+
+ /**
+ * openLessonSession.
+ *
+ * @param lesson a {@link org.owasp.webgoat.lessons.AbstractLesson} object.
+ */
+ public void openLessonSession(AbstractLesson lesson) {
+ System.out.println("Opening new lesson session for lesson " + lesson);
+ LessonSession lessonSession = new LessonSession();
+ lessonSessions.put(lesson, lessonSession);
+ }
+
+ /**
+ * closeLessonSession.
+ *
+ * @param lesson a {@link org.owasp.webgoat.lessons.AbstractLesson} object.
+ */
+ public void closeLessonSession(AbstractLesson lesson) {
+ lessonSessions.remove(lesson);
+ }
+
+ /**
+ * getLessonSession.
+ *
+ * @param lesson a {@link org.owasp.webgoat.lessons.AbstractLesson} object.
+ * @return a {@link org.owasp.webgoat.session.LessonSession} object.
+ */
+ public LessonSession getLessonSession(AbstractLesson lesson) {
+ return lessonSessions.get(lesson);
+ }
+
+ /**
+ * Gets the challenge attribute of the WebSession object
+ *
+ * @return The challenge value
+ */
+ public boolean isChallenge() {
+ if (getCurrentLesson() != null) {
+ return (Category.CHALLENGE.equals(getCurrentLesson().getCategory()));
+ }
+ return false;
+ }
+
+ /**
+ * Gets the color attribute of the WebSession object
+ *
+ * @return The color value
+ */
+ public boolean isColor() {
+ return (isColor);
+ }
+
+ /**
+ * Gets the screen attribute of the WebSession object
+ *
+ * @param value Description of the Parameter
+ * @return The screen value
+ */
+ public boolean isScreen(int value) {
+ return (getCurrentScreen() == value);
+ }
+
+ /**
+ * Gets the user attribute of the WebSession object
+ *
+ * @return The user value
+ */
+ public boolean isUser() {
+ return (!isAdmin && !isChallenge());
+ }
+
+ /**
+ * Sets the message attribute of the WebSession object
+ *
+ * @param text The new message value
+ */
+ public void setMessage(String text) {
+ message.append(" " + " * " + text);
+ }
+
+ /**
+ * setLineBreak.
+ *
+ * @param text a {@link java.lang.String} object.
+ */
+ public void setLineBreak(String text) {
+ message.append(" " + text);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ public boolean showCookies() {
+ return (showCookies);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ public boolean showParams() {
+ return (showParams);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ public boolean showRequest() {
+ return (showRequest);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ public boolean showSource() {
+ return (showSource);
+ }
+
+ /**
+ * showSolution.
+ *
+ * @return a boolean.
+ */
+ public boolean showSolution() {
+ return (showSolution);
+ }
+
+ /**
+ * Gets the userName attribute of the WebSession object
+ *
+ * @return The userName value
+ */
+ public String getUserName() {
+ HttpServletRequest request = getRequest();
+ if (request == null) {
+ throw new RuntimeException("Could not find the ServletRequest in the web session");
+ }
+ Principal principal = request.getUserPrincipal();
+ if (principal == null) {
+ throw new RuntimeException("Could not find the Principal in the Servlet Request");
+ }
+ return principal.getName();
+ }
+
+ /**
+ * Parse parameters from the given request, handle any servlet commands, and
+ * update this session based on the parameters.
+ *
+ * @param request Description of the Parameter
+ * @param response Description of the Parameter
+ * @param name Description of the Parameter
+ * @throws java.io.IOException if any.
+ */
+ public void update(HttpServletRequest request, HttpServletResponse response, String name) throws IOException {
+ String content = null;
+
+ clearMessage();
+ this.request = request;
+ this.response = response;
+ this.servletName = name;
+
+ if (myParser == null) {
+ myParser = new ParameterParser(request);
+ } else {
+ myParser.update(request);
+ }
+
+ Locale locale = request.getLocale();
+ if(locale != null) {
+ LabelManager labelManager = BeanProvider.getBean("labelManager", LabelManager.class);
+ labelManager.setLocale(locale);
+ }
+
+ // System.out.println("Current Screen 1: " + currentScreen );
+ // System.out.println("Previous Screen 1: " + previousScreen );
+ // FIXME: requires ?Logout=true
+ // FIXME: doesn't work right -- no reauthentication
+ // REMOVED - we have explicit logout now via spriing security
+ /*
+ if (myParser.getRawParameter(LOGOUT, null) != null) {
+ System.out.println("Logout " + request.getUserPrincipal());
+ eatCookies();
+ request.getSession().invalidate();
+ currentScreen = WELCOME;
+ previousScreen = ERROR;
+ }
+ */
+
+ // There are several scenarios where we want the first lesson to be loaded
+ // 1) Previous screen is Welcome - Start of the course
+ // 2) After a logout and after the session has been reinitialized
+ if ((this.getPreviousScreen() == WebSession.WELCOME) || (getRequest().getSession(false) != null
+ && // getRequest().getSession(false).isNew() &&
+ this.getCurrentScreen() == WebSession.WELCOME && this.getPreviousScreen() == WebSession.ERROR)) {
+ currentScreen = course.getFirstLesson().getScreenId();
+ hintNum = -1;
+ }
+
+ // System.out.println("Current Screen 2: " + currentScreen );
+ // System.out.println("Previous Screen 2: " + previousScreen );
+ // update the screen variables
+ previousScreen = currentScreen;
+
+ try {
+ // If the request is new there should be no parameters.
+ // This can occur from a session timeout or a the starting of a new course.
+ if (!request.getSession().isNew()) {
+ currentScreen = myParser.getIntParameter(SCREEN, currentScreen);
+ } else {
+ if (!myParser.getRawParameter(SCREEN, "NULL").equals("NULL")) {
+ this.setMessage("Session Timeout - Starting new Session.");
+ }
+ }
+ } catch (Exception e) {
+ }
+
+ // clear variables when switching screens
+ if (this.getCurrentScreen() != this.getPreviousScreen()) {
+ if (webgoatContext.isDebug()) {
+ setMessage("Changed to a new screen, clearing cookies and hints");
+ }
+ eatCookies();
+ hintNum = -1;
+ } else if (myParser.getRawParameter(STAGE, null) != null) {
+ AbstractLesson al = getCurrentLesson();
+ if (al instanceof SequentialLessonAdapter) {
+ SequentialLessonAdapter sla = (SequentialLessonAdapter) al;
+ int stage = myParser.getIntParameter(STAGE, sla.getStage(this));
+ if (stage > 0 && stage <= sla.getStageCount()) {
+ sla.setStage(this, stage);
+ }
+ } else if (al instanceof RandomLessonAdapter) {
+ try {
+ RandomLessonAdapter rla = (RandomLessonAdapter) al;
+ if (!myParser.getRawParameter(STAGE).equals("null")) {
+ int stage = myParser.getIntParameter(STAGE) - 1;
+ String[] stages = rla.getStages();
+ if (stages == null) {
+ stages = new String[0];
+ }
+ if (stage >= 0 && stage < stages.length) {
+ rla.setStage(this, stages[stage]);
+ }
+ } else {
+ rla.setStage(this, null);
+ }
+ } catch (ParameterNotFoundException pnfe) {
+ }
+ }
+ } // else update global variables for the current screen
+ else {
+ // Handle "restart" commands
+ int lessonId = myParser.getIntParameter(RESTART, -1);
+ if (lessonId != -1) {
+ restartLesson(lessonId);
+ }
+ // if ( myParser.getBooleanParameter( RESTART, false ) )
+ // {
+ // getCurrentLesson().getLessonTracker( this ).getLessonProperties().setProperty(
+ // CHALLENGE_STAGE, "1" );
+ // }
+
+ // Handle "show" commands
+ String showCommand = myParser.getStringParameter(SHOW, null);
+ if (showCommand != null) {
+ if (showCommand.equalsIgnoreCase(SHOW_PARAMS)) {
+ showParams = !showParams;
+ } else if (showCommand.equalsIgnoreCase(SHOW_COOKIES)) {
+ showCookies = !showCookies;
+ } else if (showCommand.equalsIgnoreCase(SHOW_SOURCE)) {
+ content = getSource();
+ // showSource = true;
+ } else if (showCommand.equalsIgnoreCase(SHOW_SOLUTION)) {
+ content = getSolution();
+ // showSource = true;
+ } else if (showCommand.equalsIgnoreCase(SHOW_NEXTHINT)) {
+ getNextHint();
+ } else if (showCommand.equalsIgnoreCase(SHOW_PREVIOUSHINT)) {
+ getPreviousHint();
+ }
+ }
+
+ }
+
+ isAdmin = request.isUserInRole(WEBGOAT_ADMIN);
+ isHackedAdmin = myParser.getBooleanParameter(ADMIN, isAdmin);
+ if (isHackedAdmin) {
+ System.out.println("Hacked admin");
+ hasHackedHackableAdmin = true;
+ }
+ isColor = myParser.getBooleanParameter(COLOR, isColor);
+ isDebug = myParser.getBooleanParameter(DEBUG, isDebug);
+
+ // System.out.println( "showParams:" + showParams );
+ // System.out.println( "showSource:" + showSource );
+ // System.out.println( "showSolution:" + showSolution );
+ // System.out.println( "showCookies:" + showCookies );
+ // System.out.println( "showRequest:" + showRequest );
+ if (content != null) {
+ response.setContentType("text/html");
+ PrintWriter out = new PrintWriter(response.getOutputStream());
+ out.print(content);
+ out.flush();
+ out.close();
+ }
+ }
+
+ /**
+ * updateLastAttackRequestInfo.
+ *
+ * @param request a {@link javax.servlet.http.HttpServletRequest} object.
+ */
+ public void updateLastAttackRequestInfo(HttpServletRequest request) {
+ // store cookies
+ Cookie[] cookies = request.getCookies();
+ if (cookies == null) {
+ this.cookiesOnLastRequest = new ArrayList();
+ } else {
+ this.cookiesOnLastRequest = Arrays.asList(cookies);
+ }
+ // store parameters
+ Map parmMap = request.getParameterMap();
+ logger.info("PARM MAP: " + parmMap);
+ if (parmMap == null) {
+ this.parmsOnLastRequest = new ArrayList();
+ } else {
+ this.parmsOnLastRequest = new ArrayList();
+ for (String name : parmMap.keySet()) {
+ String[] values = parmMap.get(name);
+ String delim = "";
+ StringBuffer sb = new StringBuffer();
+ if (values != null && values.length > 0) {
+ for (String parm : values) {
+ sb.append(delim).append(parm);
+ delim = ",";
+ }
+ }
+ RequestParameter parm = new RequestParameter(name, sb.toString());
+ this.parmsOnLastRequest.add(parm);
+ }
+ }
+ }
+
+ /**
+ * restartLesson.
+ *
+ * @param lessonId a int.
+ */
+ public void restartLesson(int lessonId) {
+ AbstractLesson al = getLesson(lessonId);
+ System.out.println("Restarting lesson: " + al);
+ al.getLessonTracker(this).setCompleted(false);
+ if (al instanceof SequentialLessonAdapter) {
+ SequentialLessonAdapter sla = (SequentialLessonAdapter) al;
+ sla.getLessonTracker(this).setStage(1);
+ } else if (al instanceof RandomLessonAdapter) {
+ RandomLessonAdapter rla = (RandomLessonAdapter) al;
+ rla.setStage(this, rla.getStages()[0]);
+ }
+ }
+
+ /**
+ * setHasHackableAdmin.
+ *
+ * @param role a {@link java.lang.String} object.
+ */
+ public void setHasHackableAdmin(String role) {
+ hasHackedHackableAdmin = (AbstractLesson.HACKED_ADMIN_ROLE.equals(role) & hasHackedHackableAdmin);
+
+ // if the user got the Admin=true parameter correct AND they accessed an admin screen
+ if (hasHackedHackableAdmin) {
+ completedHackableAdmin = true;
+ }
+ }
+
+ /**
+ * isDebug.
+ *
+ * @return Returns the isDebug.
+ */
+ public boolean isDebug() {
+ return isDebug;
+ }
+
+ /**
+ * getHeader.
+ *
+ * @param header - request header value to return
+ * @return a {@link java.lang.String} object.
+ */
+ public String getHeader(String header) {
+ return getRequest().getHeader(header);
+ }
+
+ /**
+ * getNextHint.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getNextHint() {
+ String hint = null;
+
+ // FIXME
+ int maxHints = getCurrentLesson().getHintCount(this);
+ if (hintNum < maxHints - 1) {
+ hintNum++;
+
+ // Hints are indexed from 0
+ getCurrentLesson().getLessonTracker(this).setMaxHintLevel(getHintNum() + 1);
+
+ hint = (String) getCurrentLesson().getHint(this, getHintNum());
+ }
+
+ return hint;
+ }
+
+ /**
+ * getPreviousHint.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getPreviousHint() {
+ String hint = null;
+
+ if (hintNum > 0) {
+ hintNum--;
+
+ // Hints are indexed from 0
+ getCurrentLesson().getLessonTracker(this).setMaxHintLevel(getHintNum() + 1);
+
+ hint = (String) getCurrentLesson().getHint(this, getHintNum());
+ }
+
+ return hint;
+ }
+
+ /**
+ * Setter for the field currentMenu
.
+ *
+ * @param ranking a {@link java.lang.Integer} object.
+ */
+ public void setCurrentMenu(Integer ranking) {
+ currentMenu = ranking.intValue();
+ }
+
+ /**
+ * Getter for the field currentMenu
.
+ *
+ * @return a int.
+ */
+ public int getCurrentMenu() {
+ return currentMenu;
+ }
+
+ /**
+ * Getter for the field webgoatContext
.
+ *
+ * @return a {@link org.owasp.webgoat.session.WebgoatContext} object.
+ */
+ public WebgoatContext getWebgoatContext() {
+ return webgoatContext;
+ }
+
+ /**
+ * getCurrrentLanguage.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getCurrrentLanguage() {
+ return currentLanguage;
+ }
+
+ /**
+ * Getter for the field cookiesOnLastRequest
.
+ *
+ * @return the cookiesOnLastRequest
+ */
+ public List getCookiesOnLastRequest() {
+ return cookiesOnLastRequest;
+ }
+
+ /**
+ * Getter for the field parmsOnLastRequest
.
+ *
+ * @return the parmsOnLastRequest
+ */
+ public List getParmsOnLastRequest() {
+ return parmsOnLastRequest;
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/WebgoatContext.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/WebgoatContext.java
index 8c9ce4549..f38081950 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/WebgoatContext.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/WebgoatContext.java
@@ -1,218 +1,310 @@
-package org.owasp.webgoat.session;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.http.HttpServlet;
-
-public class WebgoatContext {
-
- final Logger logger = LoggerFactory.getLogger(WebgoatContext.class);
-
- public final static String DATABASE_CONNECTION_STRING = "DatabaseConnectionString";
-
- public final static String DATABASE_DRIVER = "DatabaseDriver";
-
- public final static String DATABASE_USER = "DatabaseUser";
-
- public final static String DATABASE_PASSWORD = "DatabasePassword";
-
- public final static String ENTERPRISE = "Enterprise";
-
- public final static String CODING_EXERCISES = "CodingExercises";
-
- public final static String SHOWCOOKIES = "ShowCookies";
-
- public final static String SHOWPARAMS = "ShowParams";
-
- public final static String SHOWREQUEST = "ShowRequest";
-
- public final static String SHOWSOURCE = "ShowSource";
-
- public final static String SHOWSOLUTION = "ShowSolution";
-
- public final static String SHOWHINTS = "ShowHints";
-
- public final static String DEFUSEOSCOMMANDS = "DefuseOSCommands";
-
- public final static String FEEDBACK_ADDRESS_HTML = "FeedbackAddressHTML";
-
- public final static String FEEDBACK_ADDRESS = "email";
-
- public final static String DEBUG = "debug";
-
- public final static String DEFAULTLANGUAGE = "DefaultLanguage";
-
- private String databaseConnectionString;
-
- private String realConnectionString = null;
-
- private String databaseDriver;
-
- private String databaseUser;
-
- private String databasePassword;
-
- private boolean showCookies = false;
-
- private boolean showParams = false;
-
- private boolean showRequest = false;
-
- private boolean showSource = false;
-
- private boolean showSolution = false;
-
- private boolean defuseOSCommands = false;
-
- private boolean enterprise = false;
-
- private boolean codingExercises = false;
-
- private String feedbackAddress = "webgoat@owasp.org";
-
- private String feedbackAddressHTML = "webgoat@owasp.org ";
-
- private boolean isDebug = false;
-
- private String servletName;
-
- private HttpServlet servlet;
-
- private String defaultLanguage;
-
- private java.nio.file.Path pluginDirectory;
-
- public WebgoatContext(HttpServlet servlet) {
- this.servlet = servlet;
- databaseConnectionString = getParameter(servlet, DATABASE_CONNECTION_STRING);
- databaseDriver = getParameter(servlet, DATABASE_DRIVER);
- databaseUser = getParameter(servlet, DATABASE_USER);
- databasePassword = getParameter(servlet, DATABASE_PASSWORD);
-
- // initialize from web.xml
- showParams = "true".equals(getParameter(servlet, SHOWPARAMS));
- showCookies = "true".equals(getParameter(servlet, SHOWCOOKIES));
- showSource = "true".equals(getParameter(servlet, SHOWSOURCE));
- showSolution = "true".equals(getParameter(servlet, SHOWSOLUTION));
- defuseOSCommands = "true".equals(getParameter(servlet, DEFUSEOSCOMMANDS));
- enterprise = "true".equals(getParameter(servlet, ENTERPRISE));
- codingExercises = "true".equals(getParameter(servlet, CODING_EXERCISES));
- feedbackAddressHTML = getParameter(servlet, FEEDBACK_ADDRESS_HTML) != null ? getParameter(servlet,
- FEEDBACK_ADDRESS_HTML)
- : feedbackAddressHTML;
- feedbackAddress = getParameter(servlet, FEEDBACK_ADDRESS) != null ? getParameter(servlet, FEEDBACK_ADDRESS)
- : feedbackAddress;
- 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("en");
- }
-
- private String getParameter(HttpServlet servlet, String key) {
- String value = System.getenv().get(key);
- if (value == null) {
- value = servlet.getInitParameter(key);
- }
- return value;
- }
-
- /**
- * returns the connection string with the real path to the database
- * directory inserted at the word PATH
- *
- * @return The databaseConnectionString value
- */
- public String getDatabaseConnectionString() {
- if (realConnectionString == null) {
- try {
- String path = servlet.getServletContext().getRealPath("/database").replace('\\', '/');
- System.out.println("PATH: " + path);
- realConnectionString = databaseConnectionString.replaceAll("PATH", path);
- System.out.println("Database Connection String: " + realConnectionString);
- } catch (Exception e) {
- logger.error("Couldn't open database: check web.xml database parameters", e);
- }
- }
- return realConnectionString;
- }
-
- /**
- * Gets the databaseDriver attribute of the WebSession object
- *
- * @return The databaseDriver value
- */
- public String getDatabaseDriver() {
- return (databaseDriver);
- }
-
- /**
- * Gets the databaseUser attribute of the WebSession object
- *
- * @return The databaseUser value
- */
- public String getDatabaseUser() {
- return (databaseUser);
- }
-
- /**
- * Gets the databasePassword attribute of the WebSession object
- *
- * @return The databasePassword value
- */
- public String getDatabasePassword() {
- return (databasePassword);
- }
-
- public boolean isDefuseOSCommands() {
- return defuseOSCommands;
- }
-
- public boolean isEnterprise() {
- return enterprise;
- }
-
- public boolean isCodingExercises() {
- return codingExercises;
- }
-
- public String getFeedbackAddress() {
- return feedbackAddress;
- }
-
- public String getFeedbackAddressHTML() {
- return feedbackAddressHTML;
- }
-
- public boolean isDebug() {
- return isDebug;
- }
-
- public String getServletName() {
- return servletName;
- }
-
- public boolean isShowCookies() {
- return showCookies;
- }
-
- public boolean isShowParams() {
- return showParams;
- }
-
- public boolean isShowRequest() {
- return showRequest;
- }
-
- public boolean isShowSource() {
- return showSource;
- }
-
- public boolean isShowSolution() {
- return showSolution;
- }
-
- public String getDefaultLanguage() {
- return defaultLanguage;
- }
-}
+package org.owasp.webgoat.session;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServlet;
+
+/**
+ * WebgoatContext class.
+ *
+ * @version $Id: $Id
+ */
+public class WebgoatContext {
+
+ final Logger logger = LoggerFactory.getLogger(WebgoatContext.class);
+
+ /** Constant DATABASE_CONNECTION_STRING="DatabaseConnectionString"
*/
+ public final static String DATABASE_CONNECTION_STRING = "DatabaseConnectionString";
+
+ /** Constant DATABASE_DRIVER="DatabaseDriver"
*/
+ public final static String DATABASE_DRIVER = "DatabaseDriver";
+
+ /** Constant DATABASE_USER="DatabaseUser"
*/
+ public final static String DATABASE_USER = "DatabaseUser";
+
+ /** Constant DATABASE_PASSWORD="DatabasePassword"
*/
+ public final static String DATABASE_PASSWORD = "DatabasePassword";
+
+ /** Constant ENTERPRISE="Enterprise"
*/
+ public final static String ENTERPRISE = "Enterprise";
+
+ /** Constant CODING_EXERCISES="CodingExercises"
*/
+ public final static String CODING_EXERCISES = "CodingExercises";
+
+ /** Constant SHOWCOOKIES="ShowCookies"
*/
+ public final static String SHOWCOOKIES = "ShowCookies";
+
+ /** Constant SHOWPARAMS="ShowParams"
*/
+ public final static String SHOWPARAMS = "ShowParams";
+
+ /** Constant SHOWREQUEST="ShowRequest"
*/
+ public final static String SHOWREQUEST = "ShowRequest";
+
+ /** Constant SHOWSOURCE="ShowSource"
*/
+ public final static String SHOWSOURCE = "ShowSource";
+
+ /** Constant SHOWSOLUTION="ShowSolution"
*/
+ public final static String SHOWSOLUTION = "ShowSolution";
+
+ /** Constant SHOWHINTS="ShowHints"
*/
+ public final static String SHOWHINTS = "ShowHints";
+
+ /** Constant DEFUSEOSCOMMANDS="DefuseOSCommands"
*/
+ public final static String DEFUSEOSCOMMANDS = "DefuseOSCommands";
+
+ /** Constant FEEDBACK_ADDRESS_HTML="FeedbackAddressHTML"
*/
+ public final static String FEEDBACK_ADDRESS_HTML = "FeedbackAddressHTML";
+
+ /** Constant FEEDBACK_ADDRESS="email"
*/
+ public final static String FEEDBACK_ADDRESS = "email";
+
+ /** Constant DEBUG="debug"
*/
+ public final static String DEBUG = "debug";
+
+ /** Constant DEFAULTLANGUAGE="DefaultLanguage"
*/
+ public final static String DEFAULTLANGUAGE = "DefaultLanguage";
+
+ private String databaseConnectionString;
+
+ private String realConnectionString = null;
+
+ private String databaseDriver;
+
+ private String databaseUser;
+
+ private String databasePassword;
+
+ private boolean showCookies = false;
+
+ private boolean showParams = false;
+
+ private boolean showRequest = false;
+
+ private boolean showSource = false;
+
+ private boolean showSolution = false;
+
+ private boolean defuseOSCommands = false;
+
+ private boolean enterprise = false;
+
+ private boolean codingExercises = false;
+
+ private String feedbackAddress = "webgoat@owasp.org";
+
+ private String feedbackAddressHTML = "webgoat@owasp.org ";
+
+ private boolean isDebug = false;
+
+ private String servletName;
+
+ private HttpServlet servlet;
+
+ private String defaultLanguage;
+
+ private java.nio.file.Path pluginDirectory;
+
+ /**
+ * Constructor for WebgoatContext.
+ *
+ * @param servlet a {@link javax.servlet.http.HttpServlet} object.
+ */
+ public WebgoatContext(HttpServlet servlet) {
+ this.servlet = servlet;
+ databaseConnectionString = getParameter(servlet, DATABASE_CONNECTION_STRING);
+ databaseDriver = getParameter(servlet, DATABASE_DRIVER);
+ databaseUser = getParameter(servlet, DATABASE_USER);
+ databasePassword = getParameter(servlet, DATABASE_PASSWORD);
+
+ // initialize from web.xml
+ showParams = "true".equals(getParameter(servlet, SHOWPARAMS));
+ showCookies = "true".equals(getParameter(servlet, SHOWCOOKIES));
+ showSource = "true".equals(getParameter(servlet, SHOWSOURCE));
+ showSolution = "true".equals(getParameter(servlet, SHOWSOLUTION));
+ defuseOSCommands = "true".equals(getParameter(servlet, DEFUSEOSCOMMANDS));
+ enterprise = "true".equals(getParameter(servlet, ENTERPRISE));
+ codingExercises = "true".equals(getParameter(servlet, CODING_EXERCISES));
+ feedbackAddressHTML = getParameter(servlet, FEEDBACK_ADDRESS_HTML) != null ? getParameter(servlet,
+ FEEDBACK_ADDRESS_HTML)
+ : feedbackAddressHTML;
+ feedbackAddress = getParameter(servlet, FEEDBACK_ADDRESS) != null ? getParameter(servlet, FEEDBACK_ADDRESS)
+ : feedbackAddress;
+ 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("en");
+ }
+
+ private String getParameter(HttpServlet servlet, String key) {
+ String value = System.getenv().get(key);
+ if (value == null) {
+ value = servlet.getInitParameter(key);
+ }
+ return value;
+ }
+
+ /**
+ * returns the connection string with the real path to the database
+ * directory inserted at the word PATH
+ *
+ * @return The databaseConnectionString value
+ */
+ public String getDatabaseConnectionString() {
+ if (realConnectionString == null) {
+ try {
+ String path = servlet.getServletContext().getRealPath("/database").replace('\\', '/');
+ System.out.println("PATH: " + path);
+ realConnectionString = databaseConnectionString.replaceAll("PATH", path);
+ System.out.println("Database Connection String: " + realConnectionString);
+ } catch (Exception e) {
+ logger.error("Couldn't open database: check web.xml database parameters", e);
+ }
+ }
+ return realConnectionString;
+ }
+
+ /**
+ * Gets the databaseDriver attribute of the WebSession object
+ *
+ * @return The databaseDriver value
+ */
+ public String getDatabaseDriver() {
+ return (databaseDriver);
+ }
+
+ /**
+ * Gets the databaseUser attribute of the WebSession object
+ *
+ * @return The databaseUser value
+ */
+ public String getDatabaseUser() {
+ return (databaseUser);
+ }
+
+ /**
+ * Gets the databasePassword attribute of the WebSession object
+ *
+ * @return The databasePassword value
+ */
+ public String getDatabasePassword() {
+ return (databasePassword);
+ }
+
+ /**
+ * isDefuseOSCommands.
+ *
+ * @return a boolean.
+ */
+ public boolean isDefuseOSCommands() {
+ return defuseOSCommands;
+ }
+
+ /**
+ * isEnterprise.
+ *
+ * @return a boolean.
+ */
+ public boolean isEnterprise() {
+ return enterprise;
+ }
+
+ /**
+ * isCodingExercises.
+ *
+ * @return a boolean.
+ */
+ public boolean isCodingExercises() {
+ return codingExercises;
+ }
+
+ /**
+ * Getter for the field feedbackAddress
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getFeedbackAddress() {
+ return feedbackAddress;
+ }
+
+ /**
+ * Getter for the field feedbackAddressHTML
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getFeedbackAddressHTML() {
+ return feedbackAddressHTML;
+ }
+
+ /**
+ * isDebug.
+ *
+ * @return a boolean.
+ */
+ public boolean isDebug() {
+ return isDebug;
+ }
+
+ /**
+ * Getter for the field servletName
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getServletName() {
+ return servletName;
+ }
+
+ /**
+ * isShowCookies.
+ *
+ * @return a boolean.
+ */
+ public boolean isShowCookies() {
+ return showCookies;
+ }
+
+ /**
+ * isShowParams.
+ *
+ * @return a boolean.
+ */
+ public boolean isShowParams() {
+ return showParams;
+ }
+
+ /**
+ * isShowRequest.
+ *
+ * @return a boolean.
+ */
+ public boolean isShowRequest() {
+ return showRequest;
+ }
+
+ /**
+ * isShowSource.
+ *
+ * @return a boolean.
+ */
+ public boolean isShowSource() {
+ return showSource;
+ }
+
+ /**
+ * isShowSolution.
+ *
+ * @return a boolean.
+ */
+ public boolean isShowSolution() {
+ return showSolution;
+ }
+
+ /**
+ * Getter for the field defaultLanguage
.
+ *
+ * @return a {@link java.lang.String} object.
+ */
+ public String getDefaultLanguage() {
+ return defaultLanguage;
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/session/WebgoatProperties.java b/webgoat-container/src/main/java/org/owasp/webgoat/session/WebgoatProperties.java
index d1b5a6705..3edb20d6b 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/session/WebgoatProperties.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/session/WebgoatProperties.java
@@ -1,119 +1,146 @@
-package org.owasp.webgoat.session;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Properties;
-import org.owasp.webgoat.HammerHead;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * *************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project
- * utility. For details, please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- * Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
- * for free software projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public class WebgoatProperties extends Properties {
-
- /**
- *
- */
- private static final long serialVersionUID = 4351681705558227918L;
- final Logger logger = LoggerFactory.getLogger(WebgoatProperties.class);
-
- public WebgoatProperties(String propertiesFileName) throws IOException {
- if (propertiesFileName == null) {
- throw new IOException("Path to webgoat.properties is null, initialization must have failed");
- }
- File propertiesFile = new File(propertiesFileName);
- if (propertiesFile.exists() == false) {
- throw new IOException("Unable to locate webgoat.properties at: " + propertiesFileName);
- }
- FileInputStream in = new FileInputStream(propertiesFile);
- load(in);
- }
-
- public int getIntProperty(String key, int defaultValue) {
- int value = defaultValue;
-
- String s = getProperty(key);
- if (s != null) {
- value = Integer.parseInt(s);
- }
-
- return value;
- }
-
- public boolean getBooleanProperty(String key, boolean defaultValue) {
- boolean value = defaultValue;
- key = this.trimLesson(key);
-
- String s = getProperty(key);
- if (s != null) {
- if (s.equalsIgnoreCase("true")) {
- value = true;
- } else if (s.equalsIgnoreCase("yes")) {
- value = true;
- } else if (s.equalsIgnoreCase("on")) {
- value = true;
- } else if (s.equalsIgnoreCase("false")) {
- value = false;
- } else if (s.equalsIgnoreCase("no")) {
- value = false;
- } else if (s.equalsIgnoreCase("off")) {
- value = false;
- }
- }
-
- return value;
- }
-
- private String trimLesson(String lesson) {
- String result = "";
-
- if (lesson.startsWith("org.owasp.webgoat.lessons.")) {
- result = lesson.substring("org.owasp.webgoat.lessons.".length(), lesson.length());
- } else {
- result = lesson;
- }
-
- return result;
- }
-
- public static void main(String[] args) {
- WebgoatProperties properties = null;
- try {
- properties = new WebgoatProperties("C:\\webgoat.properties");
- } catch (IOException e) {
- System.out.println("Error loading properties");
- e.printStackTrace();
- }
- System.out.println(properties.getProperty("CommandInjection.category"));
- }
-
-}
+package org.owasp.webgoat.session;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+import org.owasp.webgoat.HammerHead;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project
+ * utility. For details, please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
+ * for free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public class WebgoatProperties extends Properties {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4351681705558227918L;
+ final Logger logger = LoggerFactory.getLogger(WebgoatProperties.class);
+
+ /**
+ * Constructor for WebgoatProperties.
+ *
+ * @param propertiesFileName a {@link java.lang.String} object.
+ * @throws java.io.IOException if any.
+ */
+ public WebgoatProperties(String propertiesFileName) throws IOException {
+ if (propertiesFileName == null) {
+ throw new IOException("Path to webgoat.properties is null, initialization must have failed");
+ }
+ File propertiesFile = new File(propertiesFileName);
+ if (propertiesFile.exists() == false) {
+ throw new IOException("Unable to locate webgoat.properties at: " + propertiesFileName);
+ }
+ FileInputStream in = new FileInputStream(propertiesFile);
+ load(in);
+ }
+
+ /**
+ * getIntProperty.
+ *
+ * @param key a {@link java.lang.String} object.
+ * @param defaultValue a int.
+ * @return a int.
+ */
+ public int getIntProperty(String key, int defaultValue) {
+ int value = defaultValue;
+
+ String s = getProperty(key);
+ if (s != null) {
+ value = Integer.parseInt(s);
+ }
+
+ return value;
+ }
+
+ /**
+ * getBooleanProperty.
+ *
+ * @param key a {@link java.lang.String} object.
+ * @param defaultValue a boolean.
+ * @return a boolean.
+ */
+ public boolean getBooleanProperty(String key, boolean defaultValue) {
+ boolean value = defaultValue;
+ key = this.trimLesson(key);
+
+ String s = getProperty(key);
+ if (s != null) {
+ if (s.equalsIgnoreCase("true")) {
+ value = true;
+ } else if (s.equalsIgnoreCase("yes")) {
+ value = true;
+ } else if (s.equalsIgnoreCase("on")) {
+ value = true;
+ } else if (s.equalsIgnoreCase("false")) {
+ value = false;
+ } else if (s.equalsIgnoreCase("no")) {
+ value = false;
+ } else if (s.equalsIgnoreCase("off")) {
+ value = false;
+ }
+ }
+
+ return value;
+ }
+
+ private String trimLesson(String lesson) {
+ String result = "";
+
+ if (lesson.startsWith("org.owasp.webgoat.lessons.")) {
+ result = lesson.substring("org.owasp.webgoat.lessons.".length(), lesson.length());
+ } else {
+ result = lesson;
+ }
+
+ return result;
+ }
+
+ /**
+ * main.
+ *
+ * @param args an array of {@link java.lang.String} objects.
+ */
+ public static void main(String[] args) {
+ WebgoatProperties properties = null;
+ try {
+ properties = new WebgoatProperties("C:\\webgoat.properties");
+ } catch (IOException e) {
+ System.out.println("Error loading properties");
+ e.printStackTrace();
+ }
+ System.out.println(properties.getProperty("CommandInjection.category"));
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/BeanProvider.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/BeanProvider.java
index 71e2e1998..13fc14af0 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/BeanProvider.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/BeanProvider.java
@@ -1,63 +1,68 @@
-
-package org.owasp.webgoat.util;
-
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.stereotype.Component;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for
- * free software projects.
- *
- * For details, please see http://webgoat.github.io
- */
-@Component
-public class BeanProvider implements ApplicationContextAware
-{
- private static ApplicationContext ctx;
-
- @Override
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
- {
- ctx = applicationContext;
-
- }
-
- /**
- * Get access to managed beans from id.
- *
- * @param beanName
- * the id of the searched bean
- * @param beanClass
- * the type of tye searched bean
- * @return
- */
- @SuppressWarnings("unchecked")
- public static T getBean(final String beanName, final Class beanClass)
- {
- return (T) ctx.getBean(beanName);
- }
-}
+
+package org.owasp.webgoat.util;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for
+ * free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+@Component
+public class BeanProvider implements ApplicationContextAware
+{
+ private static ApplicationContext ctx;
+
+ /** {@inheritDoc} */
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
+ {
+ ctx = applicationContext;
+
+ }
+
+ /**
+ * Get access to managed beans from id.
+ *
+ * @param beanName
+ * the id of the searched bean
+ * @param beanClass
+ * the type of tye searched bean
+ * @param a T object.
+ * @return a T object.
+ */
+ @SuppressWarnings("unchecked")
+ public static T getBean(final String beanName, final Class beanClass)
+ {
+ return (T) ctx.getBean(beanName);
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/Exec.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/Exec.java
index a34d795b7..b0f902578 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/Exec.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/Exec.java
@@ -1,527 +1,529 @@
-
-package org.owasp.webgoat.util;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-import java.util.BitSet;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- * @created October 28, 2003
- */
-public class Exec
-{
-
- /**
- * Description of the Method
- *
- * @param command
- * Description of the Parameter
- * @param input
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static ExecResults execInput(String command, String input)
- {
- return (execOptions(command, input, 0, 0, false));
- }
-
- /**
- * Description of the Method
- *
- * @param command
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static ExecResults execLazy(String command)
- {
- return (execOptions(command, "", 0, 0, true));
- }
-
- /*
- * Execute an OS command and capture the output in an ExecResults. All exceptions are caught and
- * stored in the ExecResults. @param String command is the OS command to execute @param String
- * input is piped into the OS command @param int successCode is the expected return code if the
- * command completes successfully @param int timeout is the number of milliseconds to wait
- * before interrupting the command @param boolean quit tells the method to exit when there is no
- * more output waiting
- */
- /**
- * Description of the Method
- *
- * @param command
- * Description of the Parameter
- * @param input
- * Description of the Parameter
- * @param successCode
- * Description of the Parameter
- * @param timeout
- * Description of the Parameter
- * @param lazy
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static ExecResults execOptions(String[] command, String input, int successCode, int timeout, boolean lazy)
- {
- Process child = null;
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- ByteArrayOutputStream errors = new ByteArrayOutputStream();
- ExecResults results = new ExecResults(Arrays.asList(command).toString(), input, successCode, timeout);
- BitSet interrupted = new BitSet(1);
- boolean lazyQuit = false;
- ThreadWatcher watcher;
-
- try
- {
- // start the command
- child = Runtime.getRuntime().exec(command);
-
- // get the streams in and out of the command
- InputStream processIn = child.getInputStream();
- InputStream processError = child.getErrorStream();
- OutputStream processOut = child.getOutputStream();
-
- // start the clock running
- if (timeout > 0)
- {
- watcher = new ThreadWatcher(child, interrupted, timeout);
- new Thread(watcher).start();
- }
-
- // Write to the child process' input stream
- if ((input != null) && !input.equals(""))
- {
- try
- {
- processOut.write(input.getBytes());
- processOut.flush();
- processOut.close();
- } catch (IOException e1)
- {
- results.setThrowable(e1);
- }
- }
-
- // Read from the child process' output stream
- // The process may get killed by the watcher at any time
- int c = 0;
-
- try
- {
- while (true)
- {
- if (interrupted.get(0) || lazyQuit)
- {
- break;
- }
-
- // interrupted
- c = processIn.read();
-
- if (c == -1)
- {
- break;
- }
-
- // end of stream
- output.write(c);
-
- if (lazy && (processIn.available() < 1))
- {
- lazyQuit = true;
- }
-
- // if lazy and nothing then quit (after at least one read)
- }
-
- processIn.close();
- } catch (IOException e2)
- {
- results.setThrowable(e2);
- } finally
- {
- if (interrupted.get(0))
- {
- results.setInterrupted();
- }
-
- results.setOutput(output.toString());
- }
-
- // Read from the child process' error stream
- // The process may get killed by the watcher at any time
- try
- {
- while (true)
- {
- if (interrupted.get(0) || lazyQuit)
- {
- break;
- }
-
- // interrupted
- c = processError.read();
-
- if (c == -1)
- {
- break;
- }
-
- // end of stream
- output.write(c);
-
- if (lazy && (processError.available() < 1))
- {
- lazyQuit = true;
- }
-
- // if lazy and nothing then quit (after at least one read)
- }
-
- processError.close();
- } catch (IOException e3)
- {
- results.setThrowable(e3);
- } finally
- {
- if (interrupted.get(0))
- {
- results.setInterrupted();
- }
-
- results.setErrors(errors.toString());
- }
-
- // wait for the return value of the child process.
- if (!interrupted.get(0) && !lazyQuit)
- {
- int returnCode = child.waitFor();
- results.setReturnCode(returnCode);
-
- if (returnCode != successCode)
- {
- results.setError(ExecResults.BADRETURNCODE);
- }
- }
- } catch (InterruptedException i)
- {
- results.setInterrupted();
- } catch (Throwable t)
- {
- results.setThrowable(t);
- } finally
- {
- if (child != null)
- {
- child.destroy();
- }
- }
-
- return (results);
- }
-
- /*
- * Execute an OS command and capture the output in an ExecResults. All exceptions are caught and
- * stored in the ExecResults. @param String command is the OS command to execute @param String
- * input is piped into the OS command @param int successCode is the expected return code if the
- * command completes successfully @param int timeout is the number of milliseconds to wait
- * before interrupting the command @param boolean quit tells the method to exit when there is no
- * more output waiting
- */
- /**
- * Description of the Method
- *
- * @param command
- * Description of the Parameter
- * @param input
- * Description of the Parameter
- * @param successCode
- * Description of the Parameter
- * @param timeout
- * Description of the Parameter
- * @param lazy
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static ExecResults execOptions(String command, String input, int successCode, int timeout, boolean lazy)
- {
- Process child = null;
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- ByteArrayOutputStream errors = new ByteArrayOutputStream();
- ExecResults results = new ExecResults(command, input, successCode, timeout);
- BitSet interrupted = new BitSet(1);
- boolean lazyQuit = false;
- ThreadWatcher watcher;
-
- try
- {
- // start the command
- child = Runtime.getRuntime().exec(command);
-
- // get the streams in and out of the command
- InputStream processIn = child.getInputStream();
- InputStream processError = child.getErrorStream();
- OutputStream processOut = child.getOutputStream();
-
- // start the clock running
- if (timeout > 0)
- {
- watcher = new ThreadWatcher(child, interrupted, timeout);
- new Thread(watcher).start();
- }
-
- // Write to the child process' input stream
- if ((input != null) && !input.equals(""))
- {
- try
- {
- processOut.write(input.getBytes());
- processOut.flush();
- processOut.close();
- } catch (IOException e1)
- {
- results.setThrowable(e1);
- }
- }
-
- // Read from the child process' output stream
- // The process may get killed by the watcher at any time
- int c = 0;
-
- try
- {
- while (true)
- {
- if (interrupted.get(0) || lazyQuit)
- {
- break;
- }
-
- // interrupted
- c = processIn.read();
-
- if (c == -1)
- {
- break;
- }
-
- // end of stream
- output.write(c);
-
- if (lazy && (processIn.available() < 1))
- {
- lazyQuit = true;
- }
-
- // if lazy and nothing then quit (after at least one read)
- }
-
- processIn.close();
- } catch (IOException e2)
- {
- results.setThrowable(e2);
- } finally
- {
- if (interrupted.get(0))
- {
- results.setInterrupted();
- }
-
- results.setOutput(output.toString());
- }
-
- // Read from the child process' error stream
- // The process may get killed by the watcher at any time
- try
- {
- while (true)
- {
- if (interrupted.get(0) || lazyQuit)
- {
- break;
- }
-
- // interrupted
- c = processError.read();
-
- if (c == -1)
- {
- break;
- }
-
- // end of stream
- output.write(c);
-
- if (lazy && (processError.available() < 1))
- {
- lazyQuit = true;
- }
-
- // if lazy and nothing then quit (after at least one read)
- }
-
- processError.close();
- } catch (IOException e3)
- {
- results.setThrowable(e3);
- } finally
- {
- if (interrupted.get(0))
- {
- results.setInterrupted();
- }
-
- results.setErrors(errors.toString());
- }
-
- // wait for the return value of the child process.
- if (!interrupted.get(0) && !lazyQuit)
- {
- int returnCode = child.waitFor();
- results.setReturnCode(returnCode);
-
- if (returnCode != successCode)
- {
- results.setError(ExecResults.BADRETURNCODE);
- }
- }
- } catch (InterruptedException i)
- {
- results.setInterrupted();
- } catch (Throwable t)
- {
- results.setThrowable(t);
- } finally
- {
- if (child != null)
- {
- child.destroy();
- }
- }
-
- return (results);
- }
-
- /**
- * Description of the Method
- *
- * @param command
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static ExecResults execSimple(String[] command)
- {
- return (execOptions(command, "", 0, 0, false));
- }
-
- /**
- * Description of the Method
- *
- * @param command
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static ExecResults execSimple(String command)
- {
- return (execOptions(command, "", 0, 0, false));
- }
-
- /**
- * Description of the Method
- *
- * @param command
- * Description of the Parameter
- * @param args
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static ExecResults execSimple(String command, String args)
- {
- return (execOptions(command, args, 0, 0, false));
- }
-
- /**
- * Description of the Method
- *
- * @param command
- * Description of the Parameter
- * @param timeout
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static ExecResults execTimeout(String command, int timeout)
- {
- return (execOptions(command, "", 0, timeout, false));
- }
-
- /**
- * The main program for the Exec class
- *
- * @param args
- * The command line arguments
- */
- public static void main(String[] args)
- {
- ExecResults results;
- String sep = System.getProperty("line.separator");
- System.out.println("-------------------------------------------" + sep + "TEST 1: execSimple");
- results = Exec.execSimple("c:/swarm-2.1.1/bin/whoami.exe");
- System.out.println(results);
- System.out.println("-------------------------------------------" + sep + "TEST 2: execSimple (with search)");
- results = Exec.execSimple("netstat -r");
- System.out.println(results);
-
- if (results.outputContains("localhost:1031"))
- {
- System.out.println("ERROR: listening on 1031");
- }
-
- System.out.println("-------------------------------------------" + sep + "TEST 3: execInput");
- results = Exec.execInput("find \"cde\"", "abcdefg1\nhijklmnop\nqrstuv\nabcdefg2");
- System.out.println(results);
- System.out.println("-------------------------------------------" + sep + "TEST 4:execTimeout");
- results = Exec.execTimeout("ping -t 127.0.0.1", 5 * 1000);
- System.out.println(results);
- System.out.println("-------------------------------------------" + sep + "TEST 5:execLazy");
- results = Exec.execLazy("ping -t 127.0.0.1");
- System.out.println(results);
- System.out.println("-------------------------------------------" + sep
- + "TEST 6:ExecTimeout process never outputs");
- results = Exec.execTimeout("c:/swarm-2.1.1/bin/sleep.exe 20", 5 * 1000);
- System.out.println(results);
- System.out.println("-------------------------------------------" + sep
- + "TEST 7:ExecTimeout process waits for input");
- results = Exec.execTimeout("c:/swarm-2.1.1/bin/cat", 5 * 1000);
- System.out.println(results);
- }
-}
+
+package org.owasp.webgoat.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.BitSet;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @since October 28, 2003
+ * @version $Id: $Id
+ */
+public class Exec
+{
+
+ /**
+ * Description of the Method
+ *
+ * @param command
+ * Description of the Parameter
+ * @param input
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static ExecResults execInput(String command, String input)
+ {
+ return (execOptions(command, input, 0, 0, false));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param command
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static ExecResults execLazy(String command)
+ {
+ return (execOptions(command, "", 0, 0, true));
+ }
+
+ /*
+ * Execute an OS command and capture the output in an ExecResults. All exceptions are caught and
+ * stored in the ExecResults. @param String command is the OS command to execute @param String
+ * input is piped into the OS command @param int successCode is the expected return code if the
+ * command completes successfully @param int timeout is the number of milliseconds to wait
+ * before interrupting the command @param boolean quit tells the method to exit when there is no
+ * more output waiting
+ */
+ /**
+ * Description of the Method
+ *
+ * @param command
+ * Description of the Parameter
+ * @param input
+ * Description of the Parameter
+ * @param successCode
+ * Description of the Parameter
+ * @param timeout
+ * Description of the Parameter
+ * @param lazy
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static ExecResults execOptions(String[] command, String input, int successCode, int timeout, boolean lazy)
+ {
+ Process child = null;
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ ByteArrayOutputStream errors = new ByteArrayOutputStream();
+ ExecResults results = new ExecResults(Arrays.asList(command).toString(), input, successCode, timeout);
+ BitSet interrupted = new BitSet(1);
+ boolean lazyQuit = false;
+ ThreadWatcher watcher;
+
+ try
+ {
+ // start the command
+ child = Runtime.getRuntime().exec(command);
+
+ // get the streams in and out of the command
+ InputStream processIn = child.getInputStream();
+ InputStream processError = child.getErrorStream();
+ OutputStream processOut = child.getOutputStream();
+
+ // start the clock running
+ if (timeout > 0)
+ {
+ watcher = new ThreadWatcher(child, interrupted, timeout);
+ new Thread(watcher).start();
+ }
+
+ // Write to the child process' input stream
+ if ((input != null) && !input.equals(""))
+ {
+ try
+ {
+ processOut.write(input.getBytes());
+ processOut.flush();
+ processOut.close();
+ } catch (IOException e1)
+ {
+ results.setThrowable(e1);
+ }
+ }
+
+ // Read from the child process' output stream
+ // The process may get killed by the watcher at any time
+ int c = 0;
+
+ try
+ {
+ while (true)
+ {
+ if (interrupted.get(0) || lazyQuit)
+ {
+ break;
+ }
+
+ // interrupted
+ c = processIn.read();
+
+ if (c == -1)
+ {
+ break;
+ }
+
+ // end of stream
+ output.write(c);
+
+ if (lazy && (processIn.available() < 1))
+ {
+ lazyQuit = true;
+ }
+
+ // if lazy and nothing then quit (after at least one read)
+ }
+
+ processIn.close();
+ } catch (IOException e2)
+ {
+ results.setThrowable(e2);
+ } finally
+ {
+ if (interrupted.get(0))
+ {
+ results.setInterrupted();
+ }
+
+ results.setOutput(output.toString());
+ }
+
+ // Read from the child process' error stream
+ // The process may get killed by the watcher at any time
+ try
+ {
+ while (true)
+ {
+ if (interrupted.get(0) || lazyQuit)
+ {
+ break;
+ }
+
+ // interrupted
+ c = processError.read();
+
+ if (c == -1)
+ {
+ break;
+ }
+
+ // end of stream
+ output.write(c);
+
+ if (lazy && (processError.available() < 1))
+ {
+ lazyQuit = true;
+ }
+
+ // if lazy and nothing then quit (after at least one read)
+ }
+
+ processError.close();
+ } catch (IOException e3)
+ {
+ results.setThrowable(e3);
+ } finally
+ {
+ if (interrupted.get(0))
+ {
+ results.setInterrupted();
+ }
+
+ results.setErrors(errors.toString());
+ }
+
+ // wait for the return value of the child process.
+ if (!interrupted.get(0) && !lazyQuit)
+ {
+ int returnCode = child.waitFor();
+ results.setReturnCode(returnCode);
+
+ if (returnCode != successCode)
+ {
+ results.setError(ExecResults.BADRETURNCODE);
+ }
+ }
+ } catch (InterruptedException i)
+ {
+ results.setInterrupted();
+ } catch (Throwable t)
+ {
+ results.setThrowable(t);
+ } finally
+ {
+ if (child != null)
+ {
+ child.destroy();
+ }
+ }
+
+ return (results);
+ }
+
+ /*
+ * Execute an OS command and capture the output in an ExecResults. All exceptions are caught and
+ * stored in the ExecResults. @param String command is the OS command to execute @param String
+ * input is piped into the OS command @param int successCode is the expected return code if the
+ * command completes successfully @param int timeout is the number of milliseconds to wait
+ * before interrupting the command @param boolean quit tells the method to exit when there is no
+ * more output waiting
+ */
+ /**
+ * Description of the Method
+ *
+ * @param command
+ * Description of the Parameter
+ * @param input
+ * Description of the Parameter
+ * @param successCode
+ * Description of the Parameter
+ * @param timeout
+ * Description of the Parameter
+ * @param lazy
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static ExecResults execOptions(String command, String input, int successCode, int timeout, boolean lazy)
+ {
+ Process child = null;
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ ByteArrayOutputStream errors = new ByteArrayOutputStream();
+ ExecResults results = new ExecResults(command, input, successCode, timeout);
+ BitSet interrupted = new BitSet(1);
+ boolean lazyQuit = false;
+ ThreadWatcher watcher;
+
+ try
+ {
+ // start the command
+ child = Runtime.getRuntime().exec(command);
+
+ // get the streams in and out of the command
+ InputStream processIn = child.getInputStream();
+ InputStream processError = child.getErrorStream();
+ OutputStream processOut = child.getOutputStream();
+
+ // start the clock running
+ if (timeout > 0)
+ {
+ watcher = new ThreadWatcher(child, interrupted, timeout);
+ new Thread(watcher).start();
+ }
+
+ // Write to the child process' input stream
+ if ((input != null) && !input.equals(""))
+ {
+ try
+ {
+ processOut.write(input.getBytes());
+ processOut.flush();
+ processOut.close();
+ } catch (IOException e1)
+ {
+ results.setThrowable(e1);
+ }
+ }
+
+ // Read from the child process' output stream
+ // The process may get killed by the watcher at any time
+ int c = 0;
+
+ try
+ {
+ while (true)
+ {
+ if (interrupted.get(0) || lazyQuit)
+ {
+ break;
+ }
+
+ // interrupted
+ c = processIn.read();
+
+ if (c == -1)
+ {
+ break;
+ }
+
+ // end of stream
+ output.write(c);
+
+ if (lazy && (processIn.available() < 1))
+ {
+ lazyQuit = true;
+ }
+
+ // if lazy and nothing then quit (after at least one read)
+ }
+
+ processIn.close();
+ } catch (IOException e2)
+ {
+ results.setThrowable(e2);
+ } finally
+ {
+ if (interrupted.get(0))
+ {
+ results.setInterrupted();
+ }
+
+ results.setOutput(output.toString());
+ }
+
+ // Read from the child process' error stream
+ // The process may get killed by the watcher at any time
+ try
+ {
+ while (true)
+ {
+ if (interrupted.get(0) || lazyQuit)
+ {
+ break;
+ }
+
+ // interrupted
+ c = processError.read();
+
+ if (c == -1)
+ {
+ break;
+ }
+
+ // end of stream
+ output.write(c);
+
+ if (lazy && (processError.available() < 1))
+ {
+ lazyQuit = true;
+ }
+
+ // if lazy and nothing then quit (after at least one read)
+ }
+
+ processError.close();
+ } catch (IOException e3)
+ {
+ results.setThrowable(e3);
+ } finally
+ {
+ if (interrupted.get(0))
+ {
+ results.setInterrupted();
+ }
+
+ results.setErrors(errors.toString());
+ }
+
+ // wait for the return value of the child process.
+ if (!interrupted.get(0) && !lazyQuit)
+ {
+ int returnCode = child.waitFor();
+ results.setReturnCode(returnCode);
+
+ if (returnCode != successCode)
+ {
+ results.setError(ExecResults.BADRETURNCODE);
+ }
+ }
+ } catch (InterruptedException i)
+ {
+ results.setInterrupted();
+ } catch (Throwable t)
+ {
+ results.setThrowable(t);
+ } finally
+ {
+ if (child != null)
+ {
+ child.destroy();
+ }
+ }
+
+ return (results);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param command
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static ExecResults execSimple(String[] command)
+ {
+ return (execOptions(command, "", 0, 0, false));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param command
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static ExecResults execSimple(String command)
+ {
+ return (execOptions(command, "", 0, 0, false));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param command
+ * Description of the Parameter
+ * @param args
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static ExecResults execSimple(String command, String args)
+ {
+ return (execOptions(command, args, 0, 0, false));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param command
+ * Description of the Parameter
+ * @param timeout
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static ExecResults execTimeout(String command, int timeout)
+ {
+ return (execOptions(command, "", 0, timeout, false));
+ }
+
+ /**
+ * The main program for the Exec class
+ *
+ * @param args
+ * The command line arguments
+ */
+ public static void main(String[] args)
+ {
+ ExecResults results;
+ String sep = System.getProperty("line.separator");
+ System.out.println("-------------------------------------------" + sep + "TEST 1: execSimple");
+ results = Exec.execSimple("c:/swarm-2.1.1/bin/whoami.exe");
+ System.out.println(results);
+ System.out.println("-------------------------------------------" + sep + "TEST 2: execSimple (with search)");
+ results = Exec.execSimple("netstat -r");
+ System.out.println(results);
+
+ if (results.outputContains("localhost:1031"))
+ {
+ System.out.println("ERROR: listening on 1031");
+ }
+
+ System.out.println("-------------------------------------------" + sep + "TEST 3: execInput");
+ results = Exec.execInput("find \"cde\"", "abcdefg1\nhijklmnop\nqrstuv\nabcdefg2");
+ System.out.println(results);
+ System.out.println("-------------------------------------------" + sep + "TEST 4:execTimeout");
+ results = Exec.execTimeout("ping -t 127.0.0.1", 5 * 1000);
+ System.out.println(results);
+ System.out.println("-------------------------------------------" + sep + "TEST 5:execLazy");
+ results = Exec.execLazy("ping -t 127.0.0.1");
+ System.out.println(results);
+ System.out.println("-------------------------------------------" + sep
+ + "TEST 6:ExecTimeout process never outputs");
+ results = Exec.execTimeout("c:/swarm-2.1.1/bin/sleep.exe 20", 5 * 1000);
+ System.out.println(results);
+ System.out.println("-------------------------------------------" + sep
+ + "TEST 7:ExecTimeout process waits for input");
+ results = Exec.execTimeout("c:/swarm-2.1.1/bin/cat", 5 * 1000);
+ System.out.println(results);
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/ExecResults.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/ExecResults.java
index 020b0b3c6..815ad5654 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/ExecResults.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/ExecResults.java
@@ -1,353 +1,355 @@
-
-package org.owasp.webgoat.util;
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- */
-public class ExecResults
-{
-
- /**
- * Description of the Field
- */
- public final static int BADRETURNCODE = 2;
-
- /**
- * Description of the Field
- */
- public final static int THROWABLE = 1;
-
- private String myCommand;
-
- private boolean myError = false;
-
- private int myErrorType = 0;
-
- private String myErrors = null;
-
- private String myInput;
-
- private boolean myInterrupted = false;
-
- private String myOutput = null;
-
- private int myReturnCode = 0;
-
- private int mySuccessCode;
-
- private Throwable myThrowable = null;
-
- private int myTimeout;
-
- /**
- * Constructor for the ExecResults object
- *
- * @param command
- * Description of the Parameter
- * @param input
- * Description of the Parameter
- * @param successCode
- * Description of the Parameter
- * @param timeout
- * Description of the Parameter
- */
- public ExecResults(String command, String input, int successCode, int timeout)
- {
- myCommand = command.trim();
- myInput = input.trim();
- mySuccessCode = successCode;
- myTimeout = timeout;
- }
-
- /**
- * Description of the Method
- *
- * @param haystack
- * Description of the Parameter
- * @param needle
- * Description of the Parameter
- * @param fromIndex
- * Description of the Parameter
- * @return Description of the Return Value
- */
- private boolean contains(String haystack, String needle, int fromIndex)
- {
- return (haystack.trim().toLowerCase().indexOf(needle.trim().toLowerCase(), fromIndex) != -1);
- }
-
- /**
- * Description of the Method
- *
- * @param value
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public boolean errorsContains(String value)
- {
- return (errorsContains(value, 0));
- }
-
- /**
- * Description of the Method
- *
- * @param value
- * Description of the Parameter
- * @param fromIndex
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public boolean errorsContains(String value, int fromIndex)
- {
- return (contains(myErrors, value, fromIndex));
- }
-
- /**
- * Gets the error attribute of the ExecResults object
- *
- * @return The error value
- */
- public boolean getError()
- {
- return (myError);
- }
-
- /**
- * Gets the errorMessage attribute of the ExecResults object
- *
- * @return The errorMessage value
- */
- public String getErrorMessage()
- {
- switch (getErrorType())
- {
- case THROWABLE:
- return ("Exception: " + myThrowable.getMessage());
-
- case BADRETURNCODE:
- return ("Bad return code (expected " + mySuccessCode + ")");
-
- default:
- return ("Unknown error");
- }
- }
-
- /**
- * Gets the errorType attribute of the ExecResults object
- *
- * @return The errorType value
- */
- public int getErrorType()
- {
- return (myErrorType);
- }
-
- /**
- * Gets the errors attribute of the ExecResults object
- *
- * @return The errors value
- */
- public String getErrors()
- {
- return (myErrors);
- }
-
- /**
- * Gets the interrupted attribute of the ExecResults object
- *
- * @return The interrupted value
- */
- public boolean getInterrupted()
- {
- return (myInterrupted);
- }
-
- /**
- * Gets the output attribute of the ExecResults object
- *
- * @return The output value
- */
- public String getOutput()
- {
- return (myOutput);
- }
-
- /**
- * Gets the returnCode attribute of the ExecResults object
- *
- * @return The returnCode value
- */
- public int getReturnCode()
- {
- return (myReturnCode);
- }
-
- /**
- * Gets the throwable attribute of the ExecResults object
- *
- * @return The throwable value
- */
- public Throwable getThrowable()
- {
- return (myThrowable);
- }
-
- /**
- * Description of the Method
- *
- * @param value
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public boolean outputContains(String value)
- {
- return (outputContains(value, 0));
- }
-
- /**
- * Description of the Method
- *
- * @param value
- * Description of the Parameter
- * @param fromIndex
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public boolean outputContains(String value, int fromIndex)
- {
- return (contains(myOutput, value, fromIndex));
- }
-
- /**
- * Sets the error attribute of the ExecResults object
- *
- * @param value
- * The new error value
- */
- public void setError(int value)
- {
- myError = true;
- myErrorType = value;
- }
-
- /**
- * Sets the errors attribute of the ExecResults object
- *
- * @param errors
- * The new errors value
- */
- public void setErrors(String errors)
- {
- myErrors = errors.trim();
- }
-
- /**
- * Sets the interrupted attribute of the ExecResults object
- */
- public void setInterrupted()
- {
- myInterrupted = true;
- }
-
- /**
- * Sets the output attribute of the ExecResults object
- *
- * @param value
- * The new output value
- */
- public void setOutput(String value)
- {
- myOutput = value.trim();
- }
-
- /**
- * Sets the returnCode attribute of the ExecResults object
- *
- * @param value
- * The new returnCode value
- */
- public void setReturnCode(int value)
- {
- myReturnCode = value;
- }
-
- /**
- * Sets the throwable attribute of the ExecResults object
- *
- * @param value
- * The new throwable value
- */
- public void setThrowable(Throwable value)
- {
- setError(THROWABLE);
- myThrowable = value;
- }
-
- /**
- * Description of the Method
- *
- * @return Description of the Return Value
- */
- public String toString()
- {
- String sep = System.getProperty("line.separator");
- StringBuffer value = new StringBuffer();
- value.append("ExecResults for \'" + myCommand + "\'" + sep);
-
- if ((myInput != null) && !myInput.equals(""))
- {
- value.append(sep + "Input..." + sep + myInput + sep);
- }
-
- if ((myOutput != null) && !myOutput.equals(""))
- {
- value.append(sep + "Output..." + sep + myOutput + sep);
- }
-
- if ((myErrors != null) && !myErrors.equals(""))
- {
- value.append(sep + "Errors..." + sep + myErrors + sep);
- }
-
- value.append(sep);
-
- if (myInterrupted)
- {
- value.append("Command timed out after " + (myTimeout / 1000) + " seconds " + sep);
- }
-
- value.append("Returncode: " + myReturnCode + sep);
-
- if (myError)
- {
- value.append(getErrorMessage() + sep);
- }
-
- return (value.toString());
- }
-}
+
+package org.owasp.webgoat.util;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @version $Id: $Id
+ */
+public class ExecResults
+{
+
+ /**
+ * Description of the Field
+ */
+ public final static int BADRETURNCODE = 2;
+
+ /**
+ * Description of the Field
+ */
+ public final static int THROWABLE = 1;
+
+ private String myCommand;
+
+ private boolean myError = false;
+
+ private int myErrorType = 0;
+
+ private String myErrors = null;
+
+ private String myInput;
+
+ private boolean myInterrupted = false;
+
+ private String myOutput = null;
+
+ private int myReturnCode = 0;
+
+ private int mySuccessCode;
+
+ private Throwable myThrowable = null;
+
+ private int myTimeout;
+
+ /**
+ * Constructor for the ExecResults object
+ *
+ * @param command
+ * Description of the Parameter
+ * @param input
+ * Description of the Parameter
+ * @param successCode
+ * Description of the Parameter
+ * @param timeout
+ * Description of the Parameter
+ */
+ public ExecResults(String command, String input, int successCode, int timeout)
+ {
+ myCommand = command.trim();
+ myInput = input.trim();
+ mySuccessCode = successCode;
+ myTimeout = timeout;
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param haystack
+ * Description of the Parameter
+ * @param needle
+ * Description of the Parameter
+ * @param fromIndex
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ private boolean contains(String haystack, String needle, int fromIndex)
+ {
+ return (haystack.trim().toLowerCase().indexOf(needle.trim().toLowerCase(), fromIndex) != -1);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param value
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public boolean errorsContains(String value)
+ {
+ return (errorsContains(value, 0));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param value
+ * Description of the Parameter
+ * @param fromIndex
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public boolean errorsContains(String value, int fromIndex)
+ {
+ return (contains(myErrors, value, fromIndex));
+ }
+
+ /**
+ * Gets the error attribute of the ExecResults object
+ *
+ * @return The error value
+ */
+ public boolean getError()
+ {
+ return (myError);
+ }
+
+ /**
+ * Gets the errorMessage attribute of the ExecResults object
+ *
+ * @return The errorMessage value
+ */
+ public String getErrorMessage()
+ {
+ switch (getErrorType())
+ {
+ case THROWABLE:
+ return ("Exception: " + myThrowable.getMessage());
+
+ case BADRETURNCODE:
+ return ("Bad return code (expected " + mySuccessCode + ")");
+
+ default:
+ return ("Unknown error");
+ }
+ }
+
+ /**
+ * Gets the errorType attribute of the ExecResults object
+ *
+ * @return The errorType value
+ */
+ public int getErrorType()
+ {
+ return (myErrorType);
+ }
+
+ /**
+ * Gets the errors attribute of the ExecResults object
+ *
+ * @return The errors value
+ */
+ public String getErrors()
+ {
+ return (myErrors);
+ }
+
+ /**
+ * Gets the interrupted attribute of the ExecResults object
+ *
+ * @return The interrupted value
+ */
+ public boolean getInterrupted()
+ {
+ return (myInterrupted);
+ }
+
+ /**
+ * Gets the output attribute of the ExecResults object
+ *
+ * @return The output value
+ */
+ public String getOutput()
+ {
+ return (myOutput);
+ }
+
+ /**
+ * Gets the returnCode attribute of the ExecResults object
+ *
+ * @return The returnCode value
+ */
+ public int getReturnCode()
+ {
+ return (myReturnCode);
+ }
+
+ /**
+ * Gets the throwable attribute of the ExecResults object
+ *
+ * @return The throwable value
+ */
+ public Throwable getThrowable()
+ {
+ return (myThrowable);
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param value
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public boolean outputContains(String value)
+ {
+ return (outputContains(value, 0));
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @param value
+ * Description of the Parameter
+ * @param fromIndex
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public boolean outputContains(String value, int fromIndex)
+ {
+ return (contains(myOutput, value, fromIndex));
+ }
+
+ /**
+ * Sets the error attribute of the ExecResults object
+ *
+ * @param value
+ * The new error value
+ */
+ public void setError(int value)
+ {
+ myError = true;
+ myErrorType = value;
+ }
+
+ /**
+ * Sets the errors attribute of the ExecResults object
+ *
+ * @param errors
+ * The new errors value
+ */
+ public void setErrors(String errors)
+ {
+ myErrors = errors.trim();
+ }
+
+ /**
+ * Sets the interrupted attribute of the ExecResults object
+ */
+ public void setInterrupted()
+ {
+ myInterrupted = true;
+ }
+
+ /**
+ * Sets the output attribute of the ExecResults object
+ *
+ * @param value
+ * The new output value
+ */
+ public void setOutput(String value)
+ {
+ myOutput = value.trim();
+ }
+
+ /**
+ * Sets the returnCode attribute of the ExecResults object
+ *
+ * @param value
+ * The new returnCode value
+ */
+ public void setReturnCode(int value)
+ {
+ myReturnCode = value;
+ }
+
+ /**
+ * Sets the throwable attribute of the ExecResults object
+ *
+ * @param value
+ * The new throwable value
+ */
+ public void setThrowable(Throwable value)
+ {
+ setError(THROWABLE);
+ myThrowable = value;
+ }
+
+ /**
+ * Description of the Method
+ *
+ * @return Description of the Return Value
+ */
+ public String toString()
+ {
+ String sep = System.getProperty("line.separator");
+ StringBuffer value = new StringBuffer();
+ value.append("ExecResults for \'" + myCommand + "\'" + sep);
+
+ if ((myInput != null) && !myInput.equals(""))
+ {
+ value.append(sep + "Input..." + sep + myInput + sep);
+ }
+
+ if ((myOutput != null) && !myOutput.equals(""))
+ {
+ value.append(sep + "Output..." + sep + myOutput + sep);
+ }
+
+ if ((myErrors != null) && !myErrors.equals(""))
+ {
+ value.append(sep + "Errors..." + sep + myErrors + sep);
+ }
+
+ value.append(sep);
+
+ if (myInterrupted)
+ {
+ value.append("Command timed out after " + (myTimeout / 1000) + " seconds " + sep);
+ }
+
+ value.append("Returncode: " + myReturnCode + sep);
+
+ if (myError)
+ {
+ value.append(getErrorMessage() + sep);
+ }
+
+ return (value.toString());
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/ExecutionException.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/ExecutionException.java
index 759807542..6906370f8 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/ExecutionException.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/ExecutionException.java
@@ -1,59 +1,61 @@
-
-package org.owasp.webgoat.util;
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author Jeff Williams Aspect Security
- */
-public class ExecutionException extends Exception
-{
-
- /**
- *
- */
- private static final long serialVersionUID = 7282947463831152092L;
-
- /**
- * Constructor for the ExecutionException object
- */
- public ExecutionException()
- {
- super();
- }
-
- /**
- * Constructor for the ExecutionException object
- *
- * @param msg
- * Description of the Parameter
- */
- public ExecutionException(String msg)
- {
- super(msg);
- }
-}
+
+package org.owasp.webgoat.util;
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author Jeff Williams Aspect Security
+ * @version $Id: $Id
+ */
+public class ExecutionException extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7282947463831152092L;
+
+ /**
+ * Constructor for the ExecutionException object
+ */
+ public ExecutionException()
+ {
+ super();
+ }
+
+ /**
+ * Constructor for the ExecutionException object
+ *
+ * @param msg
+ * Description of the Parameter
+ */
+ public ExecutionException(String msg)
+ {
+ super(msg);
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/HtmlEncoder.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/HtmlEncoder.java
index c7673c900..0ab032059 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/HtmlEncoder.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/HtmlEncoder.java
@@ -1,225 +1,230 @@
-
-package org.owasp.webgoat.util;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public class HtmlEncoder
-{
-
- static Map e2i = new HashMap();
-
- static Map i2e = new HashMap();
-
- // html entity list
- private static Object[][] entities = { { "quot", new Integer(34) }, // " - double-quote
- { "amp", new Integer(38) }, // & - ampersand
- { "lt", new Integer(60) }, // < - less-than
- { "gt", new Integer(62) }, // > - greater-than
- { "nbsp", new Integer(160) }, // non-breaking space
- { "copy", new Integer(169) }, // © - copyright
- { "reg", new Integer(174) }, // ® - registered trademark
- { "Agrave", new Integer(192) }, // À - uppercase A, grave accent
- { "Aacute", new Integer(193) }, // Á - uppercase A, acute accent
- { "Acirc", new Integer(194) }, // Â - uppercase A, circumflex accent
- { "Atilde", new Integer(195) }, // Ã - uppercase A, tilde
- { "Auml", new Integer(196) }, // Ä - uppercase A, umlaut
- { "Aring", new Integer(197) }, // Å - uppercase A, ring
- { "AElig", new Integer(198) }, // Æ - uppercase AE
- { "Ccedil", new Integer(199) }, // Ç - uppercase C, cedilla
- { "Egrave", new Integer(200) }, // È - uppercase E, grave accent
- { "Eacute", new Integer(201) }, // É - uppercase E, acute accent
- { "Ecirc", new Integer(202) }, // Ê - uppercase E, circumflex accent
- { "Euml", new Integer(203) }, // Ë - uppercase E, umlaut
- { "Igrave", new Integer(204) }, // Ì - uppercase I, grave accent
- { "Iacute", new Integer(205) }, // Í - uppercase I, acute accent
- { "Icirc", new Integer(206) }, // Î - uppercase I, circumflex accent
- { "Iuml", new Integer(207) }, // Ï - uppercase I, umlaut
- { "ETH", new Integer(208) }, // Ð - uppercase Eth, Icelandic
- { "Ntilde", new Integer(209) }, // Ñ - uppercase N, tilde
- { "Ograve", new Integer(210) }, // Ò - uppercase O, grave accent
- { "Oacute", new Integer(211) }, // Ó - uppercase O, acute accent
- { "Ocirc", new Integer(212) }, // Ô - uppercase O, circumflex accent
- { "Otilde", new Integer(213) }, // Õ - uppercase O, tilde
- { "Ouml", new Integer(214) }, // Ö - uppercase O, umlaut
- { "Oslash", new Integer(216) }, // Ø - uppercase O, slash
- { "Ugrave", new Integer(217) }, // Ù - uppercase U, grave accent
- { "Uacute", new Integer(218) }, // Ú - uppercase U, acute accent
- { "Ucirc", new Integer(219) }, // Û - uppercase U, circumflex accent
- { "Uuml", new Integer(220) }, // Ü - uppercase U, umlaut
- { "Yacute", new Integer(221) }, // Ý - uppercase Y, acute accent
- { "THORN", new Integer(222) }, // Þ - uppercase THORN, Icelandic
- { "szlig", new Integer(223) }, // ß - lowercase sharps, German
- { "agrave", new Integer(224) }, // à - lowercase a, grave accent
- { "aacute", new Integer(225) }, // á - lowercase a, acute accent
- { "acirc", new Integer(226) }, // â - lowercase a, circumflex accent
- { "atilde", new Integer(227) }, // ã - lowercase a, tilde
- { "auml", new Integer(228) }, // ä - lowercase a, umlaut
- { "aring", new Integer(229) }, // å - lowercase a, ring
- { "aelig", new Integer(230) }, // æ - lowercase ae
- { "ccedil", new Integer(231) }, // ç - lowercase c, cedilla
- { "egrave", new Integer(232) }, // è - lowercase e, grave accent
- { "eacute", new Integer(233) }, // é - lowercase e, acute accent
- { "ecirc", new Integer(234) }, // ê - lowercase e, circumflex accent
- { "euml", new Integer(235) }, // ë - lowercase e, umlaut
- { "igrave", new Integer(236) }, // ì - lowercase i, grave accent
- { "iacute", new Integer(237) }, // í - lowercase i, acute accent
- { "icirc", new Integer(238) }, // î - lowercase i, circumflex accent
- { "iuml", new Integer(239) }, // ï - lowercase i, umlaut
- { "igrave", new Integer(236) }, // ì - lowercase i, grave accent
- { "iacute", new Integer(237) }, // í - lowercase i, acute accent
- { "icirc", new Integer(238) }, // î - lowercase i, circumflex accent
- { "iuml", new Integer(239) }, // ï - lowercase i, umlaut
- { "eth", new Integer(240) }, // ð - lowercase eth, Icelandic
- { "ntilde", new Integer(241) }, // ñ - lowercase n, tilde
- { "ograve", new Integer(242) }, // ò - lowercase o, grave accent
- { "oacute", new Integer(243) }, // ó - lowercase o, acute accent
- { "ocirc", new Integer(244) }, // ô - lowercase o, circumflex accent
- { "otilde", new Integer(245) }, // õ - lowercase o, tilde
- { "ouml", new Integer(246) }, // ö - lowercase o, umlaut
- { "oslash", new Integer(248) }, // ø - lowercase o, slash
- { "ugrave", new Integer(249) }, // ù - lowercase u, grave accent
- { "uacute", new Integer(250) }, // ú - lowercase u, acute accent
- { "ucirc", new Integer(251) }, // û - lowercase u, circumflex accent
- { "uuml", new Integer(252) }, // ü - lowercase u, umlaut
- { "yacute", new Integer(253) }, // ý - lowercase y, acute accent
- { "thorn", new Integer(254) }, // þ - lowercase thorn, Icelandic
- { "yuml", new Integer(255) }, // ÿ - lowercase y, umlaut
- { "euro", new Integer(8364) },// Euro symbol
- };
-
- public HtmlEncoder()
- {
- for (int i = 0; i < entities.length; i++)
- e2i.put((String) entities[i][0], (Integer) entities[i][1]);
- for (int i = 0; i < entities.length; i++)
- i2e.put((Integer) entities[i][1], (String) entities[i][0]);
- }
-
- /**
- * Turns funky characters into HTML entity equivalents
- *
- *
- * e.g. "bread" & "butter" => "bread" &
- * "butter" . Update: supports nearly all HTML entities, including funky
- * accents. See the source code for more detail. Adapted from
- * http://www.purpletech.com/code/src/com/purpletech/util/Utils.java.
- *
- * @param s1
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static String encode(String s1)
- {
- StringBuffer buf = new StringBuffer();
-
- int i;
- for (i = 0; i < s1.length(); ++i)
- {
- char ch = s1.charAt(i);
-
- String entity = i2e.get(new Integer((int) ch));
-
- if (entity == null)
- {
- if (((int) ch) > 128)
- {
- buf.append("" + ((int) ch) + ";");
- }
- else
- {
- buf.append(ch);
- }
- }
- else
- {
- buf.append("&" + entity + ";");
- }
- }
-
- return buf.toString();
- }
-
- /**
- * Given a string containing entity escapes, returns a string containing the actual Unicode
- * characters corresponding to the escapes. Adapted from
- * http://www.purpletech.com/code/src/com/purpletech/util/Utils.java.
- *
- * @param s1
- * Description of the Parameter
- * @return Description of the Return Value
- */
- public static String decode(String s1)
- {
- StringBuffer buf = new StringBuffer();
-
- int i;
- for (i = 0; i < s1.length(); ++i)
- {
- char ch = s1.charAt(i);
-
- if (ch == '&')
- {
- int semi = s1.indexOf(';', i + 1);
- if (semi == -1)
- {
- buf.append(ch);
- continue;
- }
- String entity = s1.substring(i + 1, semi);
- Integer iso;
- if (entity.charAt(0) == '#')
- {
- iso = new Integer(entity.substring(1));
- }
- else
- {
- iso = e2i.get(entity);
- }
- if (iso == null)
- {
- buf.append("&" + entity + ";");
- }
- else
- {
- buf.append((char) (iso.intValue()));
- }
- i = semi;
- }
- else
- {
- buf.append(ch);
- }
- }
-
- return buf.toString();
- }
-}
+
+package org.owasp.webgoat.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public class HtmlEncoder
+{
+
+ static Map e2i = new HashMap();
+
+ static Map i2e = new HashMap();
+
+ // html entity list
+ private static Object[][] entities = { { "quot", new Integer(34) }, // " - double-quote
+ { "amp", new Integer(38) }, // - ampersand
+ { "lt", new Integer(60) }, // - less-than
+ { "gt", new Integer(62) }, // - greater-than
+ { "nbsp", new Integer(160) }, // non-breaking space
+ { "copy", new Integer(169) }, // - copyright
+ { "reg", new Integer(174) }, // - registered trademark
+ { "Agrave", new Integer(192) }, // - uppercase A, grave accent
+ { "Aacute", new Integer(193) }, // - uppercase A, acute accent
+ { "Acirc", new Integer(194) }, // - uppercase A, circumflex accent
+ { "Atilde", new Integer(195) }, // - uppercase A, tilde
+ { "Auml", new Integer(196) }, // - uppercase A, umlaut
+ { "Aring", new Integer(197) }, // - uppercase A, ring
+ { "AElig", new Integer(198) }, // - uppercase AE
+ { "Ccedil", new Integer(199) }, // - uppercase C, cedilla
+ { "Egrave", new Integer(200) }, // - uppercase E, grave accent
+ { "Eacute", new Integer(201) }, // - uppercase E, acute accent
+ { "Ecirc", new Integer(202) }, // - uppercase E, circumflex accent
+ { "Euml", new Integer(203) }, // - uppercase E, umlaut
+ { "Igrave", new Integer(204) }, // - uppercase I, grave accent
+ { "Iacute", new Integer(205) }, // - uppercase I, acute accent
+ { "Icirc", new Integer(206) }, // - uppercase I, circumflex accent
+ { "Iuml", new Integer(207) }, // - uppercase I, umlaut
+ { "ETH", new Integer(208) }, // - uppercase Eth, Icelandic
+ { "Ntilde", new Integer(209) }, // - uppercase N, tilde
+ { "Ograve", new Integer(210) }, // - uppercase O, grave accent
+ { "Oacute", new Integer(211) }, // - uppercase O, acute accent
+ { "Ocirc", new Integer(212) }, // - uppercase O, circumflex accent
+ { "Otilde", new Integer(213) }, // - uppercase O, tilde
+ { "Ouml", new Integer(214) }, // - uppercase O, umlaut
+ { "Oslash", new Integer(216) }, // - uppercase O, slash
+ { "Ugrave", new Integer(217) }, // - uppercase U, grave accent
+ { "Uacute", new Integer(218) }, // - uppercase U, acute accent
+ { "Ucirc", new Integer(219) }, // - uppercase U, circumflex accent
+ { "Uuml", new Integer(220) }, // - uppercase U, umlaut
+ { "Yacute", new Integer(221) }, // - uppercase Y, acute accent
+ { "THORN", new Integer(222) }, // - uppercase THORN, Icelandic
+ { "szlig", new Integer(223) }, // - lowercase sharps, German
+ { "agrave", new Integer(224) }, // - lowercase a, grave accent
+ { "aacute", new Integer(225) }, // - lowercase a, acute accent
+ { "acirc", new Integer(226) }, // - lowercase a, circumflex accent
+ { "atilde", new Integer(227) }, // - lowercase a, tilde
+ { "auml", new Integer(228) }, // - lowercase a, umlaut
+ { "aring", new Integer(229) }, // - lowercase a, ring
+ { "aelig", new Integer(230) }, // - lowercase ae
+ { "ccedil", new Integer(231) }, // - lowercase c, cedilla
+ { "egrave", new Integer(232) }, // - lowercase e, grave accent
+ { "eacute", new Integer(233) }, // - lowercase e, acute accent
+ { "ecirc", new Integer(234) }, // - lowercase e, circumflex accent
+ { "euml", new Integer(235) }, // - lowercase e, umlaut
+ { "igrave", new Integer(236) }, // - lowercase i, grave accent
+ { "iacute", new Integer(237) }, // - lowercase i, acute accent
+ { "icirc", new Integer(238) }, // - lowercase i, circumflex accent
+ { "iuml", new Integer(239) }, // - lowercase i, umlaut
+ { "igrave", new Integer(236) }, // - lowercase i, grave accent
+ { "iacute", new Integer(237) }, // - lowercase i, acute accent
+ { "icirc", new Integer(238) }, // - lowercase i, circumflex accent
+ { "iuml", new Integer(239) }, // - lowercase i, umlaut
+ { "eth", new Integer(240) }, // - lowercase eth, Icelandic
+ { "ntilde", new Integer(241) }, // - lowercase n, tilde
+ { "ograve", new Integer(242) }, // - lowercase o, grave accent
+ { "oacute", new Integer(243) }, // - lowercase o, acute accent
+ { "ocirc", new Integer(244) }, // - lowercase o, circumflex accent
+ { "otilde", new Integer(245) }, // - lowercase o, tilde
+ { "ouml", new Integer(246) }, // - lowercase o, umlaut
+ { "oslash", new Integer(248) }, // - lowercase o, slash
+ { "ugrave", new Integer(249) }, // - lowercase u, grave accent
+ { "uacute", new Integer(250) }, // - lowercase u, acute accent
+ { "ucirc", new Integer(251) }, // - lowercase u, circumflex accent
+ { "uuml", new Integer(252) }, // - lowercase u, umlaut
+ { "yacute", new Integer(253) }, // - lowercase y, acute accent
+ { "thorn", new Integer(254) }, // - lowercase thorn, Icelandic
+ { "yuml", new Integer(255) }, // - lowercase y, umlaut
+ { "euro", new Integer(8364) },// Euro symbol
+ };
+
+ /**
+ * Constructor for HtmlEncoder.
+ */
+ public HtmlEncoder()
+ {
+ for (int i = 0; i < entities.length; i++)
+ e2i.put((String) entities[i][0], (Integer) entities[i][1]);
+ for (int i = 0; i < entities.length; i++)
+ i2e.put((Integer) entities[i][1], (String) entities[i][0]);
+ }
+
+ /**
+ * Turns funky characters into HTML entity equivalents
+ *
+ * e.g. {@code "bread" & "butter"} = {@code "bread" &
+ * "butter"}. Update: supports nearly all HTML entities, including funky
+ * accents. See the source code for more detail. Adapted from
+ * http://www.purpletech.com/code/src/com/purpletech/util/Utils.java.
+ *
+ * @param s1
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static String encode(String s1)
+ {
+ StringBuffer buf = new StringBuffer();
+
+ int i;
+ for (i = 0; i < s1.length(); ++i)
+ {
+ char ch = s1.charAt(i);
+
+ String entity = i2e.get(new Integer((int) ch));
+
+ if (entity == null)
+ {
+ if (((int) ch) > 128)
+ {
+ buf.append("" + ((int) ch) + ";");
+ }
+ else
+ {
+ buf.append(ch);
+ }
+ }
+ else
+ {
+ buf.append("&" + entity + ";");
+ }
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * Given a string containing entity escapes, returns a string containing the actual Unicode
+ * characters corresponding to the escapes. Adapted from
+ * http://www.purpletech.com/code/src/com/purpletech/util/Utils.java.
+ *
+ * @param s1
+ * Description of the Parameter
+ * @return Description of the Return Value
+ */
+ public static String decode(String s1)
+ {
+ StringBuffer buf = new StringBuffer();
+
+ int i;
+ for (i = 0; i < s1.length(); ++i)
+ {
+ char ch = s1.charAt(i);
+
+ if (ch == '&')
+ {
+ int semi = s1.indexOf(';', i + 1);
+ if (semi == -1)
+ {
+ buf.append(ch);
+ continue;
+ }
+ String entity = s1.substring(i + 1, semi);
+ Integer iso;
+ if (entity.charAt(0) == '#')
+ {
+ iso = new Integer(entity.substring(1));
+ }
+ else
+ {
+ iso = e2i.get(entity);
+ }
+ if (iso == null)
+ {
+ buf.append("&" + entity + ";");
+ }
+ else
+ {
+ buf.append((char) (iso.intValue()));
+ }
+ i = semi;
+ }
+ else
+ {
+ buf.append(ch);
+ }
+ }
+
+ return buf.toString();
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/Interceptor.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/Interceptor.java
index 8616863f6..bb9af6e6c 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/Interceptor.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/Interceptor.java
@@ -1,143 +1,149 @@
-/**
- *
- */
-
-package org.owasp.webgoat.util;
-
-import java.io.IOException;
-import java.io.BufferedReader;
-import java.io.PrintWriter;
-import java.io.InputStreamReader;
-import java.net.UnknownHostException;
-import java.net.Socket;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.http.HttpServletRequest;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author sherif koussa - Macadamian Technologies
- *
- */
-public class Interceptor implements Filter
-{
-
- private static final String OSG_SERVER_NAME = "OSGServerName";
-
- private static final String OSG_SERVER_PORT = "OSGServerPort";
-
- /*
- * (non-Javadoc)
- * @see javax.servlet.Filter#destroy()
- */
- public void destroy()
- {
- // TODO Auto-generated method stub
-
- }
-
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
- ServletException
- {
-
- HttpServletRequest req = (HttpServletRequest) request;
-
- Socket osgSocket = null;
- PrintWriter out = null;
- BufferedReader in = null;
- String osgServerName = req.getSession().getServletContext().getInitParameter(OSG_SERVER_NAME);
- String osgServerPort = req.getSession().getServletContext().getInitParameter(OSG_SERVER_PORT);
-
- try
- {
- // If these parameters are not defined then no communication will happen with OSG
- if (osgServerName != null && osgServerName.length() != 0 && osgServerPort != null
- && osgServerPort.length() != 0)
- {
- osgSocket = new Socket(osgServerName, Integer.parseInt(osgServerPort));
- if (osgSocket != null)
- {
- out = new PrintWriter(osgSocket.getOutputStream(), true);
- in = new BufferedReader(new InputStreamReader(osgSocket.getInputStream()));
- // String message =
- // "HTTPRECEIVEHTTPREQUEST,-,DataValidation_SqlInjection_Basic.aspx";
- // out.println(message);
-
- // System.out.println(in.readLine());
- }
- }
-
- } catch (UnknownHostException e)
- {
- e.printStackTrace();
-
- } catch (IOException e)
- {
- e.printStackTrace();
- } finally
- {
- if (out != null)
- {
- out.close();
- }
- if (in != null)
- {
- in.close();
- }
- if (osgSocket != null)
- {
- osgSocket.close();
- }
- }
-
- String url = req.getRequestURL().toString();
-
- RequestDispatcher disp = req.getRequestDispatcher(url.substring(url.lastIndexOf(req.getContextPath() + "/")
- + req.getContextPath().length()));
-
- disp.forward(request, response);
-
- }
-
- /*
- * (non-Javadoc)
- * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
- */
- public void init(FilterConfig arg0) throws ServletException
- {
- // TODO Auto-generated method stub
-
- }
-
-}
+/**
+ *
+ */
+
+package org.owasp.webgoat.util;
+
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.PrintWriter;
+import java.io.InputStreamReader;
+import java.net.UnknownHostException;
+import java.net.Socket;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author sherif koussa - Macadamian Technologies
+ * @version $Id: $Id
+ */
+public class Interceptor implements Filter
+{
+
+ private static final String OSG_SERVER_NAME = "OSGServerName";
+
+ private static final String OSG_SERVER_PORT = "OSGServerPort";
+
+ /*
+ * (non-Javadoc)
+ * @see javax.servlet.Filter#destroy()
+ */
+ /**
+ * destroy.
+ */
+ public void destroy()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /** {@inheritDoc} */
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
+ ServletException
+ {
+
+ HttpServletRequest req = (HttpServletRequest) request;
+
+ Socket osgSocket = null;
+ PrintWriter out = null;
+ BufferedReader in = null;
+ String osgServerName = req.getSession().getServletContext().getInitParameter(OSG_SERVER_NAME);
+ String osgServerPort = req.getSession().getServletContext().getInitParameter(OSG_SERVER_PORT);
+
+ try
+ {
+ // If these parameters are not defined then no communication will happen with OSG
+ if (osgServerName != null && osgServerName.length() != 0 && osgServerPort != null
+ && osgServerPort.length() != 0)
+ {
+ osgSocket = new Socket(osgServerName, Integer.parseInt(osgServerPort));
+ if (osgSocket != null)
+ {
+ out = new PrintWriter(osgSocket.getOutputStream(), true);
+ in = new BufferedReader(new InputStreamReader(osgSocket.getInputStream()));
+ // String message =
+ // "HTTPRECEIVEHTTPREQUEST,-,DataValidation_SqlInjection_Basic.aspx";
+ // out.println(message);
+
+ // System.out.println(in.readLine());
+ }
+ }
+
+ } catch (UnknownHostException e)
+ {
+ e.printStackTrace();
+
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ } finally
+ {
+ if (out != null)
+ {
+ out.close();
+ }
+ if (in != null)
+ {
+ in.close();
+ }
+ if (osgSocket != null)
+ {
+ osgSocket.close();
+ }
+ }
+
+ String url = req.getRequestURL().toString();
+
+ RequestDispatcher disp = req.getRequestDispatcher(url.substring(url.lastIndexOf(req.getContextPath() + "/")
+ + req.getContextPath().length()));
+
+ disp.forward(request, response);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
+ */
+ /** {@inheritDoc} */
+ public void init(FilterConfig arg0) throws ServletException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManager.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManager.java
index b83e0a538..b55061c19 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManager.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManager.java
@@ -1,41 +1,55 @@
-
-package org.owasp.webgoat.util;
-
-import java.util.Locale;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for
- * free software projects.
- *
- * For details, please see http://webgoat.github.io
- */
-public interface LabelManager
-{
-
- public void setLocale(Locale locale);
-
- public String get(String labelKey);
-
-}
+
+package org.owasp.webgoat.util;
+
+import java.util.Locale;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for
+ * free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+public interface LabelManager
+{
+
+ /**
+ * setLocale.
+ *
+ * @param locale a {@link java.util.Locale} object.
+ */
+ public void setLocale(Locale locale);
+
+ /**
+ * get.
+ *
+ * @param labelKey a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String get(String labelKey);
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManagerImpl.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManagerImpl.java
index 2c6b59661..23c2c0a8f 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManagerImpl.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelManagerImpl.java
@@ -1,68 +1,81 @@
-
-package org.owasp.webgoat.util;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.io.Serializable;
-import java.util.Locale;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for
- * free software projects.
- *
- * For details, please see http://webgoat.github.io
- */
-@Component("labelManager")
-public class LabelManagerImpl implements LabelManager, Serializable
-{
- private static final long serialVersionUID = 1L;
-
- @Autowired
- private transient LabelProvider labelProvider;
-
- /** Locale mapped with current session. */
- private Locale locale = new Locale(LabelProvider.DEFAULT_LANGUAGE);
-
- protected LabelManagerImpl() {}
-
- protected LabelManagerImpl(LabelProvider labelProvider) {
- this.labelProvider = labelProvider;
- }
-
- public void setLocale(Locale locale)
- {
- if (locale != null)
- {
- this.locale = locale;
- }
- }
-
- public String get(String labelKey)
- {
- return labelProvider.get(locale, labelKey);
- }
-
-}
+
+package org.owasp.webgoat.util;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+import java.util.Locale;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for
+ * free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+@Component("labelManager")
+public class LabelManagerImpl implements LabelManager, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ @Autowired
+ private transient LabelProvider labelProvider;
+
+ /** Locale mapped with current session. */
+ private Locale locale = new Locale(LabelProvider.DEFAULT_LANGUAGE);
+
+ /**
+ * Constructor for LabelManagerImpl.
+ */
+ protected LabelManagerImpl() {}
+
+ /**
+ * Constructor for LabelManagerImpl.
+ *
+ * @param labelProvider a {@link org.owasp.webgoat.util.LabelProvider} object.
+ */
+ protected LabelManagerImpl(LabelProvider labelProvider) {
+ this.labelProvider = labelProvider;
+ }
+
+ /** {@inheritDoc} */
+ public void setLocale(Locale locale)
+ {
+ if (locale != null)
+ {
+ this.locale = locale;
+ }
+ }
+
+ /** {@inheritDoc} */
+ public String get(String labelKey)
+ {
+ return labelProvider.get(locale, labelKey);
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelProvider.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelProvider.java
index f05580c48..7a9f11efa 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelProvider.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/LabelProvider.java
@@ -1,100 +1,123 @@
-
-package org.owasp.webgoat.util;
-
-import org.springframework.context.support.ReloadableResourceBundleMessageSource;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.ResourceLoader;
-import org.springframework.core.io.UrlResource;
-import org.springframework.stereotype.Component;
-import org.springframework.util.DefaultPropertiesPersister;
-
-import javax.inject.Singleton;
-import java.net.MalformedURLException;
-import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Locale;
-
-
-/**
- * ************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for
- * free software projects.
- *
- * For details, please see http://webgoat.github.io
- */
-@Component
-@Singleton
-public class LabelProvider {
- public final static String DEFAULT_LANGUAGE = Locale.ENGLISH.getLanguage();
-
- private static final List SUPPORTED = Arrays.asList(Locale.GERMAN, Locale.FRENCH, Locale.ENGLISH,
- Locale.forLanguageTag("ru"));
- private final ReloadableResourceBundleMessageSource labels = new ReloadableResourceBundleMessageSource();
- private static final ReloadableResourceBundleMessageSource pluginLabels = new ReloadableResourceBundleMessageSource();
-
- public LabelProvider() {
- labels.setBasename("classpath:/i18n/WebGoatLabels");
- labels.setFallbackToSystemLocale(false);
- labels.setUseCodeAsDefaultMessage(true);
- pluginLabels.setParentMessageSource(labels);
- pluginLabels.setPropertiesPersister(new DefaultPropertiesPersister() {
-
- });
- }
-
- public static void updatePluginResources(final Path propertyFile) {
- pluginLabels.setBasename("WebGoatLabels");
- pluginLabels.setFallbackToSystemLocale(false);
- pluginLabels.setUseCodeAsDefaultMessage(true);
- pluginLabels.setResourceLoader(new ResourceLoader() {
- @Override
- public Resource getResource(String location) {
- try {
- return new UrlResource(propertyFile.toUri());
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public ClassLoader getClassLoader() {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
-
- public static void refresh() {
- pluginLabels.clearCache();
- }
-
- public String get(Locale locale, String strName) {
- return pluginLabels.getMessage(strName, null, useLocaleOrFallbackToEnglish(locale));
- }
-
- private Locale useLocaleOrFallbackToEnglish(Locale locale) {
- return SUPPORTED.contains(locale) ? Locale.ENGLISH : locale;
- }
-
-}
+
+package org.owasp.webgoat.util;
+
+import org.springframework.context.support.ReloadableResourceBundleMessageSource;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.UrlResource;
+import org.springframework.stereotype.Component;
+import org.springframework.util.DefaultPropertiesPersister;
+
+import javax.inject.Singleton;
+import java.net.MalformedURLException;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+
+
+/**
+ * *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project
+ * utility. For details, please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository
+ * for free software projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @version $Id: $Id
+ */
+@Component
+@Singleton
+public class LabelProvider {
+ /** Constant DEFAULT_LANGUAGE="Locale.ENGLISH.getLanguage()"
*/
+ public final static String DEFAULT_LANGUAGE = Locale.ENGLISH.getLanguage();
+
+ private static final List SUPPORTED = Arrays.asList(Locale.GERMAN, Locale.FRENCH, Locale.ENGLISH,
+ Locale.forLanguageTag("ru"));
+ private final ReloadableResourceBundleMessageSource labels = new ReloadableResourceBundleMessageSource();
+ private static final ReloadableResourceBundleMessageSource pluginLabels = new ReloadableResourceBundleMessageSource();
+
+ /**
+ * Constructor for LabelProvider.
+ */
+ public LabelProvider() {
+ labels.setBasename("classpath:/i18n/WebGoatLabels");
+ labels.setFallbackToSystemLocale(false);
+ labels.setUseCodeAsDefaultMessage(true);
+ pluginLabels.setParentMessageSource(labels);
+ pluginLabels.setPropertiesPersister(new DefaultPropertiesPersister() {
+
+ });
+ }
+
+ /**
+ * updatePluginResources.
+ *
+ * @param propertyFile a {@link java.nio.file.Path} object.
+ */
+ public static void updatePluginResources(final Path propertyFile) {
+ pluginLabels.setBasename("WebGoatLabels");
+ pluginLabels.setFallbackToSystemLocale(false);
+ pluginLabels.setUseCodeAsDefaultMessage(true);
+ pluginLabels.setResourceLoader(new ResourceLoader() {
+ @Override
+ public Resource getResource(String location) {
+ try {
+ return new UrlResource(propertyFile.toUri());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public ClassLoader getClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+
+ /**
+ * refresh.
+ */
+ public static void refresh() {
+ pluginLabels.clearCache();
+ }
+
+ /**
+ * get.
+ *
+ * @param locale a {@link java.util.Locale} object.
+ * @param strName a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public String get(Locale locale, String strName) {
+ return pluginLabels.getMessage(strName, null, useLocaleOrFallbackToEnglish(locale));
+ }
+
+ private Locale useLocaleOrFallbackToEnglish(Locale locale) {
+ return SUPPORTED.contains(locale) ? Locale.ENGLISH : locale;
+ }
+
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/ThreadWatcher.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/ThreadWatcher.java
index 8dc28a4df..4b411ca1f 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/ThreadWatcher.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/ThreadWatcher.java
@@ -1,103 +1,105 @@
-
-package org.owasp.webgoat.util;
-
-import java.util.BitSet;
-
-
-/***************************************************************************************************
- *
- *
- * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
- * please see http://www.owasp.org/
- *
- * Copyright (c) 2002 - 20014 Bruce Mayhew
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program; if
- * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- * Getting Source ==============
- *
- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
- * projects.
- *
- * For details, please see http://webgoat.github.io
- *
- * @author jwilliams@aspectsecurity.com
- * @created November 6, 2002
- */
-public class ThreadWatcher implements Runnable
-{
-
- // time to live in milliseconds
- private BitSet myInterrupted;
-
- private Process myProcess;
-
- private int myTimeout;
-
- /**
- * Constructor for the ThreadWatcher object
- *
- * @param p
- * Description of the Parameter
- * @param interrupted
- * Description of the Parameter
- * @param timeout
- * Description of the Parameter
- */
- public ThreadWatcher(Process p, BitSet interrupted, int timeout)
- {
- myProcess = p;
-
- // thread used by whoever constructed this watcher
- myTimeout = timeout;
- myInterrupted = interrupted;
- }
-
- /*
- * Interrupt the thread by marking the interrupted bit and killing the process
- */
-
- /**
- * Description of the Method
- */
- public void interrupt()
- {
- myInterrupted.set(0);
-
- // set interrupted bit (bit 0 of the bitset) to 1
- myProcess.destroy();
-
- /*
- * try { myProcess.getInputStream().close(); } catch( IOException e1 ) { / do nothing --
- * input streams are probably already closed } try { myProcess.getErrorStream().close(); }
- * catch( IOException e2 ) { / do nothing -- input streams are probably already closed }
- * myThread.interrupt();
- */
- }
-
- /**
- * Main processing method for the ThreadWatcher object
- */
- public void run()
- {
- try
- {
- Thread.sleep(myTimeout);
- } catch (InterruptedException e)
- {
- // do nothing -- if watcher is interrupted, so is thread
- }
-
- interrupt();
- }
-}
+
+package org.owasp.webgoat.util;
+
+import java.util.BitSet;
+
+
+/**
+ *************************************************************************************************
+ *
+ *
+ * This file is part of WebGoat, an Open Web Application Security Project utility. For details,
+ * please see http://www.owasp.org/
+ *
+ * Copyright (c) 2002 - 20014 Bruce Mayhew
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program; if
+ * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Getting Source ==============
+ *
+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software
+ * projects.
+ *
+ * For details, please see http://webgoat.github.io
+ *
+ * @author jwilliams@aspectsecurity.com
+ * @since November 6, 2002
+ * @version $Id: $Id
+ */
+public class ThreadWatcher implements Runnable
+{
+
+ // time to live in milliseconds
+ private BitSet myInterrupted;
+
+ private Process myProcess;
+
+ private int myTimeout;
+
+ /**
+ * Constructor for the ThreadWatcher object
+ *
+ * @param p
+ * Description of the Parameter
+ * @param interrupted
+ * Description of the Parameter
+ * @param timeout
+ * Description of the Parameter
+ */
+ public ThreadWatcher(Process p, BitSet interrupted, int timeout)
+ {
+ myProcess = p;
+
+ // thread used by whoever constructed this watcher
+ myTimeout = timeout;
+ myInterrupted = interrupted;
+ }
+
+ /*
+ * Interrupt the thread by marking the interrupted bit and killing the process
+ */
+
+ /**
+ * Description of the Method
+ */
+ public void interrupt()
+ {
+ myInterrupted.set(0);
+
+ // set interrupted bit (bit 0 of the bitset) to 1
+ myProcess.destroy();
+
+ /*
+ * try { myProcess.getInputStream().close(); } catch( IOException e1 ) { / do nothing --
+ * input streams are probably already closed } try { myProcess.getErrorStream().close(); }
+ * catch( IOException e2 ) { / do nothing -- input streams are probably already closed }
+ * myThread.interrupt();
+ */
+ }
+
+ /**
+ * Main processing method for the ThreadWatcher object
+ */
+ public void run()
+ {
+ try
+ {
+ Thread.sleep(myTimeout);
+ } catch (InterruptedException e)
+ {
+ // do nothing -- if watcher is interrupted, so is thread
+ }
+
+ interrupt();
+ }
+}
diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/util/WebGoatI18N.java b/webgoat-container/src/main/java/org/owasp/webgoat/util/WebGoatI18N.java
index 8285f76fd..0fb188621 100644
--- a/webgoat-container/src/main/java/org/owasp/webgoat/util/WebGoatI18N.java
+++ b/webgoat-container/src/main/java/org/owasp/webgoat/util/WebGoatI18N.java
@@ -1,66 +1,92 @@
-package org.owasp.webgoat.util;
-
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.ResourceBundle;
-
-import org.owasp.webgoat.session.WebgoatContext;
-
-@Deprecated
-public class WebGoatI18N
-{
-
- private static HashMap labels = new HashMap();
- private static Locale currentLocale;
- private static WebGoatResourceBundleController localeController;
-
- public WebGoatI18N(WebgoatContext context)
- {
- currentLocale = new Locale(context.getDefaultLanguage());
- localeController = new WebGoatResourceBundleController(currentLocale);
- }
-
- @Deprecated
- public static void loadLanguage(String language)
- {
- // Do nothing
- }
-
- public static void setCurrentLocale(Locale locale)
- {
- if (!currentLocale.equals(locale))
- {
- if (!labels.containsKey(locale))
- {
- ResourceBundle resBundle = ResourceBundle.getBundle("WebGoatLabels", locale, localeController);
- labels.put(locale, resBundle);
- }
- WebGoatI18N.currentLocale = locale;
- }
- }
-
- public static String get(String strName)
- {
- return labels.get(WebGoatI18N.currentLocale).getString(strName);
- }
-
- private static class WebGoatResourceBundleController extends ResourceBundle.Control
- {
- private Locale fallbackLocale;
-
- public WebGoatResourceBundleController(Locale l)
- {
- fallbackLocale = l;
- }
-
- @Override
- public Locale getFallbackLocale(String baseName, Locale locale)
- {
- if(! fallbackLocale.equals(locale)) {
- return fallbackLocale;
- }
- return Locale.ROOT;
- }
- }
-
-}
+package org.owasp.webgoat.util;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.owasp.webgoat.session.WebgoatContext;
+
+@Deprecated
+/**
+ * WebGoatI18N class.
+ *
+ * @version $Id: $Id
+ */
+public class WebGoatI18N
+{
+
+ private static HashMap labels = new HashMap();
+ private static Locale currentLocale;
+ private static WebGoatResourceBundleController localeController;
+
+ /**
+ * Constructor for WebGoatI18N.
+ *
+ * @param context a {@link org.owasp.webgoat.session.WebgoatContext} object.
+ */
+ public WebGoatI18N(WebgoatContext context)
+ {
+ currentLocale = new Locale(context.getDefaultLanguage());
+ localeController = new WebGoatResourceBundleController(currentLocale);
+ }
+
+ /**
+ * loadLanguage.
+ *
+ * @param language a {@link java.lang.String} object.
+ */
+ @Deprecated
+ public static void loadLanguage(String language)
+ {
+ // Do nothing
+ }
+
+ /**
+ * Setter for the field currentLocale
.
+ *
+ * @param locale a {@link java.util.Locale} object.
+ */
+ public static void setCurrentLocale(Locale locale)
+ {
+ if (!currentLocale.equals(locale))
+ {
+ if (!labels.containsKey(locale))
+ {
+ ResourceBundle resBundle = ResourceBundle.getBundle("WebGoatLabels", locale, localeController);
+ labels.put(locale, resBundle);
+ }
+ WebGoatI18N.currentLocale = locale;
+ }
+ }
+
+ /**
+ * get.
+ *
+ * @param strName a {@link java.lang.String} object.
+ * @return a {@link java.lang.String} object.
+ */
+ public static String get(String strName)
+ {
+ return labels.get(WebGoatI18N.currentLocale).getString(strName);
+ }
+
+ private static class WebGoatResourceBundleController extends ResourceBundle.Control
+ {
+ private Locale fallbackLocale;
+
+ public WebGoatResourceBundleController(Locale l)
+ {
+ fallbackLocale = l;
+ }
+
+ @Override
+ public Locale getFallbackLocale(String baseName, Locale locale)
+ {
+ if(! fallbackLocale.equals(locale)) {
+ return fallbackLocale;
+ }
+ return Locale.ROOT;
+ }
+ }
+
+}