Reformat of Java source. Added JavaStyle format definitions.
git-svn-id: http://webgoat.googlecode.com/svn/trunk/webgoat@287 4033779f-a91e-0410-96ef-6bf7bf53c507
This commit is contained in:
@ -1,10 +1,12 @@
|
||||
|
||||
package org.owasp.webgoat.session;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
public class WebgoatContext {
|
||||
|
||||
public class WebgoatContext
|
||||
{
|
||||
|
||||
public final static String DATABASE_CONNECTION_STRING = "DatabaseConnectionString";
|
||||
|
||||
@ -17,7 +19,7 @@ public class WebgoatContext {
|
||||
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";
|
||||
@ -25,9 +27,9 @@ public class WebgoatContext {
|
||||
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";
|
||||
@ -61,7 +63,7 @@ public class WebgoatContext {
|
||||
private boolean enterprise = false;
|
||||
|
||||
private boolean codingExercises = false;
|
||||
|
||||
|
||||
private String feedbackAddress = "<A HREF=mailto:webgoat@owasp.org>webgoat@owasp.org</A>";
|
||||
|
||||
private boolean isDebug = false;
|
||||
@ -70,57 +72,56 @@ public class WebgoatContext {
|
||||
|
||||
private HttpServlet servlet;
|
||||
|
||||
public WebgoatContext(HttpServlet servlet) {
|
||||
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 ) );
|
||||
feedbackAddress = getParameter(servlet, FEEDBACK_ADDRESS ) != null ?
|
||||
getParameter(servlet, FEEDBACK_ADDRESS ) : feedbackAddress;
|
||||
showRequest = "true".equals( getParameter(servlet, SHOWREQUEST ) );
|
||||
isDebug = "true".equals( getParameter(servlet, DEBUG ) );
|
||||
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));
|
||||
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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String getParameter(HttpServlet servlet, String key) {
|
||||
private String getParameter(HttpServlet servlet, String key)
|
||||
{
|
||||
String value = System.getenv().get(key);
|
||||
if (value == null)
|
||||
value = servlet.getInitParameter(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
|
||||
* 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) {
|
||||
System.out
|
||||
.println("Couldn't open database: check web.xml database parameters");
|
||||
e.printStackTrace();
|
||||
}
|
||||
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)
|
||||
{
|
||||
System.out.println("Couldn't open database: check web.xml database parameters");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return realConnectionString;
|
||||
}
|
||||
|
||||
@ -129,7 +130,8 @@ public class WebgoatContext {
|
||||
*
|
||||
* @return The databaseDriver value
|
||||
*/
|
||||
public String getDatabaseDriver() {
|
||||
public String getDatabaseDriver()
|
||||
{
|
||||
return (databaseDriver);
|
||||
}
|
||||
|
||||
@ -138,7 +140,8 @@ public class WebgoatContext {
|
||||
*
|
||||
* @return The databaseUser value
|
||||
*/
|
||||
public String getDatabaseUser() {
|
||||
public String getDatabaseUser()
|
||||
{
|
||||
return (databaseUser);
|
||||
}
|
||||
|
||||
@ -147,51 +150,63 @@ public class WebgoatContext {
|
||||
*
|
||||
* @return The databasePassword value
|
||||
*/
|
||||
public String getDatabasePassword() {
|
||||
public String getDatabasePassword()
|
||||
{
|
||||
return (databasePassword);
|
||||
}
|
||||
|
||||
public boolean isDefuseOSCommands() {
|
||||
public boolean isDefuseOSCommands()
|
||||
{
|
||||
return defuseOSCommands;
|
||||
}
|
||||
|
||||
public boolean isEnterprise() {
|
||||
public boolean isEnterprise()
|
||||
{
|
||||
return enterprise;
|
||||
}
|
||||
|
||||
public boolean isCodingExercises() {
|
||||
public boolean isCodingExercises()
|
||||
{
|
||||
return codingExercises;
|
||||
}
|
||||
|
||||
public String getFeedbackAddress() {
|
||||
|
||||
public String getFeedbackAddress()
|
||||
{
|
||||
return feedbackAddress;
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
public boolean isDebug()
|
||||
{
|
||||
return isDebug;
|
||||
}
|
||||
|
||||
public String getServletName() {
|
||||
public String getServletName()
|
||||
{
|
||||
return servletName;
|
||||
}
|
||||
|
||||
public boolean isShowCookies() {
|
||||
public boolean isShowCookies()
|
||||
{
|
||||
return showCookies;
|
||||
}
|
||||
|
||||
public boolean isShowParams() {
|
||||
public boolean isShowParams()
|
||||
{
|
||||
return showParams;
|
||||
}
|
||||
|
||||
public boolean isShowRequest() {
|
||||
public boolean isShowRequest()
|
||||
{
|
||||
return showRequest;
|
||||
}
|
||||
|
||||
public boolean isShowSource() {
|
||||
public boolean isShowSource()
|
||||
{
|
||||
return showSource;
|
||||
}
|
||||
|
||||
public boolean isShowSolution() {
|
||||
public boolean isShowSolution()
|
||||
{
|
||||
return showSolution;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user