Unify DatabaseUtilities.makeConnection()

Remove the hack to support Web services lessons that do not have a WebSession
Now that they have their own reference to WebgoatContext, they do not need one


git-svn-id: http://webgoat.googlecode.com/svn/trunk@140 4033779f-a91e-0410-96ef-6bf7bf53c507
This commit is contained in:
rogan.dawes 2007-07-10 11:51:01 +00:00
parent ada66dae10
commit 53487970f6
5 changed files with 3 additions and 54 deletions

View File

@ -409,7 +409,7 @@ public class SoapRequest extends LessonAdapter
{
try
{
Connection connection = DatabaseUtilities.makeConnection();
Connection connection = DatabaseUtilities.makeConnection(getWebgoatContext());
if (connection == null)
{
return null;

View File

@ -271,7 +271,7 @@ public class WSDLScanning extends LessonAdapter
{
try
{
Connection connection = DatabaseUtilities.makeConnection();
Connection connection = DatabaseUtilities.makeConnection(getWebgoatContext());
if (connection == null)
{
return null;

View File

@ -226,7 +226,7 @@ public class WsSqlInjection extends LessonAdapter
{
try
{
Connection connection = DatabaseUtilities.makeConnection();
Connection connection = DatabaseUtilities.makeConnection(getWebgoatContext());
if (connection == null)
{
return null;

View File

@ -47,9 +47,6 @@ import org.apache.ecs.html.Table;
public class DatabaseUtilities
{
public static String servletContextRealPath = null;
/**
* Description of the Method
*
@ -81,51 +78,6 @@ public class DatabaseUtilities
}
}
public static Connection makeConnection(String driverName,
String connectionString) throws ClassNotFoundException,
SQLException
{
Class.forName(driverName);
return (DriverManager.getConnection(connectionString));
}
public static Connection makeConnection()
{
try
{
// FIXME: Work around for not having a session object with the web service lessons
// This is the same "logic" in the web.xml file
// Get the path to webgoat database
String dbName = (servletContextRealPath + "database" + File.separator);
String os = System.getProperty("os.name", "Windows");
if (os.toLowerCase().indexOf("window") != -1)
{
dbName = dbName.concat("webgoat.mdb");
System.out.println("DBName: " + dbName);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
return DriverManager
.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ="
+ dbName + ";PWD=webgoat");
}
else
{
dbName = dbName.concat("database.prp");
Class.forName("org.enhydra.instantdb.jdbc.idbDriver");
return DriverManager.getConnection("jdbc:idb:" + dbName);
}
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
/**
* Description of the Method
*

View File

@ -38,9 +38,6 @@ public class WebgoatContext {
databaseUser = servlet.getInitParameter(DATABASE_USER);
databasePassword = servlet.getInitParameter(DATABASE_PASSWORD);
// FIXME: hack to save context for web service calls
DatabaseUtilities.servletContextRealPath = servlet.getServletContext().getRealPath("/");
System.out.println("Context Path: " + DatabaseUtilities.servletContextRealPath);
// FIXME: need to solve concurrency problem here -- make tables for this user
if ( !databaseBuilt ) {
try {